Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.X 541d83707 -> a0419085d
  refs/heads/trunk 9f75e7068 -> 2ab4666cd


cqlsh fails to format collections when using aliases

Patch by Stefania Alborghetti; reviewed by Robert Stupp for CASSANDRA-11534


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

Branch: refs/heads/cassandra-3.X
Commit: a0419085d58403557c81f4c9b784aaa7cf019314
Parents: 541d837
Author: Stefania Alborghetti <stefania.alborghe...@datastax.com>
Authored: Mon Sep 12 15:36:43 2016 +0800
Committer: Stefania Alborghetti <stefania.alborghe...@datastax.com>
Committed: Thu Oct 13 09:26:16 2016 +0800

----------------------------------------------------------------------
 CHANGES.txt                                     |   1 +
 bin/cqlsh.py                                    |  30 +++++++++----------
 ...driver-internal-only-3.5.0.post0-d8d0456.zip | Bin 245487 -> 0 bytes
 ...driver-internal-only-3.7.0.post0-70f41b5.zip | Bin 0 -> 252036 bytes
 pylib/cqlshlib/test/test_cqlsh_output.py        |  15 ++++++++++
 5 files changed, 30 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/a0419085/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 1ade69f..f0df0e6 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.10
+ * cqlsh fails to format collections when using aliases (CASSANDRA-11534)
  * Check for hash conflicts in prepared statements (CASSANDRA-12733)
  * Exit query parsing upon first error (CASSANDRA-12598)
  * Fix cassandra-stress to use single seed in UUID generation (CASSANDRA-12729)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a0419085/bin/cqlsh.py
----------------------------------------------------------------------
diff --git a/bin/cqlsh.py b/bin/cqlsh.py
index 7f8609c..e741752 100644
--- a/bin/cqlsh.py
+++ b/bin/cqlsh.py
@@ -151,6 +151,7 @@ except ImportError, e:
 
 from cassandra.auth import PlainTextAuthProvider
 from cassandra.cluster import Cluster
+from cassandra.cqltypes import cql_typename
 from cassandra.marshal import int64_unpack
 from cassandra.metadata import (ColumnMetadata, KeyspaceMetadata,
                                 TableMetadata, protect_name, protect_names)
@@ -1289,7 +1290,7 @@ class Shell(cmd.Cmd):
         elif result:
             # CAS INSERT/UPDATE
             self.writeresult("")
-            self.print_static_result(result.column_names, list(result), 
self.parse_for_update_meta(statement.query_string))
+            self.print_static_result(result, 
self.parse_for_update_meta(statement.query_string))
         self.flush_output()
         return True, future
 
@@ -1300,19 +1301,17 @@ class Shell(cmd.Cmd):
         if result.has_more_pages and self.tty:
             num_rows = 0
             while True:
-                page = result.current_rows
-                if page:
-                    num_rows += len(page)
-                    self.print_static_result(result.column_names, page, 
table_meta)
+                if result.current_rows:
+                    num_rows += len(result.current_rows)
+                    self.print_static_result(result, table_meta)
                 if result.has_more_pages:
                     raw_input("---MORE---")
                     result.fetch_next_page()
                 else:
                     break
         else:
-            rows = list(result)
-            num_rows = len(rows)
-            self.print_static_result(result.column_names, rows, table_meta)
+            num_rows = len(result.current_rows)
+            self.print_static_result(result, table_meta)
         self.writeresult("(%d rows)" % num_rows)
 
         if self.decoding_errors:
@@ -1322,24 +1321,23 @@ class Shell(cmd.Cmd):
                 self.writeresult('%d more decoding errors suppressed.'
                                  % (len(self.decoding_errors) - 2), color=RED)
 
-    def print_static_result(self, column_names, rows, table_meta):
-        if not column_names and not table_meta:
+    def print_static_result(self, result, table_meta):
+        if not result.column_names and not table_meta:
             return
 
-        column_names = column_names or table_meta.columns.keys()
+        column_names = result.column_names or table_meta.columns.keys()
         formatted_names = [self.myformat_colname(name, table_meta) for name in 
column_names]
-        if not rows:
+        if not result.current_rows:
             # print header only
             self.print_formatted_result(formatted_names, None)
             return
 
         cql_types = []
-        if table_meta:
+        if result.column_types:
             ks_meta = self.conn.metadata.keyspaces[table_meta.keyspace_name]
-            cql_types = [CqlType(table_meta.columns[c].cql_type, ks_meta)
-                         if c in table_meta.columns else None for c in 
column_names]
+            cql_types = [CqlType(cql_typename(t), ks_meta) for t in 
result.column_types]
 
-        formatted_values = [map(self.myformat_value, row.values(), cql_types) 
for row in rows]
+        formatted_values = [map(self.myformat_value, row.values(), cql_types) 
for row in result.current_rows]
 
         if self.expand_enabled:
             self.print_formatted_result_vertically(formatted_names, 
formatted_values)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a0419085/lib/cassandra-driver-internal-only-3.5.0.post0-d8d0456.zip
----------------------------------------------------------------------
diff --git a/lib/cassandra-driver-internal-only-3.5.0.post0-d8d0456.zip 
b/lib/cassandra-driver-internal-only-3.5.0.post0-d8d0456.zip
deleted file mode 100644
index 7d23b48..0000000
Binary files a/lib/cassandra-driver-internal-only-3.5.0.post0-d8d0456.zip and 
/dev/null differ

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a0419085/lib/cassandra-driver-internal-only-3.7.0.post0-70f41b5.zip
----------------------------------------------------------------------
diff --git a/lib/cassandra-driver-internal-only-3.7.0.post0-70f41b5.zip 
b/lib/cassandra-driver-internal-only-3.7.0.post0-70f41b5.zip
new file mode 100644
index 0000000..4bbe903
Binary files /dev/null and 
b/lib/cassandra-driver-internal-only-3.7.0.post0-70f41b5.zip differ

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a0419085/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 681da77..f57c734 100644
--- a/pylib/cqlshlib/test/test_cqlsh_output.py
+++ b/pylib/cqlshlib/test/test_cqlsh_output.py
@@ -847,3 +847,18 @@ class TestCqlshOutput(BaseTestCase):
             nnnnnnnn
             """),
         ))
+
+        self.assertQueriesGiveColoredOutput((
+            ("select tags as my_tags from songs;", r"""
+             my_tags
+             MMMMMMM
+            -------------------------------------------------
+
+             {tags: {'genre': 'metal', 'origin': 'england'}}
+             BYYYYBBBYYYYYYYBBYYYYYYYBBYYYYYYYYBBYYYYYYYYYBB
+
+
+            (1 rows)
+            nnnnnnnn
+            """),
+        ))

Reply via email to