mirror of https://github.com/apache/cassandra
cqlsh fails to format collections when using aliases
Patch by Stefania Alborghetti; reviewed by Robert Stupp for CASSANDRA-11534
This commit is contained in:
parent
541d837070
commit
a0419085d5
|
|
@ -1,4 +1,5 @@
|
||||||
3.10
|
3.10
|
||||||
|
* cqlsh fails to format collections when using aliases (CASSANDRA-11534)
|
||||||
* Check for hash conflicts in prepared statements (CASSANDRA-12733)
|
* Check for hash conflicts in prepared statements (CASSANDRA-12733)
|
||||||
* Exit query parsing upon first error (CASSANDRA-12598)
|
* Exit query parsing upon first error (CASSANDRA-12598)
|
||||||
* Fix cassandra-stress to use single seed in UUID generation (CASSANDRA-12729)
|
* Fix cassandra-stress to use single seed in UUID generation (CASSANDRA-12729)
|
||||||
|
|
|
||||||
30
bin/cqlsh.py
30
bin/cqlsh.py
|
|
@ -151,6 +151,7 @@ except ImportError, e:
|
||||||
|
|
||||||
from cassandra.auth import PlainTextAuthProvider
|
from cassandra.auth import PlainTextAuthProvider
|
||||||
from cassandra.cluster import Cluster
|
from cassandra.cluster import Cluster
|
||||||
|
from cassandra.cqltypes import cql_typename
|
||||||
from cassandra.marshal import int64_unpack
|
from cassandra.marshal import int64_unpack
|
||||||
from cassandra.metadata import (ColumnMetadata, KeyspaceMetadata,
|
from cassandra.metadata import (ColumnMetadata, KeyspaceMetadata,
|
||||||
TableMetadata, protect_name, protect_names)
|
TableMetadata, protect_name, protect_names)
|
||||||
|
|
@ -1289,7 +1290,7 @@ class Shell(cmd.Cmd):
|
||||||
elif result:
|
elif result:
|
||||||
# CAS INSERT/UPDATE
|
# CAS INSERT/UPDATE
|
||||||
self.writeresult("")
|
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()
|
self.flush_output()
|
||||||
return True, future
|
return True, future
|
||||||
|
|
||||||
|
|
@ -1300,19 +1301,17 @@ class Shell(cmd.Cmd):
|
||||||
if result.has_more_pages and self.tty:
|
if result.has_more_pages and self.tty:
|
||||||
num_rows = 0
|
num_rows = 0
|
||||||
while True:
|
while True:
|
||||||
page = result.current_rows
|
if result.current_rows:
|
||||||
if page:
|
num_rows += len(result.current_rows)
|
||||||
num_rows += len(page)
|
self.print_static_result(result, table_meta)
|
||||||
self.print_static_result(result.column_names, page, table_meta)
|
|
||||||
if result.has_more_pages:
|
if result.has_more_pages:
|
||||||
raw_input("---MORE---")
|
raw_input("---MORE---")
|
||||||
result.fetch_next_page()
|
result.fetch_next_page()
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
rows = list(result)
|
num_rows = len(result.current_rows)
|
||||||
num_rows = len(rows)
|
self.print_static_result(result, table_meta)
|
||||||
self.print_static_result(result.column_names, rows, table_meta)
|
|
||||||
self.writeresult("(%d rows)" % num_rows)
|
self.writeresult("(%d rows)" % num_rows)
|
||||||
|
|
||||||
if self.decoding_errors:
|
if self.decoding_errors:
|
||||||
|
|
@ -1322,24 +1321,23 @@ class Shell(cmd.Cmd):
|
||||||
self.writeresult('%d more decoding errors suppressed.'
|
self.writeresult('%d more decoding errors suppressed.'
|
||||||
% (len(self.decoding_errors) - 2), color=RED)
|
% (len(self.decoding_errors) - 2), color=RED)
|
||||||
|
|
||||||
def print_static_result(self, column_names, rows, table_meta):
|
def print_static_result(self, result, table_meta):
|
||||||
if not column_names and not table_meta:
|
if not result.column_names and not table_meta:
|
||||||
return
|
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]
|
formatted_names = [self.myformat_colname(name, table_meta) for name in column_names]
|
||||||
if not rows:
|
if not result.current_rows:
|
||||||
# print header only
|
# print header only
|
||||||
self.print_formatted_result(formatted_names, None)
|
self.print_formatted_result(formatted_names, None)
|
||||||
return
|
return
|
||||||
|
|
||||||
cql_types = []
|
cql_types = []
|
||||||
if table_meta:
|
if result.column_types:
|
||||||
ks_meta = self.conn.metadata.keyspaces[table_meta.keyspace_name]
|
ks_meta = self.conn.metadata.keyspaces[table_meta.keyspace_name]
|
||||||
cql_types = [CqlType(table_meta.columns[c].cql_type, ks_meta)
|
cql_types = [CqlType(cql_typename(t), ks_meta) for t in result.column_types]
|
||||||
if c in table_meta.columns else None for c in column_names]
|
|
||||||
|
|
||||||
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:
|
if self.expand_enabled:
|
||||||
self.print_formatted_result_vertically(formatted_names, formatted_values)
|
self.print_formatted_result_vertically(formatted_names, formatted_values)
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -847,3 +847,18 @@ class TestCqlshOutput(BaseTestCase):
|
||||||
nnnnnnnn
|
nnnnnnnn
|
||||||
"""),
|
"""),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
self.assertQueriesGiveColoredOutput((
|
||||||
|
("select tags as my_tags from songs;", r"""
|
||||||
|
my_tags
|
||||||
|
MMMMMMM
|
||||||
|
-------------------------------------------------
|
||||||
|
|
||||||
|
{tags: {'genre': 'metal', 'origin': 'england'}}
|
||||||
|
BYYYYBBBYYYYYYYBBYYYYYYYBBYYYYYYYYBBYYYYYYYYYBB
|
||||||
|
|
||||||
|
|
||||||
|
(1 rows)
|
||||||
|
nnnnnnnn
|
||||||
|
"""),
|
||||||
|
))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue