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 D042611C62 for ; Wed, 20 Aug 2014 22:47:21 +0000 (UTC) Received: (qmail 7857 invoked by uid 500); 20 Aug 2014 22:47:21 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 7823 invoked by uid 500); 20 Aug 2014 22:47:21 -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 7812 invoked by uid 99); 20 Aug 2014 22:47:21 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Aug 2014 22:47:21 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 55410982BCE; Wed, 20 Aug 2014 22:47:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tylerhobbs@apache.org To: commits@cassandra.apache.org Message-Id: <62e57f6cb8fd478a88c53f55a761749e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: cqlsh: preserve original result column names Date: Wed, 20 Aug 2014 22:47:21 +0000 (UTC) Repository: cassandra Updated Branches: refs/heads/cassandra-2.1.0 58554decc -> c4191ed1c cqlsh: preserve original result column names Patch by Tyler Hobbs; reviewed by Aleksey Yeschenko for CASSANDRA-7806 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/c4191ed1 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/c4191ed1 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/c4191ed1 Branch: refs/heads/cassandra-2.1.0 Commit: c4191ed1c9a3f623b2f37a5aab51a76174ee2eeb Parents: 58554de Author: Tyler Hobbs Authored: Wed Aug 20 17:46:41 2014 -0500 Committer: Tyler Hobbs Committed: Wed Aug 20 17:46:41 2014 -0500 ---------------------------------------------------------------------- CHANGES.txt | 2 ++ bin/cqlsh | 15 ++++++++------- pylib/cqlshlib/cql3handling.py | 8 ++++---- 3 files changed, 14 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/c4191ed1/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 2664f0f..92a177d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,6 @@ 2.1.0 + * (cqlsh) Fix column name formatting for functions, CAS operations, + and UDT field selections (CASSANDRA-7806) * (cqlsh) Fix COPY FROM handling of null/empty primary key values (CASSANDRA-7792) * Fix ordering of static cells (CASSANDRA-7763) http://git-wip-us.apache.org/repos/asf/cassandra/blob/c4191ed1/bin/cqlsh ---------------------------------------------------------------------- diff --git a/bin/cqlsh b/bin/cqlsh index 4c90f2d..686e07b 100755 --- a/bin/cqlsh +++ b/bin/cqlsh @@ -107,7 +107,7 @@ except ImportError, e: 'Error: %s\n' % (sys.executable, sys.path, e)) from cassandra.cluster import Cluster -from cassandra.query import SimpleStatement +from cassandra.query import SimpleStatement, ordered_dict_factory from cassandra.policies import WhiteListRoundRobinPolicy from cassandra.metadata import protect_name, protect_names, protect_value from cassandra.auth import PlainTextAuthProvider @@ -521,6 +521,7 @@ class Shell(cmd.Cmd): self.session = self.conn.connect(keyspace) else: self.session = self.conn.connect() + self.session.row_factory = ordered_dict_factory self.get_connection_versions() self.current_keyspace = keyspace @@ -612,9 +613,9 @@ class Shell(cmd.Cmd): def get_connection_versions(self): result, = self.session.execute("select * from system.local where key = 'local'") vers = { - 'build': result.release_version, - 'protocol': result.native_protocol_version, - 'cql': result.cql_version, + 'build': result['release_version'], + 'protocol': result['native_protocol_version'], + 'cql': result['cql_version'], } self.connection_versions = vers self.cass_ver_tuple = tuple(map(int, vers['build'].split('-', 1)[0].split('.')[:3])) @@ -952,9 +953,9 @@ class Shell(cmd.Cmd): def print_static_result(self, rows): if not rows: return - colnames = rows[0]._fields + colnames = rows[0].keys() formatted_names = [self.myformat_colname(name) for name in colnames] - formatted_values = [map(self.myformat_value, row) for row in rows] + formatted_values = [map(self.myformat_value, row.values()) for row in rows] if self.expand_enabled: self.print_formatted_result_vertically(formatted_names, formatted_values) else: @@ -1423,7 +1424,7 @@ class Shell(cmd.Cmd): format_value(v, output_encoding=encoding, nullval=nullval, time_format=self.display_time_format, float_precision=self.display_float_precision).strval - writer.writerow(map(fmt, row)) + writer.writerow(map(fmt, row.values())) rows += 1 finally: if do_close: http://git-wip-us.apache.org/repos/asf/cassandra/blob/c4191ed1/pylib/cqlshlib/cql3handling.py ---------------------------------------------------------------------- diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py index 3d489d3..1c9b00f 100644 --- a/pylib/cqlshlib/cql3handling.py +++ b/pylib/cqlshlib/cql3handling.py @@ -1149,7 +1149,7 @@ def username_name_completer(ctxt, cass): return [Hint('')] session = cass.session - return [maybe_quote(row[0].replace("'", "''")) for row in session.execute("LIST USERS")] + return [maybe_quote(row.values()[0].replace("'", "''")) for row in session.execute("LIST USERS")] # END SYNTAX/COMPLETION RULE DEFINITIONS @@ -1167,12 +1167,12 @@ class UserTypesMeta(object): def from_layout(cls, layout): result = {} for row in layout: - ksname = row.keyspace_name + ksname = row['keyspace_name'] if ksname not in result: result[ksname] = {} - utname = row.type_name + utname = row['type_name'] - result[ksname][utname] = zip(row.field_names, row.field_types) + result[ksname][utname] = zip(row['field_names'], row['field_types']) return cls(meta=result) def get_usertypes_names(self, keyspace):