(cqlsh) show correct column names for empty result sets

patch by Adam Holmberg; reviewed by Ariel Weisberg for CASSANDRA-9813
This commit is contained in:
Adam Holmberg 2015-12-11 16:18:49 -06:00 committed by Aleksey Yeschenko
parent 9dd2b5ea0f
commit bcd68b546b
2 changed files with 8 additions and 14 deletions

View File

@ -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)

View File

@ -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: