cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject cassandra git commit: Improve COPY command to work with Counter columns
Date Fri, 20 Nov 2015 14:06:30 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 882adf0ae -> 05ccdc641


Improve COPY command to work with Counter columns

patch by jasonstack; reviewed by Stefania for CASSANDRA-9043


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

Branch: refs/heads/cassandra-2.1
Commit: 05ccdc6411b9d3388a74ba06d1ce153d33ffe1c3
Parents: 882adf0
Author: Stefania Alborghetti <stefania.alborghetti@datastax.com>
Authored: Thu Nov 19 09:02:03 2015 +0800
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Fri Nov 20 15:03:47 2015 +0100

----------------------------------------------------------------------
 CHANGES.txt |  1 +
 bin/cqlsh   | 27 +++++++++++++++++++++------
 2 files changed, 22 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/05ccdc64/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 9e2869e..86e5cb2 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.12
+ * (cqlsh) Support counters in COPY commands (CASSANDRA-9043)
  * Try next replica if not possible to connect to primary replica on
    ColumnFamilyRecordReader (CASSANDRA-2388)
  * Limit window size in DTCS (CASSANDRA-10280)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/05ccdc64/bin/cqlsh
----------------------------------------------------------------------
diff --git a/bin/cqlsh b/bin/cqlsh
index 5459d67..56cd218 100755
--- a/bin/cqlsh
+++ b/bin/cqlsh
@@ -1696,10 +1696,16 @@ class Shell(cmd.Cmd):
         pk_cols = [col.name for col in table_meta.primary_key]
         cqltypes = [table_meta.columns[name].typestring for name in columns]
         pk_indexes = [columns.index(col.name) for col in table_meta.primary_key]
-        query = 'INSERT INTO %s.%s (%s) VALUES (%%s)' % (
-            protect_name(ks),
-            protect_name(cf),
-            ', '.join(protect_names(columns)))
+        is_counter_table = ("counter" in cqltypes)
+        if is_counter_table:
+            query = 'Update %s.%s SET %%s WHERE %%s' % (
+                protect_name(ks),
+                protect_name(cf))
+        else:
+            query = 'INSERT INTO %s.%s (%s) VALUES (%%s)' % (
+                protect_name(ks),
+                protect_name(cf),
+                ', '.join(protect_names(columns)))
 
         # we need to handle some types specially
         should_escape = [t in ('ascii', 'text', 'timestamp', 'date', 'time', 'inet') for
t in cqltypes]
@@ -1764,8 +1770,17 @@ class Shell(cmd.Cmd):
                         return
                     else:
                         row[i] = 'null'
-
-                full_query = query % (','.join(row),)
+                if is_counter_table:
+                    where_clause = []
+                    set_clause = []
+                    for i, value in enumerate(row):
+                        if i in pk_indexes:
+                            where_clause.append("%s=%s" % (columns[i], value))
+                        else:
+                            set_clause.append("%s=%s+%s" % (columns[i], columns[i], value))
+                    full_query = query % (','.join(set_clause), ' AND '.join(where_clause))
+                else:
+                    full_query = query % (','.join(row),)
                 query_message = QueryMessage(
                     full_query, self.consistency_level, serial_consistency_level=None,
                     fetch_size=None, paging_state=None, timestamp=insert_timestamp)


Mime
View raw message