diff --git a/CHANGES.txt b/CHANGES.txt index a16985a1af..84db328454 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,7 @@ * Cleanup dependency scopes (CASSANDRA-16704) * Make JmxHistogram#getRecentValues() and JmxTimer#getRecentValues() thread-safe (CASSANDRA-16707) Merged from 3.11: + * Make cqlsh use the same set of reserved keywords than the server uses (CASSANDRA-15663) * Optimize bytes skipping when reading SSTable files (CASSANDRA-14415) * Enable tombstone compactions when unchecked_tombstone_compaction is set in TWCS (CASSANDRA-14496) * Read only the required SSTables for single partition queries (CASSANDRA-16737) diff --git a/pylib/cqlshlib/cqlhandling.py b/pylib/cqlshlib/cqlhandling.py index e4b9fdd73f..3da0ab1aea 100644 --- a/pylib/cqlshlib/cqlhandling.py +++ b/pylib/cqlshlib/cqlhandling.py @@ -19,19 +19,23 @@ import traceback +import cassandra from cqlshlib import pylexotron, util Hint = pylexotron.Hint -# CASSANDRA-16659 - to keep things compact cql_keywords_reserved will not be imported from the drivers anymore -cql_reserved_keywords = set(( - 'authorize', 'rename', 'set', 'revoke', 'into', 'describe', 'primary', 'columnfamily', 'apply', - 'table', 'null', 'select', 'if', 'index', 'use', 'from', 'and', 'unlogged', 'create', 'nan', 'to', 'add', - 'alter', 'schema', 'begin', 'full', 'infinity', 'grant', 'truncate', 'on', 'modify', 'update', - 'asc', 'entries', 'not', 'using', 'with', 'by', 'is', 'desc', 'insert', 'execute', 'in', - 'materialized', 'drop', 'batch', 'order', 'keyspace', 'token', 'limit', 'allow', 'of', 'norecursive', 'delete', - 'where', 'or', 'view' +cql_keywords_reserved = set(( + 'add', 'allow', 'alter', 'and', 'apply', 'asc', 'authorize', 'batch', 'begin', 'by', 'columnfamily', 'create', + 'delete', 'desc', 'describe', 'drop', 'entries', 'execute', 'from', 'full', 'grant', 'if', 'in', 'index', + 'infinity', 'insert', 'into', 'is', 'keyspace', 'limit', 'materialized', 'modify', 'nan', 'norecursive', 'not', + 'null', 'of', 'on', 'or', 'order', 'primary', 'rename', 'revoke', 'schema', 'select', 'set', 'table', 'to', 'token', + 'truncate', 'unlogged', 'update', 'use', 'using', 'view', 'where', 'with' )) +""" +Set of reserved keywords in CQL. + +Derived from .../cassandra/src/java/org/apache/cassandra/cql3/ReservedKeywords.java +""" class CqlParsingRuleSet(pylexotron.ParsingRuleSet): @@ -67,7 +71,8 @@ class CqlParsingRuleSet(pylexotron.ParsingRuleSet): We cannot let reserved cql keywords be simple 'identifier' since this caused problems with completion, see CASSANDRA-10415 """ - syntax = ' ::= /(' + '|'.join(r'\b{}\b'.format(k) for k in cql_reserved_keywords) + ')/ ;' + cassandra.metadata.cql_keywords_reserved = cql_keywords_reserved + syntax = ' ::= /(' + '|'.join(r'\b{}\b'.format(k) for k in cql_keywords_reserved) + ')/ ;' self.append_rules(syntax) def completer_for(self, rulename, symname): diff --git a/pylib/cqlshlib/test/test_constants.py b/pylib/cqlshlib/test/test_constants.py index 669e433935..746c888e91 100644 --- a/pylib/cqlshlib/test/test_constants.py +++ b/pylib/cqlshlib/test/test_constants.py @@ -15,10 +15,9 @@ # limitations under the License. from os.path import join -import re from .basecase import BaseTestCase, cassandra_dir -from cqlshlib.cqlhandling import cql_reserved_keywords as cqlsh_reserved_keywords +from cqlshlib.cqlhandling import cql_keywords_reserved RESERVED_KEYWORDS_SOURCE = join(cassandra_dir, 'src', 'resources', 'org', 'apache', 'cassandra', 'cql3', 'reserved_keywords.txt') @@ -29,10 +28,10 @@ class TestConstants(BaseTestCase): with open(RESERVED_KEYWORDS_SOURCE) as f: source_reserved_keywords = set(line.rstrip().lower() for line in f) - cqlsh_not_source = cqlsh_reserved_keywords - source_reserved_keywords + cqlsh_not_source = cql_keywords_reserved - source_reserved_keywords self.assertFalse(cqlsh_not_source, "Reserved keywords in cqlsh not read from source %s." % (RESERVED_KEYWORDS_SOURCE,)) - source_not_cqlsh = source_reserved_keywords - cqlsh_reserved_keywords + source_not_cqlsh = source_reserved_keywords - cql_keywords_reserved self.assertFalse(source_not_cqlsh, "Reserved keywords in source %s not appearing in cqlsh." % (RESERVED_KEYWORDS_SOURCE,)) diff --git a/src/antlr/Lexer.g b/src/antlr/Lexer.g index c1f6f125ab..d89097e55d 100644 --- a/src/antlr/Lexer.g +++ b/src/antlr/Lexer.g @@ -57,8 +57,8 @@ lexer grammar Lexer; // Case-insensitive keywords // When adding a new reserved keyword, add entry to o.a.c.cql3.ReservedKeywords and -// pylib/cqlshlib/cqlhandling.py::CqlParsingRuleSet.cql_keywords_reserved as well -// When adding a new unreserved keyword, add entry to unreserved keywords in Parser.g +// pylib/cqlshlib/cqlhandling.py::cql_keywords_reserved. +// When adding a new unreserved keyword, add entry to unreserved keywords in Parser.g. K_SELECT: S E L E C T; K_FROM: F R O M; K_AS: A S;