cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tylerho...@apache.org
Subject [1/2] cassandra git commit: Fix CONTAINS (KEY) filtering on frozen collection clustering cols
Date Wed, 19 Nov 2014 17:40:29 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 907591851 -> 1bd5c64ba


Fix CONTAINS (KEY) filtering on frozen collection clustering cols

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


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

Branch: refs/heads/trunk
Commit: e3862bc3e08115806055fe7239f93433407a3dc6
Parents: 25a4c9e
Author: Tyler Hobbs <tyler@datastax.com>
Authored: Wed Nov 19 11:37:26 2014 -0600
Committer: Tyler Hobbs <tyler@datastax.com>
Committed: Wed Nov 19 11:37:26 2014 -0600

----------------------------------------------------------------------
 CHANGES.txt                                     |  3 ++
 .../cql3/statements/SelectStatement.java        |  8 +--
 .../org/apache/cassandra/cql3/CQLTester.java    |  7 +++
 .../cassandra/cql3/FrozenCollectionsTest.java   | 56 ++++++++++++++++++--
 4 files changed, 67 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/e3862bc3/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 8dbcbc8..c00e671 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,7 @@
 2.1.3
+ * Fix filtering for CONTAINS (KEY) relations on frozen collection
+   clustering columns when the query is restricted to a single
+   partition (CASSANDRA-8203)
  * Do more aggressive entire-sstable TTL expiry checks (CASSANDRA-8243)
  * Add more log info if readMeter is null (CASSANDRA-8238)
  * add check of the system wall clock time at startup (CASSANDRA-8305)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e3862bc3/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index 688d1d5..de3d67c 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -1981,12 +1981,12 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
                     else if (stmt.selectACollection())
                         throw new InvalidRequestException(String.format("Cannot restrict
column \"%s\" by IN relation as a collection is selected by the query", cdef.name));
                 }
-                /*
-                else if (restriction.isContains() && !hasQueriableIndex)
+                else if (restriction.isContains())
                 {
-                    throw new InvalidRequestException(String.format("Cannot restrict column
\"%s\" by a CONTAINS relation without a secondary index", cdef.name));
+                    if (!hasQueriableIndex)
+                        throw new InvalidRequestException(String.format("Cannot restrict
column \"%s\" by a CONTAINS relation without a secondary index", cdef.name));
+                    stmt.usesSecondaryIndexing = true;
                 }
-                */
 
                 previous = cdef;
             }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e3862bc3/test/unit/org/apache/cassandra/cql3/CQLTester.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/CQLTester.java b/test/unit/org/apache/cassandra/cql3/CQLTester.java
index a110af6..470b701 100644
--- a/test/unit/org/apache/cassandra/cql3/CQLTester.java
+++ b/test/unit/org/apache/cassandra/cql3/CQLTester.java
@@ -248,6 +248,13 @@ public abstract class CQLTester
         }
     }
 
+    protected void dropIndex(String query) throws Throwable
+    {
+        String fullQuery = String.format(query, KEYSPACE);
+        logger.info(fullQuery);
+        schemaChange(fullQuery);
+    }
+
     private static void schemaChange(String query)
     {
         try

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e3862bc3/test/unit/org/apache/cassandra/cql3/FrozenCollectionsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/FrozenCollectionsTest.java b/test/unit/org/apache/cassandra/cql3/FrozenCollectionsTest.java
index 203adae..bf7ccfd 100644
--- a/test/unit/org/apache/cassandra/cql3/FrozenCollectionsTest.java
+++ b/test/unit/org/apache/cassandra/cql3/FrozenCollectionsTest.java
@@ -615,10 +615,10 @@ public class FrozenCollectionsTest extends CQLTester
                              "SELECT * FROM %s WHERE c CONTAINS KEY ?", 1);
 
         // normal indexes on frozen collections don't support CONTAINS or CONTAINS KEY
