Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 a61fc01f4 -> 806378c8c


Fix cqlsh rules

patch by Stefania Alborghetti; reviewed by Benjamin Lerer for
CASSANDRA-10415


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/806378c8
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/806378c8
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/806378c8

Branch: refs/heads/cassandra-2.1
Commit: 806378c8c295fb062f94eb8bf0f719b398d27745
Parents: a61fc01
Author: Stefania Alborghetti <stefania.alborghe...@datastax.com>
Authored: Fri Oct 16 11:47:07 2015 +0200
Committer: blerer <benjamin.le...@datastax.com>
Committed: Fri Oct 16 11:47:07 2015 +0200

----------------------------------------------------------------------
 pylib/cqlshlib/cqlhandling.py                | 10 ++++++++++
 pylib/cqlshlib/test/cassconnect.py           |  3 ++-
 pylib/cqlshlib/test/run_cqlsh.py             |  2 +-
 pylib/cqlshlib/test/test_cqlsh_completion.py | 11 ++++-------
 pylib/cqlshlib/test/test_cqlsh_output.py     |  4 ++--
 pylib/cqlshlib/test/test_keyspace_init.cql   |  2 +-
 6 files changed, 20 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/806378c8/pylib/cqlshlib/cqlhandling.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/cqlhandling.py b/pylib/cqlshlib/cqlhandling.py
index 5fe311f..9ea30cd 100644
--- a/pylib/cqlshlib/cqlhandling.py
+++ b/pylib/cqlshlib/cqlhandling.py
@@ -18,6 +18,7 @@
 # i.e., stuff that's not necessarily cqlsh-specific
 
 import traceback
+from cassandra.metadata import cql_keywords_reserved
 from . import pylexotron, util
 
 Hint = pylexotron.Hint
@@ -55,6 +56,15 @@ class CqlParsingRuleSet(pylexotron.ParsingRuleSet):
 
         # note: commands_end_with_newline may be extended by callers.
         self.commands_end_with_newline = set()
+        self.set_reserved_keywords(cql_keywords_reserved)
+
+    def set_reserved_keywords(self, keywords):
+        """
+        We cannot let resreved cql keywords be simple 'identifier' since this 
caused
+        problems with completion, see CASSANDRA-10415
+        """
+        syntax = '<reserved_identifier> ::= /(' + '|'.join(r'\b{}\b'.format(k) 
for k in keywords) + ')/ ;'
+        self.append_rules(syntax)
 
     def completer_for(self, rulename, symname):
         def registrator(f):

http://git-wip-us.apache.org/repos/asf/cassandra/blob/806378c8/pylib/cqlshlib/test/cassconnect.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/test/cassconnect.py 
b/pylib/cqlshlib/test/cassconnect.py
index 21dddcd..a67407b 100644
--- a/pylib/cqlshlib/test/cassconnect.py
+++ b/pylib/cqlshlib/test/cassconnect.py
@@ -20,6 +20,7 @@ import contextlib
 import tempfile
 import os.path
 from .basecase import cql, cqlsh, cqlshlog, TEST_HOST, TEST_PORT, rundir
+from cassandra.metadata import maybe_escape_name
 from .run_cqlsh import run_cqlsh, call_cqlsh
 
 test_keyspace_init = os.path.join(rundir, 'test_keyspace_init.cql')
@@ -126,7 +127,7 @@ def cql_rule_set():
     return cqlsh.cql3handling.CqlRuleSet
 
 def quote_name(name):
-    return cql_rule_set().maybe_escape_name(name)
+    return maybe_escape_name(name)
 
 class DEFAULTVAL: pass
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/806378c8/pylib/cqlshlib/test/run_cqlsh.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/test/run_cqlsh.py b/pylib/cqlshlib/test/run_cqlsh.py
index 6ae295c..88b0ca6 100644
--- a/pylib/cqlshlib/test/run_cqlsh.py
+++ b/pylib/cqlshlib/test/run_cqlsh.py
@@ -231,7 +231,7 @@ class CqlshRunner(ProcRunner):
             self.output_header = self.read_to_next_prompt()
 
     def read_to_next_prompt(self):
-        return self.read_until(self.prompt, timeout=4.0)
+        return self.read_until(self.prompt, timeout=10.0)
 
     def read_up_to_timeout(self, timeout, blksize=4096):
         output = ProcRunner.read_up_to_timeout(self, timeout, blksize=blksize)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/806378c8/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 97bd96b..5f7b6e4 100644
