Skip to content

Commit

Permalink
cqlsh: fix DESC TYPE with non-ascii character in the identifier
Browse files Browse the repository at this point in the history
Patch by Adam Holmberg; reviewed by brandonwilliams for CASSANDRA-16400
  • Loading branch information
aholmberg authored and driftx committed May 17, 2021
1 parent 326d61e commit 0301fc6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
@@ -1,4 +1,5 @@
4.0-rc2
* cqlsh: fix DESC TYPE with non-ascii character in the identifier (CASSANDRA-16400)
* Remove drivers dependency and bring cql_keywords_reserved on server side (CASSANDRA-16659)
* Fix in-browser "help", Python 3 (CASSANDRA-16658)
* Fix DROP COMPACT STORAGE for counters (CASSANDRA-16653)
Expand Down
18 changes: 8 additions & 10 deletions bin/cqlsh.py
Expand Up @@ -618,37 +618,37 @@ def get_connection_versions(self):
self.connection_versions = vers

def get_keyspace_names(self):
return list(map(str, list(self.conn.metadata.keyspaces.keys())))
return list(self.conn.metadata.keyspaces)

def get_columnfamily_names(self, ksname=None):
if ksname is None:
ksname = self.current_keyspace

return list(map(str, list(self.get_keyspace_meta(ksname).tables.keys())))
return list(self.get_keyspace_meta(ksname).tables)

def get_materialized_view_names(self, ksname=None):
if ksname is None:
ksname = self.current_keyspace

return list(map(str, list(self.get_keyspace_meta(ksname).views.keys())))
return list(self.get_keyspace_meta(ksname).views)

def get_index_names(self, ksname=None):
if ksname is None:
ksname = self.current_keyspace

return list(map(str, list(self.get_keyspace_meta(ksname).indexes.keys())))
return list(self.get_keyspace_meta(ksname).indexes)

def get_column_names(self, ksname, cfname):
if ksname is None:
ksname = self.current_keyspace
layout = self.get_table_meta(ksname, cfname)
return [str(col) for col in layout.columns]
return list(layout.columns)

def get_usertype_names(self, ksname=None):
if ksname is None:
ksname = self.current_keyspace

return list(self.get_keyspace_meta(ksname).user_types.keys())
return list(self.get_keyspace_meta(ksname).user_types)

def get_usertype_layout(self, ksname, typename):
if ksname is None:
Expand Down Expand Up @@ -1400,9 +1400,7 @@ def describe_keyspaces(self, rows):
"""
Print the output for a DESCRIBE KEYSPACES query
"""
names = list()
for row in rows:
names.append(str(row['name']))
names = [ensure_str(r['name']) for r in rows]

print('')
cmd.Cmd.columnize(self, names)
Expand All @@ -1422,7 +1420,7 @@ def describe_list(self, rows):
keyspace = row['keyspace_name']
names = list()

names.append(str(row['name']))
names.append(ensure_str(row['name']))

if keyspace is not None:
self.print_keyspace_element_names(keyspace, names)
Expand Down
2 changes: 1 addition & 1 deletion pylib/cqlshlib/copyutil.py
Expand Up @@ -560,7 +560,7 @@ def open(self):

if self.header:
writer = csv.writer(self.current_dest.output, **self.options.dialect)
writer.writerow(self.columns)
writer.writerow([ensure_str(c) for c in self.columns])

return True

Expand Down
5 changes: 1 addition & 4 deletions pylib/cqlshlib/test/test_cqlsh_completion.py
Expand Up @@ -696,10 +696,7 @@ def test_complete_in_create_table(self):
self.trycompletions('CREATE TA', immediate='BLE ')
self.create_columnfamily_table_template('TABLE')

def test_complete_in_describe(self):
"""
Tests for Cassandra-10733
"""
def test_complete_in_describe(self): # Cassandra-10733
self.trycompletions('DES', immediate='C')
# quoted_keyspace = '"' + self.cqlsh.keyspace + '"'
self.trycompletions('DESCR', immediate='IBE ')
Expand Down
12 changes: 11 additions & 1 deletion pylib/cqlshlib/test/test_unicode.py
Expand Up @@ -56,10 +56,20 @@ def test_unicode_identifier(self):
output = c.cmd_and_response('SELECT * FROM t;')
self.assertIn(col_name, output)

def test_multiline_input(self): # CASSANDRA-16539
def test_unicode_multiline_input(self): # CASSANDRA-16400
with testrun_cqlsh(tty=True, env=self.default_env) as c:
value = '値'
c.send("INSERT INTO t(k, v) VALUES (1, \n'%s');\n" % (value,))
c.read_to_next_prompt()
output = c.cmd_and_response('SELECT v FROM t;')
self.assertIn(value, output)

def test_unicode_desc(self): # CASSANDRA-16539
with testrun_cqlsh(tty=True, env=self.default_env) as c:
v1 = 'ࠑ'
v2 = 'Ξ'
output = c.cmd_and_response('CREATE TYPE "%s" ( "%s" int );' % (v1, v2))
output = c.cmd_and_response('DESC TYPES;')
self.assertIn(v1, output)
output = c.cmd_and_response('DESC TYPE "%s";' %(v1,))
self.assertIn(v2, output)

0 comments on commit 0301fc6

Please sign in to comment.