cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/2] cassandra git commit: Fix deleting from an empty list
Date Wed, 22 Apr 2015 08:45:32 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 5e68fcec4 -> 6ad452e47


Fix deleting from an empty list

patch by jjirsa; reviewed by blerer for CASSANDRA-9198


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

Branch: refs/heads/trunk
Commit: f56244d21a331cec7da5b751a4de9effad49952b
Parents: 49c1dbd
Author: Jeff Jirsa <jeff@jeffjirsa.net>
Authored: Wed Apr 22 10:42:30 2015 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Wed Apr 22 10:42:30 2015 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 src/java/org/apache/cassandra/cql3/Lists.java   |  4 +--
 .../apache/cassandra/cql3/UpdateParameters.java |  6 +++-
 .../apache/cassandra/cql3/CollectionsTest.java  | 34 ++++++++++++++++++--
 4 files changed, 39 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f56244d2/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 9211270..e36c67e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.5
+ * Fix deleting from an empty list (CASSANDRA-9198)
  * Update tuple and collection types that use a user-defined type when that UDT
    is modified (CASSANDRA-9148, CASSANDRA-9192)
  * Re-add deprecated cold_reads_to_omit param for backwards compat (CASSANDRA-9203)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f56244d2/src/java/org/apache/cassandra/cql3/Lists.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/Lists.java b/src/java/org/apache/cassandra/cql3/Lists.java
index 6ca495b..a939a27 100644
--- a/src/java/org/apache/cassandra/cql3/Lists.java
+++ b/src/java/org/apache/cassandra/cql3/Lists.java
@@ -342,7 +342,7 @@ public abstract class Lists
 
             List<Cell> existingList = params.getPrefetchedList(rowKey, column.name);
             int idx = ByteBufferUtil.toInt(index);
-            if (existingList == null)
+            if (existingList == null || existingList.size() == 0)
                 throw new InvalidRequestException("Attempted to set an element on a list
which is null");
             if (idx < 0 || idx >= existingList.size())
                 throw new InvalidRequestException(String.format("List index %d out of bound,
list has size %d", idx, existingList.size()));
@@ -500,7 +500,7 @@ public abstract class Lists
 
             List<Cell> existingList = params.getPrefetchedList(rowKey, column.name);
             int idx = ByteBufferUtil.toInt(index.get(params.options));
-            if (existingList == null)
+            if (existingList == null || existingList.size() == 0)
                 throw new InvalidRequestException("Attempted to delete an element from a
list which is null");
             if (idx < 0 || idx >= existingList.size())
                 throw new InvalidRequestException(String.format("List index %d out of bound,
list has size %d", idx, existingList.size()));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f56244d2/src/java/org/apache/cassandra/cql3/UpdateParameters.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/UpdateParameters.java b/src/java/org/apache/cassandra/cql3/UpdateParameters.java
index 74c3214..e412585 100644
--- a/src/java/org/apache/cassandra/cql3/UpdateParameters.java
+++ b/src/java/org/apache/cassandra/cql3/UpdateParameters.java
@@ -97,6 +97,10 @@ public class UpdateParameters
             return Collections.emptyList();
 
         CQL3Row row = prefetchedLists.get(rowKey);
-        return row == null ? Collections.<Cell>emptyList() : row.getMultiCellColumn(cql3ColumnName);
+        if (row == null)
+            return Collections.<Cell>emptyList();
+
+        List<Cell> cql3List = row.getMultiCellColumn(cql3ColumnName);
+        return (cql3List == null) ? Collections.<Cell>emptyList() : cql3List;
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f56244d2/test/unit/org/apache/cassandra/cql3/CollectionsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/CollectionsTest.java b/test/unit/org/apache/cassandra/cql3/CollectionsTest.java
index 3d266b7..53895d0 100644
--- a/test/unit/org/apache/cassandra/cql3/CollectionsTest.java
+++ b/test/unit/org/apache/cassandra/cql3/CollectionsTest.java
@@ -107,6 +107,11 @@ public class CollectionsTest extends CQLTester
             row(set("v7"))
         );
 
+        execute("DELETE s[?] FROM %s WHERE k = 0", set("v7"));
+
+        // Deleting an element that does not exist will succeed
+        execute("DELETE s[?] FROM %s WHERE k = 0", set("v7"));
+
         execute("DELETE s FROM %s WHERE k = 0");
 
         assertRows(execute("SELECT s FROM %s WHERE k = 0"),
@@ -150,6 +155,31 @@ public class CollectionsTest extends CQLTester
             row(map("v5", 5, "v6", 6, "v7", 7))
         );
 
+        execute("DELETE m[?] FROM %s WHERE k = 0", "v7");
+
+        assertRows(execute("SELECT m FROM %s WHERE k = 0"),
+            row(map("v5", 5, "v6", 6))
+        );
+
+        execute("DELETE m[?] FROM %s WHERE k = 0", "v6");
+
+        assertRows(execute("SELECT m FROM %s WHERE k = 0"),
+            row(map("v5", 5))
+        );
+
+        execute("DELETE m[?] FROM %s WHERE k = 0", "v5");
+
+        assertRows(execute("SELECT m FROM %s WHERE k = 0"),
+            row((Object)null)
+        );
+
+        // Deleting a non-existing key should succeed
+        execute("DELETE m[?] FROM %s WHERE k = 0", "v5");
+
+        assertRows(execute("SELECT m FROM %s WHERE k = 0"),
+            row((Object) null)
+        );
+
         // The empty map is parsed as an empty set (because we don't have enough info at
parsing
         // time when we see a {}) and special cased later. This test checks this work properly
         execute("UPDATE %s SET m = {} WHERE k = 0");
@@ -203,9 +233,7 @@ public class CollectionsTest extends CQLTester
         assertInvalidMessage("Attempted to set an element on a list which is null",
                              "UPDATE %s SET l[0] = ? WHERE k=0", list("v10"));
 
-        assertInvalidMessage("Attempted to delete an element from a list which is null",
-                             "UPDATE %s SET l = l - ? WHERE k=0 ",
-                             list("v11"));
+        execute("UPDATE %s SET l = l - ? WHERE k=0 ", list("v11"));
 
         assertRows(execute("SELECT l FROM %s WHERE k = 0"), row((Object) null));
     }


Mime
View raw message