mirror of https://github.com/apache/cassandra
Fix completion problems in cqlsh
Patch by stefania; reviewed by pmotta for CASSANDRA-10753
This commit is contained in:
parent
8738087edd
commit
1b81ad19d3
|
|
@ -2330,7 +2330,7 @@ class ImportProcess(mp.Process):
|
|||
table_meta = new_cluster.metadata.keyspaces[self.ks].tables[self.cf]
|
||||
|
||||
pk_cols = [col.name for col in table_meta.primary_key]
|
||||
cqltypes = [table_meta.columns[name].typestring for name in self.columns]
|
||||
cqltypes = [table_meta.columns[name].cql_type for name in self.columns]
|
||||
pk_indexes = [self.columns.index(col.name) for col in table_meta.primary_key]
|
||||
is_counter_table = ("counter" in cqltypes)
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -767,21 +767,20 @@ def relation_token_subject_completer(ctxt, cass):
|
|||
@completer_for('relation', 'rel_lhs')
|
||||
def select_relation_lhs_completer(ctxt, cass):
|
||||
layout = get_table_meta(ctxt, cass)
|
||||
filterable = set((layout.partition_key[0].name, layout.clustering_key[0].name))
|
||||
filterable = set()
|
||||
already_filtered_on = map(dequote_name, ctxt.get_binding('rel_lhs', ()))
|
||||
for num in range(1, len(layout.partition_key)):
|
||||
if layout.partition_key[num - 1].name in already_filtered_on:
|
||||
for num in range(0, len(layout.partition_key)):
|
||||
if num == 0 or layout.partition_key[num - 1].name in already_filtered_on:
|
||||
filterable.add(layout.partition_key[num].name)
|
||||
else:
|
||||
break
|
||||
for num in range(1, len(layout.clustering_key)):
|
||||
if layout.clustering_key[num - 1].name in already_filtered_on:
|
||||
for num in range(0, len(layout.clustering_key)):
|
||||
if num == 0 or layout.clustering_key[num - 1].name in already_filtered_on:
|
||||
filterable.add(layout.clustering_key[num].name)
|
||||
else:
|
||||
break
|
||||
for cd in layout.columns.values():
|
||||
if cd.index:
|
||||
filterable.add(cd.name)
|
||||
for idx in layout.indexes.itervalues():
|
||||
filterable.add(idx.index_options["target"])
|
||||
return map(maybe_escape_name, filterable)
|
||||
|
||||
explain_completion('selector', 'colname')
|
||||
|
|
@ -830,16 +829,16 @@ def insert_newval_completer(ctxt, cass):
|
|||
if len(valuesdone) >= len(insertcols):
|
||||
return []
|
||||
curcol = insertcols[len(valuesdone)]
|
||||
cqltype = layout.columns[curcol].data_type
|
||||
coltype = cqltype.typename
|
||||
coltype = layout.columns[curcol].cql_type
|
||||
if coltype in ('map', 'set'):
|
||||
return ['{']
|
||||
if coltype == 'list':
|
||||
return ['[']
|
||||
if coltype == 'boolean':
|
||||
return ['true', 'false']
|
||||
|
||||
return [Hint('<value for %s (%s)>' % (maybe_escape_name(curcol),
|
||||
cqltype.cql_parameterized_type()))]
|
||||
coltype))]
|
||||
|
||||
|
||||
@completer_for('insertStatement', 'valcomma')
|
||||
|
|
@ -899,29 +898,28 @@ def update_col_completer(ctxt, cass):
|
|||
def update_countername_completer(ctxt, cass):
|
||||
layout = get_table_meta(ctxt, cass)
|
||||
curcol = dequote_name(ctxt.get_binding('updatecol', ''))
|
||||
cqltype = layout.columns[curcol].data_type
|
||||
coltype = cqltype.typename
|
||||
coltype = layout.columns[curcol].cql_type
|
||||
if coltype == 'counter':
|
||||
return [maybe_escape_name(curcol)]
|
||||
if coltype in ('map', 'set'):
|
||||
return ["{"]
|
||||
if coltype == 'list':
|
||||
return ["["]
|
||||
return [Hint('<term (%s)>' % cqltype.cql_parameterized_type())]
|
||||
return [Hint('<term (%s)>' % coltype)]
|
||||
|
||||
|
||||
@completer_for('assignment', 'counterop')
|
||||
def update_counterop_completer(ctxt, cass):
|
||||
layout = get_table_meta(ctxt, cass)
|
||||
curcol = dequote_name(ctxt.get_binding('updatecol', ''))
|
||||
return ['+', '-'] if layout.columns[curcol].data_type.typename == 'counter' else []
|
||||
return ['+', '-'] if layout.columns[curcol].cql_type == 'counter' else []
|
||||
|
||||
|
||||
@completer_for('assignment', 'inc')
|
||||
def update_counter_inc_completer(ctxt, cass):
|
||||
layout = get_table_meta(ctxt, cass)
|
||||
curcol = dequote_name(ctxt.get_binding('updatecol', ''))
|
||||
if layout.columns[curcol].data_type.typename == 'counter':
|
||||
if layout.columns[curcol].cql_type == 'counter':
|
||||
return [Hint('<wholenumber>')]
|
||||
return []
|
||||
|
||||
|
|
@ -947,7 +945,7 @@ def update_listcol_completer(ctxt, cass):
|
|||
def update_indexbracket_completer(ctxt, cass):
|
||||
layout = get_table_meta(ctxt, cass)
|
||||
curcol = dequote_name(ctxt.get_binding('updatecol', ''))
|
||||
coltype = layout.columns[curcol].data_type.typename
|
||||
coltype = layout.columns[curcol].cql_type
|
||||
if coltype in ('map', 'list'):
|
||||
return ['[']
|
||||
return []
|
||||
|
|
@ -1174,8 +1172,10 @@ explain_completion('createUserTypeStatement', 'newcol', '<new_field_name>')
|
|||
|
||||
@completer_for('createIndexStatement', 'col')
|
||||
def create_index_col_completer(ctxt, cass):
|
||||
""" Return the columns for which an index doesn't exist yet. """
|
||||
layout = get_table_meta(ctxt, cass)
|
||||
colnames = [cd.name for cd in layout.columns.values() if not cd.index]
|
||||
idx_targets = [idx.index_options["target"] for idx in layout.indexes.itervalues()]
|
||||
colnames = [cd.name for cd in layout.columns.values() if cd.name not in idx_targets]
|
||||
return map(maybe_escape_name, colnames)
|
||||
|
||||
syntax_rules += r'''
|
||||
|
|
|
|||
|
|
@ -341,18 +341,18 @@ class TestCqlshCompletion(CqlshCompletionCase):
|
|||
self.trycompletions("UPDATE empty_table SET lonelycol = 'eggs'",
|
||||
choices=[',', 'WHERE'])
|
||||
self.trycompletions("UPDATE empty_table SET lonelycol = 'eggs' WHERE ",
|
||||
choices=['TOKEN(', '<identifier>', '<quotedName>'])
|
||||
choices=['TOKEN(', 'lonelykey'])
|
||||
self.trycompletions("UPDATE empty_table SET lonelycol = 'eggs' WHERE ",
|
||||
choices=['TOKEN(', '<identifier>', '<quotedName>'])
|
||||
choices=['TOKEN(', 'lonelykey'])
|
||||
|
||||
self.trycompletions("UPDATE empty_table SET lonelycol = 'eggs' WHERE lonel",
|
||||
choices=['<quotedName>', '<identifier>'])
|
||||
immediate='ykey ')
|
||||
self.trycompletions("UPDATE empty_table SET lonelycol = 'eggs' WHERE lonelykey ",
|
||||
choices=['=', '<=', '>=', '>', '<', 'CONTAINS', 'IN', '['])
|
||||
self.trycompletions("UPDATE empty_table SET lonelycol = 'eggs' WHERE lonelykey = 0.0 ",
|
||||
choices=['AND', 'IF', ';'])
|
||||
self.trycompletions("UPDATE empty_table SET lonelycol = 'eggs' WHERE lonelykey = 0.0 AND ",
|
||||
choices=['TOKEN(', '<identifier>', '<quotedName>'])
|
||||
choices=['TOKEN(', 'lonelykey'])
|
||||
|
||||
self.trycompletions("UPDATE empty_table SET lonelycol = 'eggs' WHERE TOKEN(lonelykey ",
|
||||
choices=[',', ')'])
|
||||
|
|
@ -654,7 +654,8 @@ class TestCqlshCompletion(CqlshCompletionCase):
|
|||
choices=['base_time_seconds', 'max_sstable_age_days',
|
||||
'timestamp_resolution', 'min_threshold', 'class', 'max_threshold',
|
||||
'tombstone_compaction_interval', 'tombstone_threshold',
|
||||
'enabled', 'unchecked_tombstone_compaction'])
|
||||
'enabled', 'unchecked_tombstone_compaction',
|
||||
'max_window_size_seconds'])
|
||||
|
||||
def test_complete_in_create_columnfamily(self):
|
||||
self.trycompletions('CREATE C', choices=['COLUMNFAMILY', 'CUSTOM'])
|
||||
|
|
|
|||
|
|
@ -369,21 +369,6 @@ class TestCqlshOutput(BaseTestCase):
|
|||
"""),
|
||||
), env={'TZ': 'Etc/UTC'})
|
||||
|
||||
self.assertQueriesGiveColoredOutput((
|
||||
('''select timestampcol from has_all_types where num = 0;''', """
|
||||
timestampcol
|
||||
MMMMMMMMMMMM
|
||||
--------------------------
|
||||
|
||||
2012-05-14 07:53:20-0500
|
||||
GGGGGGGGGGGGGGGGGGGGGGGG
|
||||
|
||||
|
||||
(1 rows)
|
||||
nnnnnnnn
|
||||
"""),
|
||||
), env={'TZ': 'EST'})
|
||||
|
||||
def test_boolean_output(self):
|
||||
self.assertCqlverQueriesGiveColoredOutput((
|
||||
('select num, booleancol from has_all_types where num in (0, 1, 2, 3);', """
|
||||
|
|
|
|||
Loading…
Reference in New Issue