Merge branch 'cassandra-2.1' into trunk

This commit is contained in:
Mikhail Stepura 2014-05-21 13:28:48 -07:00
commit c6eaffc2a1
8 changed files with 68 additions and 10 deletions

View File

@ -26,7 +26,7 @@
* remove unused classes (CASSANDRA-7197)
* Limit user types to the keyspace they are defined in (CASSANDRA-6643)
* 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)
Merged from 2.0:
* Always reallocate buffers in HSHA (CASSANDRA-6285)

View File

@ -33,7 +33,7 @@ from __future__ import with_statement
from uuid import UUID
description = "CQL Shell for Apache Cassandra"
version = "5.0.0"
version = "5.0.1"
from StringIO import StringIO
from contextlib import contextmanager, closing
@ -1000,11 +1000,12 @@ class Shell(cmd.Cmd):
out.write(ksdef.as_cql_query())
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:
out.write("USE %s;\n\n" % ksname)
out.write("USE %s;\n" % ksname)
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)
if cfs:

Binary file not shown.

View File

@ -1149,7 +1149,7 @@ class UserTypesMeta(object):
result[ksname] = {}
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)
def get_usertypes_names(self, keyspace):

View File

@ -821,3 +821,33 @@ class TestCqlshOutput(BaseTestCase):
def test_empty_line(self):
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")

View File

@ -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', '19', '19');
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'}});

View File

@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from cassandra.marshal import uint16_unpack
from cassandra.marshal import int32_unpack
from cassandra.cqltypes import CompositeType
import collections
from formatting import formatter_for, format_value_utype
@ -22,6 +22,8 @@ from formatting import formatter_for, format_value_utype
class UserType(CompositeType):
typename = "'org.apache.cassandra.db.marshal.UserType'"
FIELD_LENGTH = 4
@classmethod
def apply_parameters(cls, subtypes, names):
newname = subtypes[1].cassname.decode("hex")
@ -43,12 +45,11 @@ class UserType(CompositeType):
for col_type in cls.subtypes:
if p == len(byts):
break
itemlen = uint16_unpack(byts[p:p + 2])
p += 2
itemlen = int32_unpack(byts[p:p + cls.FIELD_LENGTH])
p += cls.FIELD_LENGTH
item = byts[p:p + itemlen]
p += itemlen
result.append(col_type.from_binary(item))
p += 1
if len(result) < len(cls.subtypes):
nones = [None] * (len(cls.subtypes) - len(result))