cqlsh: use python driver for CQL keyword list Patch by Stefania Alborghetti; reviewed by Tyler Hobbs for CASSANDRA-9232
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/386f197d Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/386f197d Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/386f197d Branch: refs/heads/trunk Commit: 386f197da3aa0804338c24811d354bdebe1c1222 Parents: 7d74563 Author: Stefania Alborghetti <stefania.alborghe...@datastax.com> Authored: Tue Aug 25 09:54:16 2015 -0500 Committer: Tyler Hobbs <tylerlho...@gmail.com> Committed: Tue Aug 25 09:54:16 2015 -0500 ---------------------------------------------------------------------- CHANGES.txt | 1 + pylib/cqlshlib/cql3handling.py | 39 ++++++++++--------------------------- pylib/cqlshlib/cqlhandling.py | 12 ++---------- 3 files changed, 13 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/386f197d/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index dcae493..92dcf59 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.1.9 + * (cqlsh) update list of CQL keywords (CASSANDRA-9232) * Avoid race condition during read repair (CASSANDRA-9460) * (cqlsh) default load-from-file encoding to utf-8 (CASSANDRA-9898) * Avoid returning Permission.NONE when failing to query users table (CASSANDRA-10168) http://git-wip-us.apache.org/repos/asf/cassandra/blob/386f197d/pylib/cqlshlib/cql3handling.py ---------------------------------------------------------------------- diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py index 92e3f12..2857a7e 100644 --- a/pylib/cqlshlib/cql3handling.py +++ b/pylib/cqlshlib/cql3handling.py @@ -37,19 +37,6 @@ SYSTEM_KEYSPACES = ('system', 'system_traces', 'system_auth') NONALTERBALE_KEYSPACES = ('system') class Cql3ParsingRuleSet(CqlParsingRuleSet): - keywords = set(( - 'select', 'from', 'where', 'and', 'key', 'insert', 'update', 'with', - 'limit', 'using', 'use', 'count', 'set', - 'begin', 'apply', 'batch', 'truncate', 'delete', 'in', 'create', - 'keyspace', 'schema', 'columnfamily', 'table', 'index', 'on', 'drop', - 'primary', 'into', 'values', 'timestamp', 'ttl', 'alter', 'add', 'type', - 'compact', 'storage', 'order', 'by', 'asc', 'desc', 'clustering', - 'token', 'writetime', 'map', 'list', 'to', 'custom', 'if', 'not' - )) - - unreserved_keywords = set(( - 'key', 'clustering', 'ttl', 'compact', 'storage', 'type', 'values', 'custom', 'exists' - )) columnfamily_layout_options = ( ('bloom_filter_fp_chance', None), @@ -89,10 +76,6 @@ class Cql3ParsingRuleSet(CqlParsingRuleSet): 'SERIAL' ) - maybe_escape_name = staticmethod(maybe_escape_name) - - escape_name = staticmethod(escape_name) - @classmethod def escape_value(cls, value): if value is None: @@ -132,8 +115,6 @@ explain_completion = CqlRuleSet.explain_completion dequote_value = CqlRuleSet.dequote_value dequote_name = CqlRuleSet.dequote_name escape_value = CqlRuleSet.escape_value -maybe_escape_name = CqlRuleSet.maybe_escape_name - # BEGIN SYNTAX/COMPLETION RULE DEFINITIONS @@ -251,7 +232,7 @@ JUNK ::= /([ \t\r\f\v]+|(--|[/][/])[^\n\r]*([\n\r]|$)|[/][*].*?[*][/])/ ; ; # timestamp is included here, since it's also a keyword -<simpleStorageType> ::= typename=( <identifier> | <stringLiteral> | <K_TIMESTAMP> ) ; +<simpleStorageType> ::= typename=( <identifier> | <stringLiteral> | "timestamp" ) ; <userType> ::= utname=<cfOrKsName> ; @@ -284,14 +265,14 @@ JUNK ::= /([ \t\r\f\v]+|(--|[/][/])[^\n\r]*([\n\r]|$)|[/][*].*?[*][/])/ ; | <unreservedKeyword>; <unreservedKeyword> ::= nocomplete= - ( <K_KEY> - | <K_CLUSTERING> - # | <K_COUNT> -- to get count(*) completion, treat count as reserved - | <K_TTL> - | <K_COMPACT> - | <K_STORAGE> - | <K_TYPE> - | <K_VALUES> ) + ( "key" + | "clustering" + # | "count" -- to get count(*) completion, treat count as reserved + | "ttl" + | "compact" + | "storage" + | "type" + | "values" ) ; <property> ::= [propname]=<cident> propeq="=" [propval]=<propertyValue> @@ -1172,7 +1153,7 @@ def username_name_completer(ctxt, cass): return "'%s'" % name # disable completion for CREATE USER. - if ctxt.matched[0][0] == 'K_CREATE': + if ctxt.matched[0][0] == 'create': return [Hint('<username>')] session = cass.session http://git-wip-us.apache.org/repos/asf/cassandra/blob/386f197d/pylib/cqlshlib/cqlhandling.py ---------------------------------------------------------------------- diff --git a/pylib/cqlshlib/cqlhandling.py b/pylib/cqlshlib/cqlhandling.py index 1836961..4009125 100644 --- a/pylib/cqlshlib/cqlhandling.py +++ b/pylib/cqlshlib/cqlhandling.py @@ -24,7 +24,6 @@ Hint = pylexotron.Hint class CqlParsingRuleSet(pylexotron.ParsingRuleSet): - keywords = set() available_compression_classes = ( 'DeflateCompressor', @@ -56,7 +55,6 @@ class CqlParsingRuleSet(pylexotron.ParsingRuleSet): # note: commands_end_with_newline may be extended by callers. self.commands_end_with_newline = set() - self.set_keywords_as_syntax() def completer_for(self, rulename, symname): def registrator(f): @@ -80,12 +78,6 @@ class CqlParsingRuleSet(pylexotron.ParsingRuleSet): return explainer - def set_keywords_as_syntax(self): - syntax = [] - for k in self.keywords: - syntax.append('<K_%s> ::= "%s" ;' % (k.upper(), k)) - self.append_rules('\n'.join(syntax)) - def cql_massage_tokens(self, toklist): curstmt = [] output = [] @@ -146,9 +138,9 @@ class CqlParsingRuleSet(pylexotron.ParsingRuleSet): else: output.append(stmt) if len(stmt) > 2: - if stmt[-3][0] == 'K_APPLY': + if stmt[-3][0] == 'apply': in_batch = False - elif stmt[0][0] == 'K_BEGIN': + elif stmt[0][0] == 'begin': in_batch = True return output, in_batch