You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2015/09/29 11:53:38 UTC

cassandra git commit: Configurable page size in cqlsh

Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 5fe40a117 -> 4595ec03f


Configurable page size in cqlsh

patch by enigmacurry; reviewed by philipthompson for CASSANDRA-9855


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

Branch: refs/heads/cassandra-2.2
Commit: 4595ec03f0a30b510d5b5667b537f226563c1da1
Parents: 5fe40a1
Author: Sylvain Lebresne <sy...@datastax.com>
Authored: Tue Sep 29 11:52:22 2015 +0200
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Tue Sep 29 11:52:22 2015 +0200

----------------------------------------------------------------------
 CHANGES.txt  |  1 +
 bin/cqlsh.py | 37 ++++++++++++++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/4595ec03/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index a83fd53..7e6f1e0 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.2.2
+ * Configurable page size in cqlsh (CASSANDRA-9855)
  * Defer default role manager setup until all nodes are on 2.2+ (CASSANDRA-9761)
  * Cancel transaction for sstables we wont redistribute index summary
    for (CASSANDRA-10270)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4595ec03/bin/cqlsh.py
----------------------------------------------------------------------
diff --git a/bin/cqlsh.py b/bin/cqlsh.py
index 81c998c..6ff3a96 100644
--- a/bin/cqlsh.py
+++ b/bin/cqlsh.py
@@ -356,7 +356,7 @@ cqlsh_extra_syntax_rules = r'''
 <expandCommand> ::= "EXPAND" ( switch=( "ON" | "OFF" ) )?
                    ;
 
-<pagingCommand> ::= "PAGING" ( switch=( "ON" | "OFF" ) )?
+<pagingCommand> ::= "PAGING" ( switch=( "ON" | "OFF" | /[0-9]+/) )?
                   ;
 
 <loginCommand> ::= "LOGIN" username=<username> (password=<stringLiteral>)?
@@ -637,6 +637,7 @@ class Shell(cmd.Cmd):
         self.keyspace = keyspace
         self.ssl = ssl
         self.tracing_enabled = tracing_enabled
+        self.page_size = self.default_page_size
         self.expand_enabled = expand_enabled
         if use_conn:
             self.conn = use_conn
@@ -1131,7 +1132,7 @@ class Shell(cmd.Cmd):
         self.tracing_enabled = tracing_was_enabled
 
     def perform_statement(self, statement):
-        stmt = SimpleStatement(statement, consistency_level=self.consistency_level, serial_consistency_level=self.serial_consistency_level, fetch_size=self.default_page_size if self.use_paging else None)
+        stmt = SimpleStatement(statement, consistency_level=self.consistency_level, serial_consistency_level=self.serial_consistency_level, fetch_size=self.page_size if self.use_paging else None)
         result, future = self.perform_simple_statement(stmt)
 
         if future:
@@ -2248,7 +2249,14 @@ class Shell(cmd.Cmd):
 
           PAGING with no arguments shows the current query paging status.
         """
-        self.use_paging = SwitchCommand("PAGING", "Query paging").execute(self.use_paging, parsed, self.printerr)
+        (self.use_paging, requested_page_size) = SwitchCommandWithValue(
+            "PAGING", "Query paging", value_type=int).execute(self.use_paging, parsed, self.printerr)
+        if self.use_paging and requested_page_size is not None:
+            self.page_size = requested_page_size
+        if self.use_paging:
+            print("Page size: {}".format(self.page_size))
+        else:
+            self.page_size = self.default_page_size
 
     def applycolor(self, text, color=None):
         if not color or not self.color:
@@ -2481,6 +2489,29 @@ class SwitchCommand(object):
             print 'Disabled %s.' % (self.description,)
             return False
 
+class SwitchCommandWithValue(SwitchCommand):
+    """The same as SwitchCommand except it also accepts a value in place of ON.
+    
+    This returns a tuple of the form: (SWITCH_VALUE, PASSED_VALUE)
+    eg: PAGING 50 returns (True, 50)
+        PAGING OFF returns (False, None)
+        PAGING ON returns (True, None)
+
+    The value_type must match for the PASSED_VALUE, otherwise it will return None.
+    """
+    def __init__(self, command, desc, value_type=int):
+        SwitchCommand.__init__(self, command, desc)
+        self.value_type = value_type
+        
+    def execute(self, state, parsed, printerr):
+        binary_switch_value = SwitchCommand.execute(self, state, parsed, printerr)
+        switch = parsed.get_binding('switch')
+        try:
+            value = self.value_type(switch)
+            binary_switch_value = True
+        except (ValueError, TypeError):
+            value = None
+        return (binary_switch_value, value)
 
 def option_with_default(cparser_getter, section, option, default=None):
     try: