Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 36D02DDBE for ; Tue, 18 Sep 2012 07:31:36 +0000 (UTC) Received: (qmail 10114 invoked by uid 500); 18 Sep 2012 07:31:35 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 9904 invoked by uid 500); 18 Sep 2012 07:31:35 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 9788 invoked by uid 99); 18 Sep 2012 07:31:33 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Sep 2012 07:31:33 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id CC06C3759E; Tue, 18 Sep 2012 07:31:32 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: slebresne@apache.org To: commits@cassandra.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [2/2] git commit: cqlsh: adapt to CASSANDRA-4018 system cf changes Message-Id: <20120918073132.CC06C3759E@tyr.zones.apache.org> Date: Tue, 18 Sep 2012 07:31:32 +0000 (UTC) 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 Authored: Sat Aug 4 23:10:00 2012 -0600 Committer: Sylvain Lebresne 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: