You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ty...@apache.org on 2014/12/05 20:16:08 UTC
cassandra git commit: Fix NPE in SelectStatement with empty IN values
Repository: cassandra
Updated Branches:
refs/heads/trunk 58c88b7d5 -> 98cf63431
Fix NPE in SelectStatement with empty IN values
Patch by Benjamin Lerer; reviewed by Tyler Hobbs for CASSANDRA-8419
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/98cf6343
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/98cf6343
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/98cf6343
Branch: refs/heads/trunk
Commit: 98cf63431af3d1cd6a411e311250ab71961df9e7
Parents: 58c88b7
Author: blerer <b_...@hotmail.com>
Authored: Fri Dec 5 13:15:35 2014 -0600
Committer: Tyler Hobbs <ty...@datastax.com>
Committed: Fri Dec 5 13:15:35 2014 -0600
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../SingleColumnPrimaryKeyRestrictions.java | 9 +++++++--
.../cassandra/cql3/MultiColumnRelationTest.java | 4 ++++
.../cassandra/cql3/SingleColumnRelationTest.java | 16 ++++++++++++++++
4 files changed, 28 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/98cf6343/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index f5a5f6a..588f58f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
3.0
+ * Fix NPE in SelectStatement with empty IN values (CASSANDRA-8419)
* Refactor SelectStatement, return IN results in natural order instead
of IN value list order (CASSANDRA-7981)
* Support UDTs, tuples, and collections in user-defined
http://git-wip-us.apache.org/repos/asf/cassandra/blob/98cf6343/src/java/org/apache/cassandra/cql3/restrictions/SingleColumnPrimaryKeyRestrictions.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/restrictions/SingleColumnPrimaryKeyRestrictions.java b/src/java/org/apache/cassandra/cql3/restrictions/SingleColumnPrimaryKeyRestrictions.java
index 3858cdc..5c8386e 100644
--- a/src/java/org/apache/cassandra/cql3/restrictions/SingleColumnPrimaryKeyRestrictions.java
+++ b/src/java/org/apache/cassandra/cql3/restrictions/SingleColumnPrimaryKeyRestrictions.java
@@ -186,7 +186,7 @@ final class SingleColumnPrimaryKeyRestrictions extends AbstractPrimaryKeyRestric
List<ByteBuffer> values = r.values(options);
if (values.isEmpty())
- return null;
+ return Collections.emptyList();
builder.addEachElementToAll(values);
checkFalse(builder.containsNull(), "Invalid null value for column %s", def.name);
@@ -236,7 +236,12 @@ final class SingleColumnPrimaryKeyRestrictions extends AbstractPrimaryKeyRestric
return compositeBuilder.buildWithEOC(eoc);
}
- compositeBuilder.addEachElementToAll(r.values(options));
+ List<ByteBuffer> values = r.values(options);
+
+ if (values.isEmpty())
+ return Collections.emptyList();
+
+ compositeBuilder.addEachElementToAll(values);
checkFalse(compositeBuilder.containsNull(), "Invalid null clustering key part %s", def.name);
keyPosition++;
http://git-wip-us.apache.org/repos/asf/cassandra/blob/98cf6343/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java b/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
index 291afd8..b178498 100644
--- a/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
@@ -441,11 +441,15 @@ public class MultiColumnRelationTest extends CQLTester
row(0, 0, 1, 1)
);
+ assertEmpty(execute("SELECT * FROM %s WHERE a = ? and (b) IN ()", 0));
+
assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) IN ((?, ?)) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1),
row(0, 0, 1, 1),
row(0, 0, 1, 0)
);
+ assertEmpty(execute("SELECT * FROM %s WHERE a = ? AND (b, c) IN () ORDER BY b DESC, c DESC, d DESC", 0));
+
// IN on both partition key and clustering key
execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 1, 0, 0, 0);
execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 1, 0, 1, 0);
http://git-wip-us.apache.org/repos/asf/cassandra/blob/98cf6343/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java b/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java
index 112da06..e6412a3 100644
--- a/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java
@@ -363,4 +363,20 @@ public class SingleColumnRelationTest extends CQLTester
"SELECT * FROM %s WHERE setid = 0 AND row < 1;");
assertRows(execute("SELECT * FROM %s WHERE setid = 0 AND row < 1 ALLOW FILTERING;"), row(0, 0, 0));
}
+
+ @Test
+ public void testEmptyIN() throws Throwable
+ {
+ for (String compactOption : new String[] { "", " WITH COMPACT STORAGE" })
+ {
+ createTable("CREATE TABLE %s (k1 int, k2 int, v int, PRIMARY KEY (k1, k2))" + compactOption);
+
+ for (int i = 0; i <= 2; i++)
+ for (int j = 0; j <= 2; j++)
+ execute("INSERT INTO %s (k1, k2, v) VALUES (?, ?, ?)", i, j, i + j);
+
+ assertEmpty(execute("SELECT v FROM %s WHERE k1 IN ()"));
+ assertEmpty(execute("SELECT v FROM %s WHERE k1 = 0 AND k2 IN ()"));
+ }
+ }
}