--- a/pylib/cqlshlib/test/test_cqlsh_completion.py
+++ b/pylib/cqlshlib/test/test_cqlsh_completion.py
@@ -142,8 +142,8 @@ class TestCqlshCompletion(CqlshCompletionCase):
     def test_complete_on_empty_string(self):
         self.trycompletions('', choices=('?', 'ALTER', 'BEGIN', 'CAPTURE', 
'CONSISTENCY',
                                          'COPY', 'CREATE', 'DEBUG', 'DELETE', 
'DESC', 'DESCRIBE',
-                                         'DROP', 'GRANT', 'HELP', 'INSERT', 
'LIST', 'PAGING', 'REVOKE',
-                                         'SELECT', 'SHOW', 'SOURCE', 
'TRACING', 'EXPAND', 'TRUNCATE',
+                                         'DROP', 'GRANT', 'HELP', 'INSERT', 
'LIST', 'LOGIN', 'PAGING', 'REVOKE',
+                                         'SELECT', 'SERIAL', 'SHOW', 'SOURCE', 
'TRACING', 'EXPAND', 'TRUNCATE',
                                          'UPDATE', 'USE', 'exit', 'quit'))
 
     def test_complete_command_words(self):
@@ -228,8 +228,8 @@ class TestCqlshCompletion(CqlshCompletionCase):
              "VALUES ( 'eggs', 'sausage', 'spam');"),
             choices=['?', 'ALTER', 'BEGIN', 'CAPTURE', 'CONSISTENCY', 'COPY',
                      'CREATE', 'DEBUG', 'DELETE', 'DESC', 'DESCRIBE', 'DROP',
-                     'EXPAND', 'GRANT', 'HELP', 'INSERT', 'LIST', 'PAGING',
-                     'REVOKE', 'SELECT', 'SHOW', 'SOURCE', 'TRACING',
+                     'EXPAND', 'GRANT', 'HELP', 'INSERT', 'LIST', 'LOGIN', 
'PAGING',
+                     'REVOKE', 'SELECT', 'SERIAL', 'SHOW', 'SOURCE', 'TRACING',
                      'TRUNCATE', 'UPDATE', 'USE', 'exit', 'quit'])
 
         self.trycompletions(
@@ -422,9 +422,6 @@ class TestCqlshCompletion(CqlshCompletionCase):
     def test_complete_in_string_literals(self):
         # would be great if we could get a space after this sort of completion,
         # but readline really wants to make things difficult for us
-        self.trycompletions('insert into system."Index', 'Info"')
-        self.trycompletions('USE "', choices=('system', self.cqlsh.keyspace),
-                            other_choices_ok=True)
         self.trycompletions("create keyspace blah with replication = {'class': 
'Sim",
                             "pleStrategy'")
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/806378c8/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 60ef3a4..64950e2 100644
--- a/pylib/cqlshlib/test/test_cqlsh_output.py
+++ b/pylib/cqlshlib/test/test_cqlsh_output.py
@@ -609,7 +609,7 @@ class TestCqlshOutput(BaseTestCase):
             ) WITH bloom_filter_fp_chance = 0.01
                 AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
                 AND comment = ''
-                AND compaction = {'min_threshold': '4', 'class': 
'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 
'max_threshold': '32'}
+                AND compaction = {'class': 
'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'}
                 AND compression = {'sstable_compression': 
'org.apache.cassandra.io.compress.LZ4Compressor'}
                 AND dclocal_read_repair_chance = 0.1
                 AND default_time_to_live = 0
@@ -627,7 +627,7 @@ class TestCqlshOutput(BaseTestCase):
                 for semicolon in (';', ''):
                     output = c.cmd_and_response('%s has_all_types%s' % 
(cmdword, semicolon))
                     self.assertNoHasColors(output)
-                    self.assertEqual(output, table_desc3)
+                    self.assertSequenceEqual(output.split('\n'), 
table_desc3.split('\n'))
 
     def test_describe_columnfamilies_output(self):
         output_re = r'''

http://git-wip-us.apache.org/repos/asf/cassandra/blob/806378c8/pylib/cqlshlib/test/test_keyspace_init.cql
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/test/test_keyspace_init.cql 
b/pylib/cqlshlib/test/test_keyspace_init.cql
index cd5ac75..9a13918 100644
--- a/pylib/cqlshlib/test/test_keyspace_init.cql
+++ b/pylib/cqlshlib/test/test_keyspace_init.cql
@@ -26,7 +26,7 @@ INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, 
blobcol, booleancol
                            decimalcol, doublecol, floatcol, textcol,
                            timestampcol, uuidcol, varcharcol, varintcol)
 VALUES (1, 2147483647, '__!''$#@!~"', 9223372036854775807, 
0xffffffffffffffffff, true,
-        0.00000000000001, 9999999.999, 99999.99, '∭Ƕ⑮ฑ➳❏''', 
'1900-01-01+0000',
+        0.00000000000001, 9999999.999, 99999.999, '∭Ƕ⑮ฑ➳❏''', 
'1900-01-01+0000',
         ffffffff-ffff-ffff-ffff-ffffffffffff, 'newline->
 <-', 9);
 

Reply via email to