You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by mi...@apache.org on 2014/05/21 22:29:13 UTC
[2/3] git commit: Support new UDT serialization format for CQLSH
Support new UDT serialization format for CQLSH
patch by Mikhail Stepura; reviewed by Tyler Hobbs for CASSANDRA-7261
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/a3effe66
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/a3effe66
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/a3effe66
Branch: refs/heads/trunk
Commit: a3effe6698bca8e4a18b29d010a0e36cbcd9b591
Parents: e06d74e
Author: Mikhail Stepura <mi...@apache.org>
Authored: Tue May 20 18:58:31 2014 -0700
Committer: Mikhail Stepura <mi...@apache.org>
Committed: Wed May 21 13:27:55 2014 -0700
----------------------------------------------------------------------
CHANGES.txt | 2 +-
bin/cqlsh | 9 +++---
...assandra-driver-internal-only-1.0.2.post.zip | Bin 95846 -> 0 bytes
lib/cassandra-driver-internal-only-1.1.2.zip | Bin 0 -> 105983 bytes
pylib/cqlshlib/cql3handling.py | 2 +-
pylib/cqlshlib/test/test_cqlsh_output.py | 30 +++++++++++++++++++
pylib/cqlshlib/test/test_keyspace_init.cql | 26 ++++++++++++++++
pylib/cqlshlib/usertypes.py | 9 +++---
8 files changed, 68 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a3effe66/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 61ea788..e2ca9b5 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -17,7 +17,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)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a3effe66/bin/cqlsh
----------------------------------------------------------------------
diff --git a/bin/cqlsh b/bin/cqlsh
index f9b433d..c242010 100755
--- a/bin/cqlsh
+++ b/bin/cqlsh
@@ -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:
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a3effe66/lib/cassandra-driver-internal-only-1.0.2.post.zip
----------------------------------------------------------------------
diff --git a/lib/cassandra-driver-internal-only-1.0.2.post.zip b/lib/cassandra-driver-internal-only-1.0.2.post.zip
deleted file mode 100644
index 7ccd5f7..0000000
Binary files a/lib/cassandra-driver-internal-only-1.0.2.post.zip and /dev/null differ
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a3effe66/lib/cassandra-driver-internal-only-1.1.2.zip
----------------------------------------------------------------------
diff --git a/lib/cassandra-driver-internal-only-1.1.2.zip b/lib/cassandra-driver-internal-only-1.1.2.zip
new file mode 100644
index 0000000..cd5181c
Binary files /dev/null and b/lib/cassandra-driver-internal-only-1.1.2.zip differ
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a3effe66/pylib/cqlshlib/cql3handling.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py
index 14b3dba..e4364a0 100644
--- a/pylib/cqlshlib/cql3handling.py
+++ b/pylib/cqlshlib/cql3handling.py
@@ -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):
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a3effe66/pylib/cqlshlib/test/test_cqlsh_output.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/test/test_cqlsh_output.py b/pylib/cqlshlib/test/test_cqlsh_output.py
index 5a2a837..32cdbe1 100644
--- a/pylib/cqlshlib/test/test_cqlsh_output.py
+++ b/pylib/cqlshlib/test/test_cqlsh_output.py
@@ -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")
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a3effe66/pylib/cqlshlib/test/test_keyspace_init.cql
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/test/test_keyspace_init.cql b/pylib/cqlshlib/test/test_keyspace_init.cql
index 8079cd5..6f44e92 100644
--- a/pylib/cqlshlib/test/test_keyspace_init.cql
+++ b/pylib/cqlshlib/test/test_keyspace_init.cql
@@ -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'}});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a3effe66/pylib/cqlshlib/usertypes.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/usertypes.py b/pylib/cqlshlib/usertypes.py
index 1ca9b11..22d3080 100644
--- a/pylib/cqlshlib/usertypes.py
+++ b/pylib/cqlshlib/usertypes.py
@@ -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))