-        assertInvalidMessage("No secondary indexes on the restricted columns support the
provided operator",
+        assertInvalidMessage("Cannot restrict column \"b\" by a CONTAINS relation without
a secondary index",
                              "SELECT * FROM %s WHERE b CONTAINS ?", 1);
 
-        assertInvalidMessage("No secondary indexes on the restricted columns support the
provided operator",
+        assertInvalidMessage("Cannot restrict column \"b\" by a CONTAINS relation without
a secondary index",
                              "SELECT * FROM %s WHERE b CONTAINS ? ALLOW FILTERING", 1);
 
         assertInvalidMessage("No secondary indexes on the restricted columns support the
provided operator",
@@ -627,7 +627,7 @@ public class FrozenCollectionsTest extends CQLTester
         assertInvalidMessage("No secondary indexes on the restricted columns support the
provided operator",
                              "SELECT * FROM %s WHERE d CONTAINS KEY ? ALLOW FILTERING", 1);
 
-        assertInvalidMessage("No secondary indexes on the restricted columns support the
provided operator",
+        assertInvalidMessage("Cannot restrict column \"b\" by a CONTAINS relation without
a secondary index",
                              "SELECT * FROM %s WHERE b CONTAINS ? AND d CONTAINS KEY ? ALLOW
FILTERING", 1, 1);
 
         // index lookup on b
@@ -743,6 +743,56 @@ public class FrozenCollectionsTest extends CQLTester
         );
     }
 
+    /** Test for CASSANDRA-8302 */
+    @Test
+    public void testClusteringColumnFiltering() throws Throwable
+    {
+        createTable("CREATE TABLE %s (a int, b frozen<map<int, int>>, c int,
d int, PRIMARY KEY (a, b, c))");
+        createIndex("CREATE INDEX c_index ON %s (c)");
+        createIndex("CREATE INDEX d_index ON %s (d)");
+
+        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, map(0, 0, 1, 1), 0,
0);
+        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, map(1, 1, 2, 2), 0,
0);
+        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 1, map(0, 0, 1, 1), 0,
0);
+        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 1, map(1, 1, 2, 2), 0,
0);
+
+        assertRows(execute("SELECT * FROM %s WHERE d=? AND b CONTAINS ? ALLOW FILTERING",
0, 0),
+                row(0, map(0, 0, 1, 1), 0, 0),
+                row(1, map(0, 0, 1, 1), 0, 0)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE d=? AND b CONTAINS KEY ? ALLOW FILTERING",
0, 0),
+                row(0, map(0, 0, 1, 1), 0, 0),
+                row(1, map(0, 0, 1, 1), 0, 0)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a=? AND d=? AND b CONTAINS ? ALLOW FILTERING",
0, 0, 0),
+                row(0, map(0, 0, 1, 1), 0, 0)
+        );
+        assertRows(execute("SELECT * FROM %s WHERE a=? AND d=? AND b CONTAINS KEY ? ALLOW
FILTERING", 0, 0, 0),
+                row(0, map(0, 0, 1, 1), 0, 0)
+        );
+
+        dropIndex("DROP INDEX %s.d_index");
+
+        assertRows(execute("SELECT * FROM %s WHERE c=? AND b CONTAINS ? ALLOW FILTERING",
0, 0),
+                row(0, map(0, 0, 1, 1), 0, 0),
+                row(1, map(0, 0, 1, 1), 0, 0)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE c=? AND b CONTAINS KEY ? ALLOW FILTERING",
0, 0),
+                row(0, map(0, 0, 1, 1), 0, 0),
+                row(1, map(0, 0, 1, 1), 0, 0)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a=? AND c=? AND b CONTAINS ? ALLOW FILTERING",
0, 0, 0),
+                row(0, map(0, 0, 1, 1), 0, 0)
+        );
+        assertRows(execute("SELECT * FROM %s WHERE a=? AND c=? AND b CONTAINS KEY ? ALLOW
FILTERING", 0, 0, 0),
+                row(0, map(0, 0, 1, 1), 0, 0)
+        );
+    }
+
     @Test
     public void testUserDefinedTypes() throws Throwable
     {


Mime
View raw message