Fix completion problems in cqlsh Patch by stefania; reviewed by pmotta for CASSANDRA-10753
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/1b81ad19 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/1b81ad19 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/1b81ad19 Branch: refs/heads/cassandra-3.1 Commit: 1b81ad19d33710bfa1724262f76cd3cd8114b162 Parents: 8738087 Author: Stefania <stefania.alborghe...@datastax.com> Authored: Tue Dec 1 13:52:09 2015 -0500 Committer: Joshua McKenzie <jmcken...@apache.org> Committed: Tue Dec 1 13:52:09 2015 -0500 ---------------------------------------------------------------------- bin/cqlsh.py | 2 +- ...andra-driver-internal-only-3.0.0-6af642d.zip | Bin 0 -> 228893 bytes ...iver-internal-only-3.0.0a3.post0-c535450.zip | Bin 233938 -> 0 bytes pylib/cqlshlib/cql3handling.py | 36 +++++++++---------- pylib/cqlshlib/test/test_cqlsh_completion.py | 11 +++--- pylib/cqlshlib/test/test_cqlsh_output.py | 15 -------- 6 files changed, 25 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/1b81ad19/bin/cqlsh.py ---------------------------------------------------------------------- diff --git a/bin/cqlsh.py b/bin/cqlsh.py index 027a45e..a5a2bfa 100644 --- a/bin/cqlsh.py +++ b/bin/cqlsh.py @@ -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) http://git-wip-us.apache.org/repos/asf/cassandra/blob/1b81ad19/lib/cassandra-driver-internal-only-3.0.0-6af642d.zip ---------------------------------------------------------------------- diff --git a/lib/cassandra-driver-internal-only-3.0.0-6af642d.zip b/lib/cassandra-driver-internal-only-3.0.0-6af642d.zip new file mode 100644 index 0000000..507370b Binary files /dev/null and b/lib/cassandra-driver-internal-only-3.0.0-6af642d.zip differ http://git-wip-us.apache.org/repos/asf/cassandra/blob/1b81ad19/lib/cassandra-driver-internal-only-3.0.0a3.post0-c535450.zip ---------------------------------------------------------------------- diff --git a/lib/cassandra-driver-internal-only-3.0.0a3.post0-c535450.zip b/lib/cassandra-driver-internal-only-3.0.0a3.post0-c535450.zip deleted file mode 100644 index 9c75cd6..0000000 Binary files a/lib/cassandra-driver-internal-only-3.0.0a3.post0-c535450.zip and /dev/null differ http://git-wip-us.apache.org/repos/asf/cassandra/blob/1b81ad19/pylib/cqlshlib/cql3handling.py ---------------------------------------------------------------------- diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py index aed7d01..4c21f7a 100644 --- a/pylib/cqlshlib/cql3handling.py +++ b/pylib/cqlshlib/cql3handling.py @@ -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''' http://git-wip-us.apache.org/repos/asf/cassandra/blob/1b81ad19/pylib/cqlshlib/test/test_cqlsh_completion.py ---------------------------------------------------------------------- diff --git a/pylib/cqlshlib/test/test_cqlsh_completion.py b/pylib/cqlshlib/test/test_cqlsh_completion.py index 7cf583d..e5eb9e1 100644 --- a/pylib/cqlshlib/test/test_cqlsh_completion.py +++ b/pylib/cqlshlib/test/test_cqlsh_completion.py @@ -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']) http://git-wip-us.apache.org/repos/asf/cassandra/blob/1b81ad19/pylib/cqlshlib/test/test_cqlsh_output.py ---------------------------------------------------------------------- diff --git a/pylib/cqlshlib/test/test_cqlsh_output.py b/pylib/cqlshlib/test/test_cqlsh_output.py index 3246541..7a2fc86 100644 --- a/pylib/cqlshlib/test/test_cqlsh_output.py +++ b/pylib/cqlshlib/test/test_cqlsh_output.py @@ -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);', """