cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ble...@apache.org
Subject [2/3] cassandra git commit: Fix update/delete behavior for static lists
Date Wed, 09 Sep 2015 20:12:57 GMT
Fix update/delete behavior for static lists

patch by Brett Snyder; reviewed by Benjamin Lerer for CASSANDRA-9838


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

Branch: refs/heads/cassandra-2.2
Commit: 21065423c6ce5a92194994bfa9e441d1d2b86b0a
Parents: 04e789b
Author: Brett Snyder <bsnyder788@gmail.com>
Authored: Wed Sep 9 21:49:14 2015 +0200
Committer: blerer <benjamin.lerer@datastax.com>
Committed: Wed Sep 9 21:49:14 2015 +0200

----------------------------------------------------------------------
 .../cql3/statements/ModificationStatement.java  |  6 ++++-
 .../validation/entities/CollectionsTest.java    | 23 ++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/21065423/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
index 876c5e4..37b46ae 100644
--- a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
@@ -29,6 +29,7 @@ import org.apache.cassandra.config.ColumnDefinition;
 import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.cql3.*;
 import org.apache.cassandra.db.*;
+import org.apache.cassandra.db.composites.AbstractCellNameType;
 import org.apache.cassandra.db.composites.CBuilder;
 import org.apache.cassandra.db.composites.Composite;
 import org.apache.cassandra.db.filter.ColumnSlice;
@@ -446,7 +447,10 @@ public abstract class ModificationStatement implements CQLStatement
             if (row.cf == null || row.cf.isEmpty())
                 continue;
 
-            Iterator<CQL3Row> iter = cfm.comparator.CQL3RowBuilder(cfm, now).group(row.cf.getSortedColumns().iterator());
+            CQL3Row.RowIterator iter = cfm.comparator.CQL3RowBuilder(cfm, now).group(row.cf.getSortedColumns().iterator());
+            if(iter.getStaticRow() != null) {
+                map.put(row.key.getKey(), iter.getStaticRow());
+            }
             if (iter.hasNext())
             {
                 map.put(row.key.getKey(), iter.next());

http://git-wip-us.apache.org/repos/asf/cassandra/blob/21065423/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
b/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
index 0241d4f..31dd5a6 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
@@ -485,4 +485,27 @@ public class CollectionsTest extends CQLTester
         assertInvalid("alter table %s add v set<int>");
     }
 
+
+    /**
+     * Test for 9838.
+     */
+    @Test
+    public void testUpdateStaticList() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k1 text, k2 text, s_list list<int> static, PRIMARY
KEY (k1, k2))");
+
+        execute("insert into %s (k1, k2) VALUES ('a','b')");
+        execute("update %s set s_list = s_list + [0] where k1='a'");
+        assertRows(execute("select s_list from %s where k1='a'"), row(list(0)));
+
+        execute("update %s set s_list[0] = 100 where k1='a'");
+        assertRows(execute("select s_list from %s where k1='a'"), row(list(100)));
+
+        execute("update %s set s_list = s_list + [0] where k1='a'");
+        assertRows(execute("select s_list from %s where k1='a'"), row(list(100, 0)));
+
+        execute("delete s_list[0] from %s where k1='a'");
+        assertRows(execute("select s_list from %s where k1='a'"), row(list(0)));
+    }
+
 }


Mime
View raw message