cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tylerho...@apache.org
Subject git commit: Fix CONTAINS filtering on sets
Date Tue, 07 Oct 2014 15:22:52 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 260160469 -> 8d20b48fc


Fix CONTAINS filtering on sets

We were comparing the index expression value with the cell values
instead of the cell names, which is where set values are stored.

Patch by Tyler Hobbs; reviewed by Benjamin Lerer for CASSANDRA-8033


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

Branch: refs/heads/cassandra-2.1
Commit: 8d20b48fc34b520f0c36250bb7557da8c1e59b7d
Parents: 2601604
Author: Tyler Hobbs <tyler@datastax.com>
Authored: Tue Oct 7 10:21:11 2014 -0500
Committer: Tyler Hobbs <tyler@datastax.com>
Committed: Tue Oct 7 10:21:11 2014 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/db/filter/ExtendedFilter.java     | 15 +++++++++---
 .../cassandra/cql3/ContainsRelationTest.java    | 24 ++++++++++++++++++++
 3 files changed, 37 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/8d20b48f/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index f9523ed..6949209 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.1
+ * Fix filtering for CONTAINS on sets (CASSANDRA-8033)
  * Properly track added size (CASSANDRA-7239)
  * Allow compilation in java 8 (CASSANDRA-7208)
  * Fix Assertion error on RangeTombstoneList diff (CASSANDRA-8013)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/8d20b48f/src/java/org/apache/cassandra/db/filter/ExtendedFilter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/filter/ExtendedFilter.java b/src/java/org/apache/cassandra/db/filter/ExtendedFilter.java
index bc59152..4f27a51 100644
--- a/src/java/org/apache/cassandra/db/filter/ExtendedFilter.java
+++ b/src/java/org/apache/cassandra/db/filter/ExtendedFilter.java
@@ -327,6 +327,7 @@ public abstract class ExtendedFilter
         private static boolean collectionSatisfies(ColumnDefinition def, ColumnFamily data,
Composite prefix, IndexExpression expr, ByteBuffer collectionElement)
         {
             assert def.type.isCollection();
+            CollectionType type = (CollectionType)def.type;
 
             if (expr.operator == IndexExpression.Operator.CONTAINS)
             {
@@ -334,14 +335,22 @@ public abstract class ExtendedFilter
                 Iterator<Cell> iter = data.iterator(new ColumnSlice[]{ data.getComparator().create(prefix,
def).slice() });
                 while (iter.hasNext())
                 {
-                    if (((CollectionType) def.type).valueComparator().compare(iter.next().value(),
expr.value) == 0)
-                        return true;
+                    Cell cell = iter.next();
+                    if (type.kind == CollectionType.Kind.SET)
+                    {
+                        if (type.nameComparator().compare(cell.name().collectionElement(),
expr.value) == 0)
+                            return true;
+                    }
+                    else
+                    {
+                        if (type.valueComparator().compare(cell.value(), expr.value) == 0)
+                            return true;
+                    }
                 }
 
                 return false;
             }
 
-            CollectionType type = (CollectionType)def.type;
             switch (type.kind)
             {
                 case LIST:

http://git-wip-us.apache.org/repos/asf/cassandra/blob/8d20b48f/test/unit/org/apache/cassandra/cql3/ContainsRelationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/ContainsRelationTest.java b/test/unit/org/apache/cassandra/cql3/ContainsRelationTest.java
index 84a8c8f..525059d 100644
--- a/test/unit/org/apache/cassandra/cql3/ContainsRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/ContainsRelationTest.java
@@ -133,4 +133,28 @@ public class ContainsRelationTest extends CQLTester
             row("test", 5, map("lmn", "foo"))
         );
     }
+
+    // See CASSANDRA-8033
+    @Test
+    public void testFilterForContains() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k1 int, k2 int, v set<int>, PRIMARY KEY ((k1,
k2)))");
+        createIndex("CREATE INDEX ON %s(k2)");
+
+        execute("INSERT INTO %s (k1, k2, v) VALUES (?, ?, ?)", 0, 0, set(1, 2, 3));
+        execute("INSERT INTO %s (k1, k2, v) VALUES (?, ?, ?)", 0, 1, set(2, 3, 4));
+        execute("INSERT INTO %s (k1, k2, v) VALUES (?, ?, ?)", 1, 0, set(3, 4, 5));
+        execute("INSERT INTO %s (k1, k2, v) VALUES (?, ?, ?)", 1, 1, set(4, 5, 6));
+
+        assertRows(execute("SELECT * FROM %s WHERE k2 = ?", 1),
+            row(0, 1, set(2, 3, 4)),
+            row(1, 1, set(4, 5, 6))
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k2 = ? AND v CONTAINS ? ALLOW FILTERING",
1, 6),
+            row(1, 1, set(4, 5, 6))
+        );
+
+        assertEmpty(execute("SELECT * FROM %s WHERE k2 = ? AND v CONTAINS ? ALLOW FILTERING",
1, 7));
+    }
 }


Mime
View raw message