Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.0 fa18880e7 -> 2800bf108


(cqlsh) show correct column names for empty result sets

patch by Adam Holmberg; reviewed by Ariel Weisberg for CASSANDRA-9813


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

Branch: refs/heads/cassandra-3.0
Commit: bcd68b546b7e449afd5f4233e01a45e0e4609307
Parents: 9dd2b5e
Author: Adam Holmberg <adam.holmb...@datastax.com>
Authored: Fri Dec 11 16:18:49 2015 -0600
Committer: Aleksey Yeschenko <alek...@apache.org>
Committed: Fri Dec 18 23:26:53 2015 +0000

----------------------------------------------------------------------
 CHANGES.txt  |  1 +
 bin/cqlsh.py | 21 +++++++--------------
 2 files changed, 8 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/bcd68b54/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 1480960..88ef42e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.2.5
+ * (cqlsh) show correct column names for empty result sets (CASSANDRA-9813)
  * Add new types to Stress (CASSANDRA-9556)
  * Add property to allow listening on broadcast interface (CASSANDRA-9748)
  * Fix regression in split size on CqlInputFormat (CASSANDRA-10835)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/bcd68b54/bin/cqlsh.py
----------------------------------------------------------------------
diff --git a/bin/cqlsh.py b/bin/cqlsh.py
index 1119289..427fc29 100644
--- a/bin/cqlsh.py
+++ b/bin/cqlsh.py
@@ -1242,7 +1242,7 @@ class Shell(cmd.Cmd):
         elif result:
             # CAS INSERT/UPDATE
             self.writeresult("")
-            self.print_static_result(list(result), 
self.parse_for_table_meta(statement.query_string))
+            self.print_static_result(result.column_names, list(result), 
self.parse_for_table_meta(statement.query_string))
         self.flush_output()
         return True, future
 
@@ -1256,7 +1256,7 @@ class Shell(cmd.Cmd):
                 page = result.current_rows
                 if page:
                     num_rows += len(page)
-                    self.print_static_result(page, table_meta)
+                    self.print_static_result(result.column_names, page, 
table_meta)
                 if result.has_more_pages:
                     raw_input("---MORE---")
                     result.fetch_next_page()
@@ -1265,7 +1265,7 @@ class Shell(cmd.Cmd):
         else:
             rows = list(result)
             num_rows = len(rows)
-            self.print_static_result(rows, table_meta)
+            self.print_static_result(result.column_names, rows, table_meta)
         self.writeresult("(%d rows)" % num_rows)
 
         if self.decoding_errors:
@@ -1275,18 +1275,11 @@ class Shell(cmd.Cmd):
                 self.writeresult('%d more decoding errors suppressed.'
                                  % (len(self.decoding_errors) - 2), color=RED)
 
-    def print_static_result(self, rows, table_meta):
-        if not rows:
-            if not table_meta:
-                return
-            # print header only
-            colnames = table_meta.columns.keys()  # full header
-            formatted_names = [self.myformat_colname(name, table_meta) for 
name in colnames]
-            self.print_formatted_result(formatted_names, None)
+    def print_static_result(self, column_names, rows, table_meta):
+        if not column_names and not table_meta:
             return
-
-        colnames = rows[0].keys()
-        formatted_names = [self.myformat_colname(name, table_meta) for name in 
colnames]
+        column_names = column_names or table_meta.columns.keys()
+        formatted_names = [self.myformat_colname(name, table_meta) for name in 
column_names]
         formatted_values = [map(self.myformat_value, row.values()) for row in 
rows]
 
         if self.expand_enabled:

Reply via email to