cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [2/2] git commit: cqlsh: adapt to CASSANDRA-4018 system cf changes
Date Tue, 18 Sep 2012 07:31:32 GMT
cqlsh: adapt to CASSANDRA-4018 system cf changes


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/9ec77eb6
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/9ec77eb6
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/9ec77eb6

Branch: refs/heads/trunk
Commit: 9ec77eb66ec4106fde1b8ecaf17c2aca521fe9f0
Parents: 6fc3080
Author: paul cannon <paul@datastax.com>
Authored: Sat Aug 4 23:10:00 2012 -0600
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Tue Sep 18 09:09:39 2012 +0200

----------------------------------------------------------------------
 bin/cqlsh                      |   42 ++++++++++++++++++++++++++++------
 pylib/cqlshlib/cql3handling.py |   12 ++++++++-
 2 files changed, 44 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/9ec77eb6/bin/cqlsh
----------------------------------------------------------------------
diff --git a/bin/cqlsh b/bin/cqlsh
index 42a77cc..43b1e53 100755
--- a/bin/cqlsh
+++ b/bin/cqlsh
@@ -434,6 +434,7 @@ class Shell(cmd.Cmd):
                 tempcurs.execute('USE %s;' % self.cql_protect_name(keyspace))
                 tempcurs.close()
         self.cursor = self.conn.cursor()
+        self.get_connection_versions()
 
         self.current_keyspace = keyspace
 
@@ -470,6 +471,9 @@ class Shell(cmd.Cmd):
     def cqlver_atleast(self, major, minor=0, patch=0):
         return self.cql_ver_tuple[:3] >= (major, minor, patch)
 
+    def cassandraver_atleast(self, major, minor=0, patch=0):
+        return self.cass_ver_tuple[:3] >= (major, minor, patch)
+
     def myformat_value(self, val, casstype, **kwargs):
         if isinstance(val, DecodeError):
             self.decoding_errors.append(val)
@@ -491,7 +495,7 @@ class Shell(cmd.Cmd):
                 self.port)
 
     def show_version(self):
-        vers = self.get_cluster_versions()
+        vers = self.connection_versions.copy()
         vers['shver'] = version
         # system.Versions['cql'] apparently does not reflect changes with
         # set_cql_version.
@@ -524,7 +528,22 @@ class Shell(cmd.Cmd):
                           % (cf, colname, cql_typename(vtype))
         print
 
-    def get_cluster_versions(self):
+    def get_connection_versions(self):
+        try:
+            self.cursor.execute("select * from system.local where key = 'local'")
+        except cql.ProgrammingError:
+            vers = self.get_connection_versions_fallback()
+        else:
+            result = self.fetchdict()
+            vers = {
+                'build': result['release_version'],
+                'thrift': result['thrift_version'],
+                'cql': result['cql_version'],
+            }
+        self.connection_versions = vers
+        self.cass_ver_tuple = tuple(map(int, vers['build'].split('-', 1)[0].split('.', 2)))
+
+    def get_connection_versions_fallback(self):
         if self.cqlver_atleast(3):
             query = 'select component, version from system."Versions"'
         else:
@@ -660,15 +679,21 @@ class Shell(cmd.Cmd):
     def get_columnfamily_layout(self, ksname, cfname):
         if ksname is None:
             ksname = self.current_keyspace
-        self.cursor.execute("""select * from system.schema_columnfamilies
-                                where "keyspace"=:ks and "columnfamily"=:cf""",
-                            {'ks': ksname, 'cf': cfname})
+        if self.cassandraver_atleast(1, 2):
+            cf_q = """select * from system.schema_columnfamilies
+                       where keyspace_name=:ks and columnfamily_name=:cf"""
+            col_q = """select * from system.schema_columns
+                        where keyspace_name=:ks and columnfamily_name=:cf"""
+        else:
+            cf_q = """select * from system.schema_columnfamilies
+                       where "keyspace"=:ks and "columnfamily"=:cf"""
+            col_q = """select * from system.schema_columns
+                        where "keyspace"=:ks and "columnfamily"=:cf"""
+        self.cursor.execute(cf_q, {'ks': ksname, 'cf': cfname})
         layout = self.fetchdict()
         if layout is None:
             raise ColumnFamilyNotFound("Column family %r not found" % cfname)
-        self.cursor.execute("""select * from system.schema_columns
-                                where "keyspace"=:ks and "columnfamily"=:cf""",
-                            {'ks': ksname, 'cf': cfname})
+        self.cursor.execute(col_q, {'ks': ksname, 'cf': cfname})
         cols = self.fetchdict_all()
         return cql3handling.CqlTableDef.from_layout(layout, cols)
 
@@ -1544,6 +1569,7 @@ class Shell(cmd.Cmd):
 
         showwhat = parsed.get_binding('what').lower()
         if showwhat == 'version':
+            self.get_connection_versions()
             self.show_version()
         elif showwhat == 'host':
             self.show_host()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/9ec77eb6/pylib/cqlshlib/cql3handling.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py
index 13ce07a..f1d7f81 100644
--- a/pylib/cqlshlib/cql3handling.py
+++ b/pylib/cqlshlib/cql3handling.py
@@ -692,7 +692,11 @@ class CqlColumnDef:
 
     @classmethod
     def from_layout(cls, layout):
-        c = cls(layout[u'column'], cql_typename(layout[u'validator']))
+        try:
+            colname = layout[u'column_name']
+        except KeyError:
+            colname = layout[u'column']
+        c = cls(colname, cql_typename(layout[u'validator']))
         c.index_name = layout[u'index_name']
         return c
 
@@ -716,7 +720,11 @@ class CqlTableDef:
 
     @classmethod
     def from_layout(cls, layout, coldefs):
-        cf = cls(name=layout[u'columnfamily'])
+        try:
+            cfname = layout[u'columnfamily_name']
+        except KeyError:
+            cfname = layout[u'columnfamily']
+        cf = cls(name=cfname)
         for attr, val in layout.items():
             setattr(cf, attr.encode('ascii'), val)
         for attr in cls.json_attrs:


Mime
View raw message