mirror of https://github.com/apache/cassandra
Support new UDT serialization format for CQLSH
patch by Mikhail Stepura; reviewed by Tyler Hobbs for CASSANDRA-7261
This commit is contained in:
parent
e06d74ef53
commit
a3effe6698
|
|
@ -17,7 +17,7 @@
|
||||||
* remove unused classes (CASSANDRA-7197)
|
* remove unused classes (CASSANDRA-7197)
|
||||||
* Limit user types to the keyspace they are defined in (CASSANDRA-6643)
|
* Limit user types to the keyspace they are defined in (CASSANDRA-6643)
|
||||||
* Add validate method to CollectionType (CASSANDRA-7208)
|
* Add validate method to CollectionType (CASSANDRA-7208)
|
||||||
* New serialization format for UDT values (CASSANDRA-7209)
|
* New serialization format for UDT values (CASSANDRA-7209, CASSANDRA-7261)
|
||||||
* Fix nodetool netstats (CASSANDRA-7270)
|
* Fix nodetool netstats (CASSANDRA-7270)
|
||||||
Merged from 2.0:
|
Merged from 2.0:
|
||||||
* Always reallocate buffers in HSHA (CASSANDRA-6285)
|
* Always reallocate buffers in HSHA (CASSANDRA-6285)
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ from __future__ import with_statement
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
description = "CQL Shell for Apache Cassandra"
|
description = "CQL Shell for Apache Cassandra"
|
||||||
version = "5.0.0"
|
version = "5.0.1"
|
||||||
|
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
from contextlib import contextmanager, closing
|
from contextlib import contextmanager, closing
|
||||||
|
|
@ -1000,11 +1000,12 @@ class Shell(cmd.Cmd):
|
||||||
out.write(ksdef.as_cql_query())
|
out.write(ksdef.as_cql_query())
|
||||||
out.write("\n\n")
|
out.write("\n\n")
|
||||||
|
|
||||||
uts = self.get_usertypes_meta().get_usertypes_names(ksname)
|
uts = self.get_usertypes_meta().get_usertypes_names(ksdef.name)
|
||||||
if uts:
|
if uts:
|
||||||
out.write("USE %s;\n\n" % ksname)
|
out.write("USE %s;\n" % ksname)
|
||||||
for ut in uts:
|
for ut in uts:
|
||||||
self.print_recreate_usertype(ksname, ut, out)
|
out.write('\n')
|
||||||
|
self.print_recreate_usertype(ksdef.name, ut, out)
|
||||||
|
|
||||||
cfs = self.get_columnfamily_names(ksdef.name)
|
cfs = self.get_columnfamily_names(ksdef.name)
|
||||||
if cfs:
|
if cfs:
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -1149,7 +1149,7 @@ class UserTypesMeta(object):
|
||||||
result[ksname] = {}
|
result[ksname] = {}
|
||||||
utname = row.type_name
|
utname = row.type_name
|
||||||
|
|
||||||
result[ksname][utname] = zip(row.column_names, row.column_types)
|
result[ksname][utname] = zip(row.field_names, row.field_types)
|
||||||
return cls(meta=result)
|
return cls(meta=result)
|
||||||
|
|
||||||
def get_usertypes_names(self, keyspace):
|
def get_usertypes_names(self, keyspace):
|
||||||
|
|
|
||||||
|
|
@ -821,3 +821,33 @@ class TestCqlshOutput(BaseTestCase):
|
||||||
|
|
||||||
def test_empty_line(self):
|
def test_empty_line(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_user_types_output(self):
|
||||||
|
self.assertCqlverQueriesGiveColoredOutput((
|
||||||
|
("select addresses from users;", r"""
|
||||||
|
addresses
|
||||||
|
MMMMMMMMM
|
||||||
|
--------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
{{city: 'Austin', address: '902 East 5th St. #202', zip: '78702'}, {city: 'Sunnyvale', address: '292 Gibraltar Drive #107', zip: '94089'}}
|
||||||
|
BBYYYYBBYYYYYYYYBBYYYYYYYBBYYYYYYYYYYYYYYYYYYYYYYYBBYYYBBYYYYYYYBBBBYYYYBBYYYYYYYYYYYBBYYYYYYYBBYYYYYYYYYYYYYYYYYYYYYYYYYYBBYYYBBYYYYYYYBB
|
||||||
|
|
||||||
|
|
||||||
|
(1 rows)
|
||||||
|
nnnnnnnn
|
||||||
|
"""),
|
||||||
|
), cqlver="3.1.6")
|
||||||
|
self.assertCqlverQueriesGiveColoredOutput((
|
||||||
|
("select phone_numbers from users;", r"""
|
||||||
|
phone_numbers
|
||||||
|
MMMMMMMMMMMMM
|
||||||
|
-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
{{country: '+1', number: '512-537-7809'}, {country: '+44', number: '208 622 3021'}}
|
||||||
|
BBYYYYYYYBBYYYYBBYYYYYYBBYYYYYYYYYYYYYYBBBBYYYYYYYBBYYYYYBBYYYYYYBBYYYYYYYYYYYYYYBB
|
||||||
|
|
||||||
|
|
||||||
|
(1 rows)
|
||||||
|
nnnnnnnn
|
||||||
|
"""),
|
||||||
|
), cqlver="3.1.6")
|
||||||
|
|
@ -197,3 +197,29 @@ INSERT INTO twenty_rows_composite_table (a, b, c) VALUES ('A', '17', '17');
|
||||||
INSERT INTO twenty_rows_composite_table (a, b, c) VALUES ('A', '18', '18');
|
INSERT INTO twenty_rows_composite_table (a, b, c) VALUES ('A', '18', '18');
|
||||||
INSERT INTO twenty_rows_composite_table (a, b, c) VALUES ('A', '19', '19');
|
INSERT INTO twenty_rows_composite_table (a, b, c) VALUES ('A', '19', '19');
|
||||||
INSERT INTO twenty_rows_composite_table (a, b, c) VALUES ('A', '20', '20');
|
INSERT INTO twenty_rows_composite_table (a, b, c) VALUES ('A', '20', '20');
|
||||||
|
|
||||||
|
CREATE TYPE address (
|
||||||
|
city text,
|
||||||
|
address text,
|
||||||
|
zip text
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TYPE phone_number (
|
||||||
|
country text,
|
||||||
|
number text
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE users (
|
||||||
|
login text PRIMARY KEY,
|
||||||
|
name text,
|
||||||
|
addresses set<address>,
|
||||||
|
phone_numbers set<phone_number>
|
||||||
|
);
|
||||||
|
|
||||||
|
insert into users (login, name, addresses, phone_numbers)
|
||||||
|
values ('jbellis',
|
||||||
|
'jonathan ellis',
|
||||||
|
{{city: 'Austin', address: '902 East 5th St. #202', zip: '78702'},
|
||||||
|
{city: 'Sunnyvale', address: '292 Gibraltar Drive #107', zip: '94089'}},
|
||||||
|
{{country: '+44', number: '208 622 3021'},
|
||||||
|
{country: '+1', number: '512-537-7809'}});
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from cassandra.marshal import uint16_unpack
|
from cassandra.marshal import int32_unpack
|
||||||
from cassandra.cqltypes import CompositeType
|
from cassandra.cqltypes import CompositeType
|
||||||
import collections
|
import collections
|
||||||
from formatting import formatter_for, format_value_utype
|
from formatting import formatter_for, format_value_utype
|
||||||
|
|
@ -22,6 +22,8 @@ from formatting import formatter_for, format_value_utype
|
||||||
class UserType(CompositeType):
|
class UserType(CompositeType):
|
||||||
typename = "'org.apache.cassandra.db.marshal.UserType'"
|
typename = "'org.apache.cassandra.db.marshal.UserType'"
|
||||||
|
|
||||||
|
FIELD_LENGTH = 4
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def apply_parameters(cls, subtypes, names):
|
def apply_parameters(cls, subtypes, names):
|
||||||
newname = subtypes[1].cassname.decode("hex")
|
newname = subtypes[1].cassname.decode("hex")
|
||||||
|
|
@ -43,12 +45,11 @@ class UserType(CompositeType):
|
||||||
for col_type in cls.subtypes:
|
for col_type in cls.subtypes:
|
||||||
if p == len(byts):
|
if p == len(byts):
|
||||||
break
|
break
|
||||||
itemlen = uint16_unpack(byts[p:p + 2])
|
itemlen = int32_unpack(byts[p:p + cls.FIELD_LENGTH])
|
||||||
p += 2
|
p += cls.FIELD_LENGTH
|
||||||
item = byts[p:p + itemlen]
|
item = byts[p:p + itemlen]
|
||||||
p += itemlen
|
p += itemlen
|
||||||
result.append(col_type.from_binary(item))
|
result.append(col_type.from_binary(item))
|
||||||
p += 1
|
|
||||||
|
|
||||||
if len(result) < len(cls.subtypes):
|
if len(result) < len(cls.subtypes):
|
||||||
nones = [None] * (len(cls.subtypes) - len(result))
|
nones = [None] * (len(cls.subtypes) - len(result))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue