You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by bl...@apache.org on 2016/04/15 22:27:45 UTC
[1/2] cassandra git commit: Allow filtering on clustering columns for
queries without secondary indexes
Repository: cassandra
Updated Branches:
refs/heads/trunk 831bebdba -> a600920cb
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a600920c/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
index 75334f0..6789baf 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
@@ -1447,65 +1447,66 @@ public class SelectTest extends CQLTester
execute("DELETE FROM %s WHERE a = 1 AND b = 1");
execute("DELETE FROM %s WHERE a = 2 AND b = 2");
- flush();
+ beforeAndAfterFlush(() -> {
- // Checks filtering
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c = 4 AND d = 8");
+ // Checks filtering
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c = 4 AND d = 8");
- assertRows(execute("SELECT * FROM %s WHERE c = 4 AND d = 8 ALLOW FILTERING"),
- row(1, 2, 1, 4, 8),
- row(1, 4, 1, 4, 8));
+ assertRows(execute("SELECT * FROM %s WHERE c = 4 AND d = 8 ALLOW FILTERING"),
+ row(1, 2, 1, 4, 8),
+ row(1, 4, 1, 4, 8));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE a = 1 AND b = 4 AND d = 8");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE a = 1 AND b = 4 AND d = 8");
- assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 4 AND d = 8 ALLOW FILTERING"),
- row(1, 4, 1, 4, 8));
+ assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 4 AND d = 8 ALLOW FILTERING"),
+ row(1, 4, 1, 4, 8));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE s = 1 AND d = 12");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE s = 1 AND d = 12");
- assertRows(execute("SELECT * FROM %s WHERE s = 1 AND d = 12 ALLOW FILTERING"),
- row(1, 3, 1, 6, 12));
+ assertRows(execute("SELECT * FROM %s WHERE s = 1 AND d = 12 ALLOW FILTERING"),
+ row(1, 3, 1, 6, 12));
- assertInvalidMessage("IN predicates on non-primary-key columns (c) is not yet supported",
- "SELECT * FROM %s WHERE a IN (1, 2) AND c IN (6, 7)");
+ assertInvalidMessage("IN predicates on non-primary-key columns (c) is not yet supported",
+ "SELECT * FROM %s WHERE a IN (1, 2) AND c IN (6, 7)");
- assertInvalidMessage("IN predicates on non-primary-key columns (c) is not yet supported",
- "SELECT * FROM %s WHERE a IN (1, 2) AND c IN (6, 7) ALLOW FILTERING");
+ assertInvalidMessage("IN predicates on non-primary-key columns (c) is not yet supported",
+ "SELECT * FROM %s WHERE a IN (1, 2) AND c IN (6, 7) ALLOW FILTERING");
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c > 4");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > 4");
- assertRows(execute("SELECT * FROM %s WHERE c > 4 ALLOW FILTERING"),
- row(1, 3, 1, 6, 12),
- row(2, 3, 2, 7, 12));
+ assertRows(execute("SELECT * FROM %s WHERE c > 4 ALLOW FILTERING"),
+ row(1, 3, 1, 6, 12),
+ row(2, 3, 2, 7, 12));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE s > 1");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE s > 1");
- assertRows(execute("SELECT * FROM %s WHERE s > 1 ALLOW FILTERING"),
- row(2, 3, 2, 7, 12),
- row(3, null, 3, null, null));
+ assertRows(execute("SELECT * FROM %s WHERE s > 1 ALLOW FILTERING"),
+ row(2, 3, 2, 7, 12),
+ row(3, null, 3, null, null));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE b < 3 AND c <= 4");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE b < 3 AND c <= 4");
- assertRows(execute("SELECT * FROM %s WHERE b < 3 AND c <= 4 ALLOW FILTERING"),
- row(1, 2, 1, 4, 8));
+ assertRows(execute("SELECT * FROM %s WHERE b < 3 AND c <= 4 ALLOW FILTERING"),
+ row(1, 2, 1, 4, 8));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c >= 3 AND c <= 6");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c >= 3 AND c <= 6");
- assertRows(execute("SELECT * FROM %s WHERE c >= 3 AND c <= 6 ALLOW FILTERING"),
- row(1, 2, 1, 4, 8),
- row(1, 3, 1, 6, 12),
- row(1, 4, 1, 4, 8));
+ assertRows(execute("SELECT * FROM %s WHERE c >= 3 AND c <= 6 ALLOW FILTERING"),
+ row(1, 2, 1, 4, 8),
+ row(1, 3, 1, 6, 12),
+ row(1, 4, 1, 4, 8));
- assertRows(execute("SELECT * FROM %s WHERE s >= 1 LIMIT 2 ALLOW FILTERING"),
- row(1, 2, 1, 4, 8),
- row(1, 3, 1, 6, 12));
+ assertRows(execute("SELECT * FROM %s WHERE s >= 1 LIMIT 2 ALLOW FILTERING"),
+ row(1, 2, 1, 4, 8),
+ row(1, 3, 1, 6, 12));
+ });
// Checks filtering with null
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
@@ -1552,41 +1553,43 @@ public class SelectTest extends CQLTester
execute("DELETE FROM %s WHERE a = 1 AND b = 1");
execute("DELETE FROM %s WHERE a = 2 AND b = 2");
- flush();
+ beforeAndAfterFlush(() -> {
- // Checks filtering
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = 4");
+ // Checks filtering
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = 4");
- assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = 4 ALLOW FILTERING"),
- row(1, 4, 4));
+ assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = 4 ALLOW FILTERING"),
+ row(1, 4, 4));
- assertInvalidMessage("IN predicates on non-primary-key columns (c) is not yet supported",
- "SELECT * FROM %s WHERE a IN (1, 2) AND c IN (6, 7)");
+ assertInvalidMessage("IN predicates on non-primary-key columns (c) is not yet supported",
+ "SELECT * FROM %s WHERE a IN (1, 2) AND c IN (6, 7)");
- assertInvalidMessage("IN predicates on non-primary-key columns (c) is not yet supported",
- "SELECT * FROM %s WHERE a IN (1, 2) AND c IN (6, 7) ALLOW FILTERING");
+ assertInvalidMessage("IN predicates on non-primary-key columns (c) is not yet supported",
+ "SELECT * FROM %s WHERE a IN (1, 2) AND c IN (6, 7) ALLOW FILTERING");
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c > 4");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > 4");
- assertRows(execute("SELECT * FROM %s WHERE c > 4 ALLOW FILTERING"),
- row(1, 3, 6),
- row(2, 3, 7));
+ assertRows(execute("SELECT * FROM %s WHERE c > 4 ALLOW FILTERING"),
+ row(1, 3, 6),
+ row(2, 3, 7));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE b < 3 AND c <= 4");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE b < 3 AND c <= 4");
- assertRows(execute("SELECT * FROM %s WHERE b < 3 AND c <= 4 ALLOW FILTERING"),
- row(1, 2, 4));
+ assertRows(execute("SELECT * FROM %s WHERE b < 3 AND c <= 4 ALLOW FILTERING"),
+ row(1, 2, 4));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c >= 3 AND c <= 6");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c >= 3 AND c <= 6");
- assertRows(execute("SELECT * FROM %s WHERE c >= 3 AND c <= 6 ALLOW FILTERING"),
- row(1, 2, 4),
- row(1, 3, 6),
- row(1, 4, 4));
+ assertRows(execute("SELECT * FROM %s WHERE c >= 3 AND c <= 6 ALLOW FILTERING"),
+ row(1, 2, 4),
+ row(1, 3, 6),
+ row(1, 4, 4));
+
+ });
// Checks filtering with null
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
@@ -1598,7 +1601,7 @@ public class SelectTest extends CQLTester
assertInvalidMessage("Unsupported null value for column c",
"SELECT * FROM %s WHERE c > null ALLOW FILTERING");
- // // Checks filtering with unset
+ // Checks filtering with unset
assertInvalidMessage("Unsupported unset value for column c",
"SELECT * FROM %s WHERE c = ? ALLOW FILTERING",
unset());
@@ -1622,42 +1625,43 @@ public class SelectTest extends CQLTester
execute("DELETE FROM %s WHERE a = 0");
execute("DELETE FROM %s WHERE a = 5");
- flush();
+ beforeAndAfterFlush(() -> {
- // Checks filtering
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = 4");
+ // Checks filtering
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = 4");
- assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 2 AND c = 4 ALLOW FILTERING"),
- row(1, 2, 4));
+ assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 2 AND c = 4 ALLOW FILTERING"),
+ row(1, 2, 4));
- assertInvalidMessage("IN predicates on non-primary-key columns (c) is not yet supported",
- "SELECT * FROM %s WHERE a IN (1, 2) AND c IN (6, 7)");
+ assertInvalidMessage("IN predicates on non-primary-key columns (c) is not yet supported",
+ "SELECT * FROM %s WHERE a IN (1, 2) AND c IN (6, 7)");
- assertInvalidMessage("IN predicates on non-primary-key columns (c) is not yet supported",
- "SELECT * FROM %s WHERE a IN (1, 2) AND c IN (6, 7) ALLOW FILTERING");
+ assertInvalidMessage("IN predicates on non-primary-key columns (c) is not yet supported",
+ "SELECT * FROM %s WHERE a IN (1, 2) AND c IN (6, 7) ALLOW FILTERING");
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c > 4");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > 4");
- assertRows(execute("SELECT * FROM %s WHERE c > 4 ALLOW FILTERING"),
- row(2, 1, 6),
- row(4, 1, 7));
+ assertRows(execute("SELECT * FROM %s WHERE c > 4 ALLOW FILTERING"),
+ row(2, 1, 6),
+ row(4, 1, 7));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE b < 3 AND c <= 4");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE b < 3 AND c <= 4");
- assertRows(execute("SELECT * FROM %s WHERE b < 3 AND c <= 4 ALLOW FILTERING"),
- row(1, 2, 4),
- row(3, 2, 4));
+ assertRows(execute("SELECT * FROM %s WHERE b < 3 AND c <= 4 ALLOW FILTERING"),
+ row(1, 2, 4),
+ row(3, 2, 4));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c >= 3 AND c <= 6");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c >= 3 AND c <= 6");
- assertRows(execute("SELECT * FROM %s WHERE c >= 3 AND c <= 6 ALLOW FILTERING"),
- row(1, 2, 4),
- row(2, 1, 6),
- row(3, 2, 4));
+ assertRows(execute("SELECT * FROM %s WHERE c >= 3 AND c <= 6 ALLOW FILTERING"),
+ row(1, 2, 4),
+ row(2, 1, 6),
+ row(3, 2, 4));
+ });
// Checks filtering with null
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
@@ -1688,50 +1692,51 @@ public class SelectTest extends CQLTester
execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 4, [1, 2], {2, 4}, {1: 2})");
execute("INSERT INTO %s (a, b, c, d, e) VALUES (2, 3, [3, 6], {6, 12}, {3: 6})");
- flush();
+ beforeAndAfterFlush(() -> {
- // Checks filtering for lists
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c CONTAINS 2");
+ // Checks filtering for lists
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c CONTAINS 2");
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)),
- row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)),
+ row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS 3 ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS 3 ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
- // Checks filtering for sets
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE d CONTAINS 4");
+ // Checks filtering for sets
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE d CONTAINS 4");
- assertRows(execute("SELECT * FROM %s WHERE d CONTAINS 4 ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)),
- row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE d CONTAINS 4 ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)),
+ row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
- assertRows(execute("SELECT * FROM %s WHERE d CONTAINS 4 AND d CONTAINS 6 ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE d CONTAINS 4 AND d CONTAINS 6 ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
- // Checks filtering for maps
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE e CONTAINS 2");
+ // Checks filtering for maps
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE e CONTAINS 2");
- assertRows(execute("SELECT * FROM %s WHERE e CONTAINS 2 ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)),
- row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE e CONTAINS 2 ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)),
+ row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
- assertRows(execute("SELECT * FROM %s WHERE e CONTAINS KEY 1 ALLOW FILTERING"),
- row(1, 2, list(1, 6), set(2, 12), map(1, 6)),
- row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE e CONTAINS KEY 1 ALLOW FILTERING"),
+ row(1, 2, list(1, 6), set(2, 12), map(1, 6)),
+ row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
- assertRows(execute("SELECT * FROM %s WHERE e[1] = 6 ALLOW FILTERING"),
- row(1, 2, list(1, 6), set(2, 12), map(1, 6)));
+ assertRows(execute("SELECT * FROM %s WHERE e[1] = 6 ALLOW FILTERING"),
+ row(1, 2, list(1, 6), set(2, 12), map(1, 6)));
- assertRows(execute("SELECT * FROM %s WHERE e CONTAINS KEY 1 AND e CONTAINS 2 ALLOW FILTERING"),
- row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE e CONTAINS KEY 1 AND e CONTAINS 2 ALLOW FILTERING"),
+ row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND d CONTAINS 4 AND e CONTAINS KEY 3 ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND d CONTAINS 4 AND e CONTAINS KEY 3 ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ });
// Checks filtering with null
assertInvalidMessage("Unsupported null value for column c",
@@ -1778,100 +1783,101 @@ public class SelectTest extends CQLTester
execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 4, [1, 2], {2, 4}, {1: 2})");
execute("INSERT INTO %s (a, b, c, d, e) VALUES (2, 3, [3, 6], {6, 12}, {3: 6})");
- flush();
+ beforeAndAfterFlush(() -> {
- // Checks filtering for lists
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c = [3, 2]");
+ // Checks filtering for lists
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c = [3, 2]");
- assertRows(execute("SELECT * FROM %s WHERE c = [3, 2] ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c = [3, 2] ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c > [1, 5] AND c < [3, 6]");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > [1, 5] AND c < [3, 6]");
- assertRows(execute("SELECT * FROM %s WHERE c > [1, 5] AND c < [3, 6] ALLOW FILTERING"),
- row(1, 2, list(1, 6), set(2, 12), map(1, 6)),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c > [1, 5] AND c < [3, 6] ALLOW FILTERING"),
+ row(1, 2, list(1, 6), set(2, 12), map(1, 6)),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
- assertRows(execute("SELECT * FROM %s WHERE c >= [1, 6] AND c < [3, 3] ALLOW FILTERING"),
- row(1, 2, list(1, 6), set(2, 12), map(1, 6)),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c >= [1, 6] AND c < [3, 3] ALLOW FILTERING"),
+ row(1, 2, list(1, 6), set(2, 12), map(1, 6)),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c CONTAINS 2");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c CONTAINS 2");
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)),
- row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)),
+ row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS 3 ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS 3 ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
- // Checks filtering for sets
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE d = {6, 4}");
+ // Checks filtering for sets
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE d = {6, 4}");
- assertRows(execute("SELECT * FROM %s WHERE d = {6, 4} ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE d = {6, 4} ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE d > {4, 5} AND d < {6}");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE d > {4, 5} AND d < {6}");
- assertRows(execute("SELECT * FROM %s WHERE d > {4, 5} AND d < {6} ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE d > {4, 5} AND d < {6} ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
- assertRows(execute("SELECT * FROM %s WHERE d >= {2, 12} AND d <= {4, 6} ALLOW FILTERING"),
- row(1, 2, list(1, 6), set(2, 12), map(1, 6)),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE d >= {2, 12} AND d <= {4, 6} ALLOW FILTERING"),
+ row(1, 2, list(1, 6), set(2, 12), map(1, 6)),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE d CONTAINS 4");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE d CONTAINS 4");
- assertRows(execute("SELECT * FROM %s WHERE d CONTAINS 4 ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)),
- row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE d CONTAINS 4 ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)),
+ row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
- assertRows(execute("SELECT * FROM %s WHERE d CONTAINS 4 AND d CONTAINS 6 ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE d CONTAINS 4 AND d CONTAINS 6 ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
- // Checks filtering for maps
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE e = {1 : 2}");
+ // Checks filtering for maps
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE e = {1 : 2}");
- assertRows(execute("SELECT * FROM %s WHERE e = {1 : 2} ALLOW FILTERING"),
- row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE e = {1 : 2} ALLOW FILTERING"),
+ row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE e > {1 : 4} AND e < {3 : 6}");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE e > {1 : 4} AND e < {3 : 6}");
- assertRows(execute("SELECT * FROM %s WHERE e > {1 : 4} AND e < {3 : 6} ALLOW FILTERING"),
- row(1, 2, list(1, 6), set(2, 12), map(1, 6)),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE e > {1 : 4} AND e < {3 : 6} ALLOW FILTERING"),
+ row(1, 2, list(1, 6), set(2, 12), map(1, 6)),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
- assertRows(execute("SELECT * FROM %s WHERE e >= {1 : 6} AND e <= {3 : 2} ALLOW FILTERING"),
- row(1, 2, list(1, 6), set(2, 12), map(1, 6)),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE e >= {1 : 6} AND e <= {3 : 2} ALLOW FILTERING"),
+ row(1, 2, list(1, 6), set(2, 12), map(1, 6)),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE e CONTAINS 2");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE e CONTAINS 2");
- assertRows(execute("SELECT * FROM %s WHERE e CONTAINS 2 ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)),
- row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE e CONTAINS 2 ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)),
+ row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
- assertRows(execute("SELECT * FROM %s WHERE e CONTAINS KEY 1 ALLOW FILTERING"),
- row(1, 2, list(1, 6), set(2, 12), map(1, 6)),
- row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE e CONTAINS KEY 1 ALLOW FILTERING"),
+ row(1, 2, list(1, 6), set(2, 12), map(1, 6)),
+ row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
- assertInvalidMessage("Map-entry equality predicates on frozen map column e are not supported",
- "SELECT * FROM %s WHERE e[1] = 6 ALLOW FILTERING");
+ assertInvalidMessage("Map-entry equality predicates on frozen map column e are not supported",
+ "SELECT * FROM %s WHERE e[1] = 6 ALLOW FILTERING");
- assertRows(execute("SELECT * FROM %s WHERE e CONTAINS KEY 1 AND e CONTAINS 2 ALLOW FILTERING"),
- row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE e CONTAINS KEY 1 AND e CONTAINS 2 ALLOW FILTERING"),
+ row(1, 4, list(1, 2), set(2, 4), map(1, 2)));
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND d CONTAINS 4 AND e CONTAINS KEY 3 ALLOW FILTERING"),
- row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND d CONTAINS 4 AND e CONTAINS KEY 3 ALLOW FILTERING"),
+ row(1, 3, list(3, 2), set(6, 4), map(3, 2)));
+ });
// Checks filtering with null
assertInvalidMessage("Unsupported null value for column c",
@@ -1936,47 +1942,48 @@ public class SelectTest extends CQLTester
execute("INSERT INTO %s (a, b, c) VALUES (1, 4, [4, 1])");
execute("INSERT INTO %s (a, b, c) VALUES (2, 3, [7, 1])");
- flush();
+ beforeAndAfterFlush(() -> {
- // Checks filtering
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = [4, 1]");
+ // Checks filtering
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = [4, 1]");
- assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = [4, 1] ALLOW FILTERING"),
- row(1, 4, list(4, 1)));
+ assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = [4, 1] ALLOW FILTERING"),
+ row(1, 4, list(4, 1)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c > [4, 2]");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > [4, 2]");
- assertRows(execute("SELECT * FROM %s WHERE c > [4, 2] ALLOW FILTERING"),
- row(1, 3, list(6, 2)),
- row(2, 3, list(7, 1)));
+ assertRows(execute("SELECT * FROM %s WHERE c > [4, 2] ALLOW FILTERING"),
+ row(1, 3, list(6, 2)),
+ row(2, 3, list(7, 1)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE b <= 3 AND c < [6, 2]");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE b <= 3 AND c < [6, 2]");
- assertRows(execute("SELECT * FROM %s WHERE b <= 3 AND c < [6, 2] ALLOW FILTERING"),
- row(1, 2, list(4, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE b <= 3 AND c < [6, 2] ALLOW FILTERING"),
+ row(1, 2, list(4, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c >= [4, 2] AND c <= [6, 4]");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c >= [4, 2] AND c <= [6, 4]");
- assertRows(execute("SELECT * FROM %s WHERE c >= [4, 2] AND c <= [6, 4] ALLOW FILTERING"),
- row(1, 2, list(4, 2)),
- row(1, 3, list(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c >= [4, 2] AND c <= [6, 4] ALLOW FILTERING"),
+ row(1, 2, list(4, 2)),
+ row(1, 3, list(6, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c CONTAINS 2");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c CONTAINS 2");
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
- row(1, 2, list(4, 2)),
- row(1, 3, list(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
+ row(1, 2, list(4, 2)),
+ row(1, 3, list(6, 2)));
- assertInvalidMessage("Cannot use CONTAINS KEY on non-map column c",
- "SELECT * FROM %s WHERE c CONTAINS KEY 2 ALLOW FILTERING");
+ assertInvalidMessage("Cannot use CONTAINS KEY on non-map column c",
+ "SELECT * FROM %s WHERE c CONTAINS KEY 2 ALLOW FILTERING");
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS 6 ALLOW FILTERING"),
- row(1, 3, list(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS 6 ALLOW FILTERING"),
+ row(1, 3, list(6, 2)));
+ });
// Checks filtering with null
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
@@ -2013,47 +2020,48 @@ public class SelectTest extends CQLTester
execute("INSERT INTO %s (a, b, c) VALUES (3, 2, [4, 1])");
execute("INSERT INTO %s (a, b, c) VALUES (4, 1, [7, 1])");
- flush();
+ beforeAndAfterFlush(() -> {
- // Checks filtering
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE a = 1 AND b = 2 AND c = [4, 2]");
+ // Checks filtering
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE a = 1 AND b = 2 AND c = [4, 2]");
- assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 2 AND c = [4, 2] ALLOW FILTERING"),
- row(1, 2, list(4, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 2 AND c = [4, 2] ALLOW FILTERING"),
+ row(1, 2, list(4, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c > [4, 2]");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > [4, 2]");
- assertRows(execute("SELECT * FROM %s WHERE c > [4, 2] ALLOW FILTERING"),
- row(2, 1, list(6, 2)),
- row(4, 1, list(7, 1)));
+ assertRows(execute("SELECT * FROM %s WHERE c > [4, 2] ALLOW FILTERING"),
+ row(2, 1, list(6, 2)),
+ row(4, 1, list(7, 1)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE b < 3 AND c <= [4, 2]");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE b < 3 AND c <= [4, 2]");
- assertRows(execute("SELECT * FROM %s WHERE b < 3 AND c <= [4, 2] ALLOW FILTERING"),
- row(1, 2, list(4, 2)),
- row(3, 2, list(4, 1)));
+ assertRows(execute("SELECT * FROM %s WHERE b < 3 AND c <= [4, 2] ALLOW FILTERING"),
+ row(1, 2, list(4, 2)),
+ row(3, 2, list(4, 1)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c >= [4, 3] AND c <= [7]");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c >= [4, 3] AND c <= [7]");
- assertRows(execute("SELECT * FROM %s WHERE c >= [4, 3] AND c <= [7] ALLOW FILTERING"),
- row(2, 1, list(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c >= [4, 3] AND c <= [7] ALLOW FILTERING"),
+ row(2, 1, list(6, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c CONTAINS 2");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c CONTAINS 2");
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
- row(1, 2, list(4, 2)),
- row(2, 1, list(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
+ row(1, 2, list(4, 2)),
+ row(2, 1, list(6, 2)));
- assertInvalidMessage("Cannot use CONTAINS KEY on non-map column c",
- "SELECT * FROM %s WHERE c CONTAINS KEY 2 ALLOW FILTERING");
+ assertInvalidMessage("Cannot use CONTAINS KEY on non-map column c",
+ "SELECT * FROM %s WHERE c CONTAINS KEY 2 ALLOW FILTERING");
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS 6 ALLOW FILTERING"),
- row(2, 1, list(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS 6 ALLOW FILTERING"),
+ row(2, 1, list(6, 2)));
+ });
// Checks filtering with null
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
@@ -2094,48 +2102,48 @@ public class SelectTest extends CQLTester
execute("INSERT INTO %s (a, b, c) VALUES (1, 4, {4, 1})");
execute("INSERT INTO %s (a, b, c) VALUES (2, 3, {7, 1})");
- flush();
-
- // Checks filtering
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = {4, 1}");
+ beforeAndAfterFlush(() -> {
- assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = {4, 1} ALLOW FILTERING"),
- row(1, 4, set(4, 1)));
+ // Checks filtering
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = {4, 1}");
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c > {4, 2}");
+ assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = {4, 1} ALLOW FILTERING"),
+ row(1, 4, set(4, 1)));
- assertRows(execute("SELECT * FROM %s WHERE c > {4, 2} ALLOW FILTERING"),
- row(1, 3, set(6, 2)));
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > {4, 2}");
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE b <= 3 AND c < {6, 2}");
+ assertRows(execute("SELECT * FROM %s WHERE c > {4, 2} ALLOW FILTERING"),
+ row(1, 3, set(6, 2)));
- assertRows(execute("SELECT * FROM %s WHERE b <= 3 AND c < {6, 2} ALLOW FILTERING"),
- row(1, 2, set(2, 4)),
- row(2, 3, set(1, 7)));
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE b <= 3 AND c < {6, 2}");
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c >= {4, 2} AND c <= {6, 4}");
+ assertRows(execute("SELECT * FROM %s WHERE b <= 3 AND c < {6, 2} ALLOW FILTERING"),
+ row(1, 2, set(2, 4)),
+ row(2, 3, set(1, 7)));
- assertRows(execute("SELECT * FROM %s WHERE c >= {4, 2} AND c <= {6, 4} ALLOW FILTERING"),
- row(1, 2, set(4, 2)),
- row(1, 3, set(6, 2)));
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c >= {4, 2} AND c <= {6, 4}");
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c CONTAINS 2");
+ assertRows(execute("SELECT * FROM %s WHERE c >= {4, 2} AND c <= {6, 4} ALLOW FILTERING"),
+ row(1, 2, set(4, 2)),
+ row(1, 3, set(6, 2)));
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
- row(1, 2, set(4, 2)),
- row(1, 3, set(6, 2)));
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c CONTAINS 2");
- assertInvalidMessage("Cannot use CONTAINS KEY on non-map column c",
- "SELECT * FROM %s WHERE c CONTAINS KEY 2 ALLOW FILTERING");
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
+ row(1, 2, set(4, 2)),
+ row(1, 3, set(6, 2)));
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS 6 ALLOW FILTERING"),
- row(1, 3, set(6, 2)));
+ assertInvalidMessage("Cannot use CONTAINS KEY on non-map column c",
+ "SELECT * FROM %s WHERE c CONTAINS KEY 2 ALLOW FILTERING");
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS 6 ALLOW FILTERING"),
+ row(1, 3, set(6, 2)));
+ });
// Checks filtering with null
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
"SELECT * FROM %s WHERE c = null");
@@ -2171,47 +2179,48 @@ public class SelectTest extends CQLTester
execute("INSERT INTO %s (a, b, c) VALUES (3, 2, {4, 1})");
execute("INSERT INTO %s (a, b, c) VALUES (4, 1, {7, 1})");
- flush();
+ beforeAndAfterFlush(() -> {
- // Checks filtering
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE a = 1 AND b = 2 AND c = {4, 2}");
+ // Checks filtering
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE a = 1 AND b = 2 AND c = {4, 2}");
- assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 2 AND c = {4, 2} ALLOW FILTERING"),
- row(1, 2, set(4, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 2 AND c = {4, 2} ALLOW FILTERING"),
+ row(1, 2, set(4, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c > {4, 2}");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > {4, 2}");
- assertRows(execute("SELECT * FROM %s WHERE c > {4, 2} ALLOW FILTERING"),
- row(2, 1, set(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c > {4, 2} ALLOW FILTERING"),
+ row(2, 1, set(6, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE b < 3 AND c <= {4, 2}");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE b < 3 AND c <= {4, 2}");
- assertRows(execute("SELECT * FROM %s WHERE b < 3 AND c <= {4, 2} ALLOW FILTERING"),
- row(1, 2, set(4, 2)),
- row(4, 1, set(1, 7)),
- row(3, 2, set(4, 1)));
+ assertRows(execute("SELECT * FROM %s WHERE b < 3 AND c <= {4, 2} ALLOW FILTERING"),
+ row(1, 2, set(4, 2)),
+ row(4, 1, set(1, 7)),
+ row(3, 2, set(4, 1)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c >= {4, 3} AND c <= {7}");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c >= {4, 3} AND c <= {7}");
- assertRows(execute("SELECT * FROM %s WHERE c >= {5, 2} AND c <= {7} ALLOW FILTERING"),
- row(2, 1, set(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c >= {5, 2} AND c <= {7} ALLOW FILTERING"),
+ row(2, 1, set(6, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c CONTAINS 2");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c CONTAINS 2");
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
- row(1, 2, set(4, 2)),
- row(2, 1, set(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
+ row(1, 2, set(4, 2)),
+ row(2, 1, set(6, 2)));
- assertInvalidMessage("Cannot use CONTAINS KEY on non-map column c",
- "SELECT * FROM %s WHERE c CONTAINS KEY 2 ALLOW FILTERING");
+ assertInvalidMessage("Cannot use CONTAINS KEY on non-map column c",
+ "SELECT * FROM %s WHERE c CONTAINS KEY 2 ALLOW FILTERING");
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS 6 ALLOW FILTERING"),
- row(2, 1, set(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS 6 ALLOW FILTERING"),
+ row(2, 1, set(6, 2)));
+ });
// Checks filtering with null
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
@@ -2268,47 +2277,48 @@ public class SelectTest extends CQLTester
execute("INSERT INTO %s (a, b, c) VALUES (1, 4, {4 : 1})");
execute("INSERT INTO %s (a, b, c) VALUES (2, 3, {7 : 1})");
- flush();
+ beforeAndAfterFlush(() -> {
- // Checks filtering
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = {4 : 1}");
+ // Checks filtering
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = {4 : 1}");
- assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = {4 : 1} ALLOW FILTERING"),
- row(1, 4, map(4, 1)));
+ assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 4 AND c = {4 : 1} ALLOW FILTERING"),
+ row(1, 4, map(4, 1)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c > {4 : 2}");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > {4 : 2}");
- assertRows(execute("SELECT * FROM %s WHERE c > {4 : 2} ALLOW FILTERING"),
- row(1, 3, map(6, 2)),
- row(2, 3, map(7, 1)));
+ assertRows(execute("SELECT * FROM %s WHERE c > {4 : 2} ALLOW FILTERING"),
+ row(1, 3, map(6, 2)),
+ row(2, 3, map(7, 1)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE b <= 3 AND c < {6 : 2}");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE b <= 3 AND c < {6 : 2}");
- assertRows(execute("SELECT * FROM %s WHERE b <= 3 AND c < {6 : 2} ALLOW FILTERING"),
- row(1, 2, map(4, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE b <= 3 AND c < {6 : 2} ALLOW FILTERING"),
+ row(1, 2, map(4, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c >= {4 : 2} AND c <= {6 : 4}");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c >= {4 : 2} AND c <= {6 : 4}");
- assertRows(execute("SELECT * FROM %s WHERE c >= {4 : 2} AND c <= {6 : 4} ALLOW FILTERING"),
- row(1, 2, map(4, 2)),
- row(1, 3, map(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c >= {4 : 2} AND c <= {6 : 4} ALLOW FILTERING"),
+ row(1, 2, map(4, 2)),
+ row(1, 3, map(6, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c CONTAINS 2");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c CONTAINS 2");
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
- row(1, 2, map(4, 2)),
- row(1, 3, map(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
+ row(1, 2, map(4, 2)),
+ row(1, 3, map(6, 2)));
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS KEY 6 ALLOW FILTERING"),
- row(1, 3, map(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS KEY 6 ALLOW FILTERING"),
+ row(1, 3, map(6, 2)));
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS KEY 6 ALLOW FILTERING"),
- row(1, 3, map(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS KEY 6 ALLOW FILTERING"),
+ row(1, 3, map(6, 2)));
+ });
// Checks filtering with null
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
@@ -2350,48 +2360,49 @@ public class SelectTest extends CQLTester
execute("INSERT INTO %s (a, b, c) VALUES (3, 2, {4 : 1})");
execute("INSERT INTO %s (a, b, c) VALUES (4, 1, {7 : 1})");
- flush();
+ beforeAndAfterFlush(() -> {
- // Checks filtering
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE a = 1 AND b = 2 AND c = {4 : 2}");
+ // Checks filtering
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE a = 1 AND b = 2 AND c = {4 : 2}");
- assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 2 AND c = {4 : 2} ALLOW FILTERING"),
- row(1, 2, map(4, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE a = 1 AND b = 2 AND c = {4 : 2} ALLOW FILTERING"),
+ row(1, 2, map(4, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c > {4 : 2}");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > {4 : 2}");
- assertRows(execute("SELECT * FROM %s WHERE c > {4 : 2} ALLOW FILTERING"),
- row(2, 1, map(6, 2)),
- row(4, 1, map(7, 1)));
+ assertRows(execute("SELECT * FROM %s WHERE c > {4 : 2} ALLOW FILTERING"),
+ row(2, 1, map(6, 2)),
+ row(4, 1, map(7, 1)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE b < 3 AND c <= {4 : 2}");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE b < 3 AND c <= {4 : 2}");
- assertRows(execute("SELECT * FROM %s WHERE b < 3 AND c <= {4 : 2} ALLOW FILTERING"),
- row(1, 2, map(4, 2)),
- row(3, 2, map(4, 1)));
+ assertRows(execute("SELECT * FROM %s WHERE b < 3 AND c <= {4 : 2} ALLOW FILTERING"),
+ row(1, 2, map(4, 2)),
+ row(3, 2, map(4, 1)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c >= {4 : 3} AND c <= {7 : 1}");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c >= {4 : 3} AND c <= {7 : 1}");
- assertRows(execute("SELECT * FROM %s WHERE c >= {5 : 2} AND c <= {7 : 0} ALLOW FILTERING"),
- row(2, 1, map(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c >= {5 : 2} AND c <= {7 : 0} ALLOW FILTERING"),
+ row(2, 1, map(6, 2)));
- assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
- "SELECT * FROM %s WHERE c CONTAINS 2");
+ assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c CONTAINS 2");
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
- row(1, 2, map(4, 2)),
- row(2, 1, map(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 ALLOW FILTERING"),
+ row(1, 2, map(4, 2)),
+ row(2, 1, map(6, 2)));
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS KEY 4 ALLOW FILTERING"),
- row(1, 2, map(4, 2)),
- row(3, 2, map(4, 1)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS KEY 4 ALLOW FILTERING"),
+ row(1, 2, map(4, 2)),
+ row(3, 2, map(4, 1)));
- assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS KEY 6 ALLOW FILTERING"),
- row(2, 1, map(6, 2)));
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS KEY 6 ALLOW FILTERING"),
+ row(2, 1, map(6, 2)));
+ });
// Checks filtering with null
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
@@ -2426,4 +2437,322 @@ public class SelectTest extends CQLTester
unset());
}
+ @Test
+ public void filteringOnClusteringColumns() throws Throwable
+ {
+ createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))");
+
+ execute("INSERT INTO %s (a,b,c,d) VALUES (11, 12, 13, 14)");
+ execute("INSERT INTO %s (a,b,c,d) VALUES (11, 15, 16, 17)");
+ execute("INSERT INTO %s (a,b,c,d) VALUES (21, 22, 23, 24)");
+ execute("INSERT INTO %s (a,b,c,d) VALUES (31, 32, 33, 34)");
+
+ beforeAndAfterFlush(() -> {
+
+ assertRows(execute("SELECT * FROM %s WHERE a = 11 AND b > 12 AND c > 13 AND d = 17 ALLOW FILTERING"),
+ row(11, 15, 16, 17));
+ assertInvalidMessage("Clustering column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)",
+ "SELECT * FROM %s WHERE a = 11 AND b > 12 AND c > 13 and d = 17");
+
+ assertRows(execute("SELECT * FROM %s WHERE b > 20 AND c > 30 ALLOW FILTERING"),
+ row(31, 32, 33, 34));
+ assertInvalidMessage("Clustering column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)",
+ "SELECT * FROM %s WHERE b > 20 AND c > 30");
+
+ assertRows(execute("SELECT * FROM %s WHERE b > 20 AND c < 30 ALLOW FILTERING"),
+ row(21, 22, 23, 24));
+ assertInvalidMessage("Clustering column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)",
+ "SELECT * FROM %s WHERE b > 20 AND c < 30");
+
+ assertRows(execute("SELECT * FROM %s WHERE b > 20 AND c = 33 ALLOW FILTERING"),
+ row(31, 32, 33, 34));
+ assertInvalidMessage("Clustering column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)",
+ "SELECT * FROM %s WHERE b > 20 AND c = 33");
+
+ assertRows(execute("SELECT * FROM %s WHERE c = 33 ALLOW FILTERING"),
+ row(31, 32, 33, 34));
+ assertInvalidMessage("PRIMARY KEY column \"c\" cannot be restricted as preceding column \"b\" is not restricted",
+ "SELECT * FROM %s WHERE c = 33");
+ });
+
+ // --------------------------------------------------
+ // Clustering column within and across partition keys
+ // --------------------------------------------------
+ createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))");
+
+ execute("INSERT INTO %s (a,b,c,d) VALUES (11, 12, 13, 14)");
+ execute("INSERT INTO %s (a,b,c,d) VALUES (11, 15, 16, 17)");
+ execute("INSERT INTO %s (a,b,c,d) VALUES (11, 18, 19, 20)");
+
+ execute("INSERT INTO %s (a,b,c,d) VALUES (21, 22, 23, 24)");
+ execute("INSERT INTO %s (a,b,c,d) VALUES (21, 25, 26, 27)");
+ execute("INSERT INTO %s (a,b,c,d) VALUES (21, 28, 29, 30)");
+
+ execute("INSERT INTO %s (a,b,c,d) VALUES (31, 32, 33, 34)");
+ execute("INSERT INTO %s (a,b,c,d) VALUES (31, 35, 36, 37)");
+ execute("INSERT INTO %s (a,b,c,d) VALUES (31, 38, 39, 40)");
+
+ beforeAndAfterFlush(() -> {
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE a = 21 AND c > 23"),
+ row(21, 25, 26, 27),
+ row(21, 28, 29, 30));
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE a = 21 AND c > 23 ORDER BY b DESC"),
+ row(21, 28, 29, 30),
+ row(21, 25, 26, 27));
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c > 16 and c < 36"),
+ row(11, 18, 19, 20),
+ row(21, 22, 23, 24),
+ row(21, 25, 26, 27),
+ row(21, 28, 29, 30),
+ row(31, 32, 33, 34));
+ });
+ }
+
+ @Test
+ public void filteringWithMultiColumnSlices() throws Throwable
+ {
+ //----------------------------------------
+ // Multi-column slices for clustering keys
+ //----------------------------------------
+ createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, PRIMARY KEY (a, b, c, d))");
+
+ execute("INSERT INTO %s (a,b,c,d,e) VALUES (11, 12, 13, 14, 15)");
+ execute("INSERT INTO %s (a,b,c,d,e) VALUES (21, 22, 23, 24, 25)");
+ execute("INSERT INTO %s (a,b,c,d,e) VALUES (31, 32, 33, 34, 35)");
+
+ beforeAndAfterFlush(() -> {
+
+ assertRows(execute("SELECT * FROM %s WHERE b = 22 AND d = 24 ALLOW FILTERING"),
+ row(21, 22, 23, 24, 25));
+ assertInvalidMessage("PRIMARY KEY column \"d\" cannot be restricted as preceding column \"c\" is not restricted",
+ "SELECT * FROM %s WHERE b = 22 AND d = 24");
+
+ assertRows(execute("SELECT * FROM %s WHERE (b, c) > (20, 30) AND d = 34 ALLOW FILTERING"),
+ row(31, 32, 33, 34, 35));
+ assertInvalidMessage("Clustering column \"d\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)",
+ "SELECT * FROM %s WHERE (b, c) > (20, 30) AND d = 34");
+ });
+ }
+
+ @Test
+ public void containsFilteringForClusteringKeys() throws Throwable
+ {
+ //-------------------------------------------------
+ // Frozen collections filtering for clustering keys
+ //-------------------------------------------------
+ createTable("CREATE TABLE %s (a int, b int, c frozen<list<int>>, d int, PRIMARY KEY (a, b, c))");
+
+ execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", 11, 12, list(1, 3), 14);
+ execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", 21, 22, list(2, 3), 24);
+ execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", 21, 22, list(3, 3), 34);
+
+ beforeAndAfterFlush(() -> {
+
+ assertRows(execute("SELECT * FROM %s WHERE b > 20 AND c CONTAINS 2 ALLOW FILTERING"),
+ row(21, 22, list(2, 3), 24));
+ assertInvalidMessage("Clustering column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)",
+ "SELECT * FROM %s WHERE b > 20 AND c CONTAINS 2");
+
+ assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 3 ALLOW FILTERING"),
+ row(11, 12, list(1, 3), 14),
+ row(21, 22, list(2, 3), 24),
+ row(21, 22, list(3, 3), 34));
+ });
+
+ createTable("CREATE TABLE %s (a int, b int, c frozen<map<text, text>>, d int, PRIMARY KEY (a, b, c))");
+
+ execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", 11, 12, map("1", "3"), 14);
+ execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", 21, 22, map("2", "3"), 24);
+ execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", 21, 22, map("3", "3"), 34);
+
+ beforeAndAfterFlush(() -> {
+ assertRows(execute("SELECT * FROM %s WHERE b > 20 AND c CONTAINS KEY '2' ALLOW FILTERING"),
+ row(21, 22, map("2", "3"), 24));
+ assertInvalidMessage("Clustering column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)",
+ "SELECT * FROM %s WHERE b > 20 AND c CONTAINS KEY '2'");
+ });
+ }
+
+ @Test
+ public void filteringWithOrderClause() throws Throwable
+ {
+ createTable("CREATE TABLE %s (a int, b int, c int, d list<int>, PRIMARY KEY (a, b, c))");
+
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 11, 12, 13, list(1,4));
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 22, 23, list(2,4));
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 25, 26, list(2,7));
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 31, 32, 33, list(3,4));
+
+ beforeAndAfterFlush(() -> {
+
+ assertRows(executeFilteringOnly("SELECT a, b, c, d FROM %s WHERE a = 21 AND c > 20 ORDER BY b DESC"),
+ row(21, 25, 26, list(2, 7)),
+ row(21, 22, 23, list(2, 4)));
+
+ assertRows(executeFilteringOnly("SELECT a, b, c, d FROM %s WHERE a IN(21, 31) AND c > 20 ORDER BY b DESC"),
+ row(31, 32, 33, list(3, 4)),
+ row(21, 25, 26, list(2, 7)),
+ row(21, 22, 23, list(2, 4)));
+ });
+ }
+
+
+ @Test
+ public void filteringOnStaticColumnTest() throws Throwable
+ {
+ createTable("CREATE TABLE %s (a int, b int, c int, d int, s int static, PRIMARY KEY (a, b))");
+
+ execute("INSERT INTO %s (a, b, c, d, s) VALUES (11, 12, 13, 14, 15)");
+ execute("INSERT INTO %s (a, b, c, d, s) VALUES (21, 22, 23, 24, 25)");
+ execute("INSERT INTO %s (a, b, c, d, s) VALUES (21, 26, 27, 28, 29)");
+ execute("INSERT INTO %s (a, b, c, d, s) VALUES (31, 32, 33, 34, 35)");
+ execute("INSERT INTO %s (a, b, c, d, s) VALUES (11, 42, 43, 44, 45)");
+
+ beforeAndAfterFlush(() -> {
+
+ assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE s = 29"),
+ row(21, 22, 23, 24, 29),
+ row(21, 26, 27, 28, 29));
+ assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE b > 22 AND s = 29"),
+ row(21, 26, 27, 28, 29));
+ assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE b > 10 and b < 26 AND s = 29"),
+ row(21, 22, 23, 24, 29));
+ assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE c > 10 and c < 27 AND s = 29"),
+ row(21, 22, 23, 24, 29));
+ assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE c > 10 and c < 43 AND s = 29"),
+ row(21, 22, 23, 24, 29),
+ row(21, 26, 27, 28, 29));
+ assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE c > 10 AND s > 15 AND s < 45"),
+ row(21, 22, 23, 24, 29),
+ row(21, 26, 27, 28, 29),
+ row(31, 32, 33, 34, 35));
+ assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE a = 21 AND s > 15 AND s < 45 ORDER BY b DESC"),
+ row(21, 26, 27, 28, 29),
+ row(21, 22, 23, 24, 29));
+ assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE c > 13 and d < 44"),
+ row(21, 22, 23, 24, 29),
+ row(21, 26, 27, 28, 29),
+ row(31, 32, 33, 34, 35));
+ });
+ }
+
+ @Test
+ public void containsFilteringOnNonClusteringColumn() throws Throwable {
+ createTable("CREATE TABLE %s (a int, b int, c int, d list<int>, PRIMARY KEY (a, b, c))");
+
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 11, 12, 13, list(1,4));
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 22, 23, list(2,4));
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 25, 26, list(2,7));
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 31, 32, 33, list(3,4));
+
+ beforeAndAfterFlush(() -> {
+
+ assertRows(executeFilteringOnly("SELECT a, b, c, d FROM %s WHERE b > 20 AND d CONTAINS 2"),
+ row(21, 22, 23, list(2, 4)),
+ row(21, 25, 26, list(2, 7)));
+
+ assertRows(executeFilteringOnly("SELECT a, b, c, d FROM %s WHERE b > 20 AND d CONTAINS 2 AND d contains 4"),
+ row(21, 22, 23, list(2, 4)));
+ });
+ }
+
+ @Test
+ public void filteringOnCompactTable() throws Throwable
+ {
+ createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c)) WITH COMPACT STORAGE");
+
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 11, 12, 13, 14);
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 22, 23, 24);
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 25, 26, 27);
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 31, 32, 33, 34);
+
+ beforeAndAfterFlush(() -> {
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c > 13"),
+ row(21, 22, 23, 24),
+ row(21, 25, 26, 27),
+ row(31, 32, 33, 34));
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c > 13 AND c < 33"),
+ row(21, 22, 23, 24),
+ row(21, 25, 26, 27));
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c > 13 AND b < 32"),
+ row(21, 22, 23, 24),
+ row(21, 25, 26, 27));
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE a = 21 AND c > 13 AND b < 32 ORDER BY b DESC"),
+ row(21, 25, 26, 27),
+ row(21, 22, 23, 24));
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE a IN (21, 31) AND c > 13 ORDER BY b DESC"),
+ row(31, 32, 33, 34),
+ row(21, 25, 26, 27),
+ row(21, 22, 23, 24));
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c > 13 AND d < 34"),
+ row(21, 22, 23, 24),
+ row(21, 25, 26, 27));
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c > 13"),
+ row(21, 22, 23, 24),
+ row(21, 25, 26, 27),
+ row(31, 32, 33, 34));
+ });
+
+ // with frozen in clustering key
+ createTable("CREATE TABLE %s (a int, b int, c frozen<list<int>>, d int, PRIMARY KEY (a, b, c)) WITH COMPACT STORAGE");
+
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 11, 12, list(1, 3), 14);
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 22, list(2, 3), 24);
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 25, list(2, 6), 27);
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 31, 32, list(3, 3), 34);
+
+ beforeAndAfterFlush(() -> {
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c CONTAINS 2"),
+ row(21, 22, list(2, 3), 24),
+ row(21, 25, list(2, 6), 27));
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c CONTAINS 2 AND b < 25"),
+ row(21, 22, list(2, 3), 24));
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS 3"),
+ row(21, 22, list(2, 3), 24));
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE b > 12 AND c CONTAINS 2 AND d < 27"),
+ row(21, 22, list(2, 3), 24));
+ });
+
+ // with frozen in value
+ createTable("CREATE TABLE %s (a int, b int, c int, d frozen<list<int>>, PRIMARY KEY (a, b, c)) WITH COMPACT STORAGE");
+
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 11, 12, 13, list(1, 4));
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 22, 23, list(2, 4));
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 25, 25, list(2, 6));
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 31, 32, 34, list(3, 4));
+
+ beforeAndAfterFlush(() -> {
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE d CONTAINS 2"),
+ row(21, 22, 23, list(2, 4)),
+ row(21, 25, 25, list(2, 6)));
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE d CONTAINS 2 AND b < 25"),
+ row(21, 22, 23, list(2, 4)));
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE d CONTAINS 2 AND d CONTAINS 4"),
+ row(21, 22, 23, list(2, 4)));
+
+ assertRows(executeFilteringOnly("SELECT * FROM %s WHERE b > 12 AND c < 25 AND d CONTAINS 2"),
+ row(21, 22, 23, list(2, 4)));
+ });
+ }
+
+ private UntypedResultSet executeFilteringOnly(String statement) throws Throwable
+ {
+ assertInvalid(statement);
+ return execute(statement + " ALLOW FILTERING");
+ }
}
\ No newline at end of file
[2/2] cassandra git commit: Allow filtering on clustering columns for
queries without secondary indexes
Posted by bl...@apache.org.
Allow filtering on clustering columns for queries without secondary indexes
patch by Alex Petrov; reviewed by Benjamin Lerer for CASSANDRA-11310
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/a600920c
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/a600920c
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/a600920c
Branch: refs/heads/trunk
Commit: a600920cb5ee2866b09ee6c1ebae9518096e5bc4
Parents: 831bebd
Author: Alex Petrov <ol...@gmail.com>
Authored: Fri Apr 15 22:26:02 2016 +0200
Committer: Benjamin Lerer <b....@gmail.com>
Committed: Fri Apr 15 22:26:02 2016 +0200
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../ClusteringColumnRestrictions.java | 80 +-
.../restrictions/StatementRestrictions.java | 58 +-
.../entities/FrozenCollectionsTest.java | 9 +-
.../cql3/validation/operations/SelectTest.java | 1067 ++++++++++++------
5 files changed, 800 insertions(+), 415 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a600920c/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index acbbfa5..7bb97e5 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
3.6
+ * Allow filtering on clustering columns for queries without secondary indexes (CASSANDRA-11310)
* Refactor Restriction hierarchy (CASSANDRA-11354)
* Eliminate allocations in R/W path (CASSANDRA-11421)
* Update Netty to 4.0.36 (CASSANDRA-11567)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a600920c/src/java/org/apache/cassandra/cql3/restrictions/ClusteringColumnRestrictions.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/restrictions/ClusteringColumnRestrictions.java b/src/java/org/apache/cassandra/cql3/restrictions/ClusteringColumnRestrictions.java
index 47cf76b..ab16ebc 100644
--- a/src/java/org/apache/cassandra/cql3/restrictions/ClusteringColumnRestrictions.java
+++ b/src/java/org/apache/cassandra/cql3/restrictions/ClusteringColumnRestrictions.java
@@ -42,16 +42,28 @@ final class ClusteringColumnRestrictions extends RestrictionSetWrapper
*/
protected final ClusteringComparator comparator;
+ /**
+ * <code>true</code> if filtering is allowed for this restriction, <code>false</code> otherwise
+ */
+ private final boolean allowFiltering;
+
public ClusteringColumnRestrictions(CFMetaData cfm)
{
- super(new RestrictionSet());
- this.comparator = cfm.comparator;
+ this(cfm, false);
}
- private ClusteringColumnRestrictions(ClusteringComparator comparator, RestrictionSet restrictionSet)
+ public ClusteringColumnRestrictions(CFMetaData cfm, boolean allowFiltering)
+ {
+ this(cfm.comparator, new RestrictionSet(), allowFiltering);
+ }
+
+ private ClusteringColumnRestrictions(ClusteringComparator comparator,
+ RestrictionSet restrictionSet,
+ boolean allowFiltering)
{
super(restrictionSet);
this.comparator = comparator;
+ this.allowFiltering = allowFiltering;
}
public ClusteringColumnRestrictions mergeWith(Restriction restriction) throws InvalidRequestException
@@ -59,7 +71,7 @@ final class ClusteringColumnRestrictions extends RestrictionSetWrapper
SingleRestriction newRestriction = (SingleRestriction) restriction;
RestrictionSet newRestrictionSet = restrictions.addRestriction(newRestriction);
- if (!isEmpty())
+ if (!isEmpty() && !allowFiltering)
{
SingleRestriction lastRestriction = restrictions.lastRestriction();
ColumnDefinition lastRestrictionStart = lastRestriction.getFirstColumn();
@@ -76,7 +88,7 @@ final class ClusteringColumnRestrictions extends RestrictionSetWrapper
newRestrictionStart.name);
}
- return new ClusteringColumnRestrictions(this.comparator, newRestrictionSet);
+ return new ClusteringColumnRestrictions(this.comparator, newRestrictionSet, allowFiltering);
}
private boolean hasMultiColumnSlice()
@@ -105,11 +117,10 @@ final class ClusteringColumnRestrictions extends RestrictionSetWrapper
{
MultiCBuilder builder = MultiCBuilder.create(comparator, hasIN() || hasMultiColumnSlice());
int keyPosition = 0;
+
for (SingleRestriction r : restrictions)
{
- ColumnDefinition def = r.getFirstColumn();
-
- if (keyPosition != def.position() || r.isContains() || r.isLIKE())
+ if (handleInFilter(r, keyPosition))
break;
if (r.isSlice())
@@ -155,6 +166,32 @@ final class ClusteringColumnRestrictions extends RestrictionSetWrapper
return restrictions.stream().anyMatch(SingleRestriction::isSlice);
}
+ /**
+ * Checks if underlying restrictions would require filtering
+ *
+ * @return <code>true</code> if any underlying restrictions require filtering, <code>false</code>
+ * otherwise
+ */
+ public final boolean needFiltering()
+ {
+ int position = 0;
+ SingleRestriction slice = null;
+ for (SingleRestriction restriction : restrictions)
+ {
+ if (handleInFilter(restriction, position))
+ return true;
+
+ if (slice != null && !slice.getFirstColumn().equals(restriction.getFirstColumn()))
+ return true;
+
+ if (slice == null && restriction.isSlice())
+ slice = restriction;
+ else
+ position = restriction.getLastColumn().position() + 1;
+ }
+ return hasContains();
+ }
+
@Override
public void addRowFilterTo(RowFilter filter,
SecondaryIndexManager indexManager,
@@ -162,18 +199,31 @@ final class ClusteringColumnRestrictions extends RestrictionSetWrapper
{
int position = 0;
+ SingleRestriction slice = null;
for (SingleRestriction restriction : restrictions)
{
- ColumnDefinition columnDef = restriction.getFirstColumn();
-
// We ignore all the clustering columns that can be handled by slices.
- if (!(restriction.isContains() || restriction.isLIKE()) && position == columnDef.position())
+ if (handleInFilter(restriction, position) || restriction.hasSupportingIndex(indexManager))
{
- position = restriction.getLastColumn().position() + 1;
- if (!restriction.hasSupportingIndex(indexManager))
- continue;
+ restriction.addRowFilterTo(filter, indexManager, options);
+ continue;
}
- restriction.addRowFilterTo(filter, indexManager, options);
+
+ if (slice != null && !slice.getFirstColumn().equals(restriction.getFirstColumn()))
+ {
+ restriction.addRowFilterTo(filter, indexManager, options);
+ continue;
+ }
+
+ if (slice == null && restriction.isSlice())
+ slice = restriction;
+ else
+ position = restriction.getLastColumn().position() + 1;
}
}
+
+ private boolean handleInFilter(SingleRestriction restriction, int index) {
+ return restriction.isContains() || restriction.isLIKE() || index != restriction.getFirstColumn().position();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a600920c/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java
index 032a622..b146cfd 100644
--- a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java
+++ b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java
@@ -85,7 +85,7 @@ public final class StatementRestrictions
/**
* The restrictions used to build the row filter
*/
- private final IndexRestrictions indexRestrictions = new IndexRestrictions();
+ private final IndexRestrictions filterRestrictions = new IndexRestrictions();
/**
* <code>true</code> if the secondary index need to be queried, <code>false</code> otherwise
@@ -106,15 +106,15 @@ public final class StatementRestrictions
*/
public static StatementRestrictions empty(StatementType type, CFMetaData cfm)
{
- return new StatementRestrictions(type, cfm);
+ return new StatementRestrictions(type, cfm, false);
}
- private StatementRestrictions(StatementType type, CFMetaData cfm)
+ private StatementRestrictions(StatementType type, CFMetaData cfm, boolean allowFiltering)
{
this.type = type;
this.cfm = cfm;
this.partitionKeyRestrictions = new PartitionKeySingleRestrictionSet(cfm.getKeyValidatorAsClusteringComparator());
- this.clusteringColumnsRestrictions = new ClusteringColumnRestrictions(cfm);
+ this.clusteringColumnsRestrictions = new ClusteringColumnRestrictions(cfm, allowFiltering);
this.nonPrimaryKeyRestrictions = new RestrictionSet();
this.notNullColumns = new HashSet<>();
}
@@ -125,10 +125,10 @@ public final class StatementRestrictions
VariableSpecifications boundNames,
boolean selectsOnlyStaticColumns,
boolean selectsComplexColumn,
- boolean useFiltering,
- boolean forView) throws InvalidRequestException
+ boolean allowFiltering,
+ boolean forView)
{
- this(type, cfm);
+ this(type, cfm, allowFiltering);
ColumnFamilyStore cfs;
@@ -185,7 +185,7 @@ public final class StatementRestrictions
processCustomIndexExpressions(whereClause.expressions, boundNames, secondaryIndexManager);
hasQueriableClusteringColumnIndex = clusteringColumnsRestrictions.hasSupportingIndex(secondaryIndexManager);
- hasQueriableIndex = !indexRestrictions.getCustomIndexExpressions().isEmpty()
+ hasQueriableIndex = !filterRestrictions.getCustomIndexExpressions().isEmpty()
|| hasQueriableClusteringColumnIndex
|| partitionKeyRestrictions.hasSupportingIndex(secondaryIndexManager)
|| nonPrimaryKeyRestrictions.hasSupportingIndex(secondaryIndexManager);
@@ -197,7 +197,7 @@ public final class StatementRestrictions
// Some but not all of the partition key columns have been specified;
// hence we need turn these restrictions into a row filter.
if (usesSecondaryIndexing)
- indexRestrictions.add(partitionKeyRestrictions);
+ filterRestrictions.add(partitionKeyRestrictions);
if (selectsOnlyStaticColumns && hasClusteringColumnsRestriction())
{
@@ -218,16 +218,18 @@ public final class StatementRestrictions
throw invalidRequest("Cannot restrict clustering columns when selecting only static columns");
}
- processClusteringColumnsRestrictions(hasQueriableIndex, selectsOnlyStaticColumns, selectsComplexColumn, forView);
+ processClusteringColumnsRestrictions(hasQueriableIndex,
+ selectsOnlyStaticColumns,
+ selectsComplexColumn,
+ forView,
+ allowFiltering);
// Covers indexes on the first clustering column (among others).
if (isKeyRange && hasQueriableClusteringColumnIndex)
usesSecondaryIndexing = true;
- usesSecondaryIndexing = usesSecondaryIndexing || clusteringColumnsRestrictions.hasContains();
-
- if (usesSecondaryIndexing)
- indexRestrictions.add(clusteringColumnsRestrictions);
+ if (usesSecondaryIndexing || clusteringColumnsRestrictions.needFiltering())
+ filterRestrictions.add(clusteringColumnsRestrictions);
// Even if usesSecondaryIndexing is false at this point, we'll still have to use one if
// there is restrictions not covered by the PK.
@@ -243,10 +245,10 @@ public final class StatementRestrictions
}
if (hasQueriableIndex)
usesSecondaryIndexing = true;
- else if (!useFiltering)
+ else if (!allowFiltering)
throw invalidRequest(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE);
- indexRestrictions.add(nonPrimaryKeyRestrictions);
+ filterRestrictions.add(nonPrimaryKeyRestrictions);
}
if (usesSecondaryIndexing)
@@ -274,7 +276,7 @@ public final class StatementRestrictions
// may be used by QueryHandler implementations
public IndexRestrictions getIndexRestrictions()
{
- return indexRestrictions;
+ return filterRestrictions;
}
/**
@@ -285,7 +287,7 @@ public final class StatementRestrictions
public Set<ColumnDefinition> nonPKRestrictedColumns(boolean includeNotNullRestrictions)
{
Set<ColumnDefinition> columns = new HashSet<>();
- for (Restrictions r : indexRestrictions.getRestrictions())
+ for (Restrictions r : filterRestrictions.getRestrictions())
{
for (ColumnDefinition def : r.getColumnDefs())
if (!def.isPrimaryKeyColumn())
@@ -451,7 +453,8 @@ public final class StatementRestrictions
private void processClusteringColumnsRestrictions(boolean hasQueriableIndex,
boolean selectsOnlyStaticColumns,
boolean selectsComplexColumn,
- boolean forView) throws InvalidRequestException
+ boolean forView,
+ boolean allowFiltering)
{
checkFalse(!type.allowClusteringColumnSlices() && clusteringColumnsRestrictions.hasSlice(),
"Slice restrictions are not supported on the clustering columns in %s statements", type);
@@ -467,9 +470,10 @@ public final class StatementRestrictions
{
checkFalse(clusteringColumnsRestrictions.hasIN() && selectsComplexColumn,
"Cannot restrict clustering columns by IN relations when a collection is selected by the query");
- checkFalse(clusteringColumnsRestrictions.hasContains() && !hasQueriableIndex,
+ checkFalse(clusteringColumnsRestrictions.hasContains() && !hasQueriableIndex && !allowFiltering,
"Cannot restrict clustering columns by a CONTAINS relation without a secondary index");
+
if (hasClusteringColumnsRestriction())
{
List<ColumnDefinition> clusteringColumns = cfm.clusteringColumns();
@@ -480,7 +484,7 @@ public final class StatementRestrictions
ColumnDefinition clusteringColumn = clusteringColumns.get(i);
ColumnDefinition restrictedColumn = restrictedColumns.get(i);
- if (!clusteringColumn.equals(restrictedColumn))
+ if (!clusteringColumn.equals(restrictedColumn) && !allowFiltering)
{
checkTrue(hasQueriableIndex || forView,
"PRIMARY KEY column \"%s\" cannot be restricted as preceding column \"%s\" is not restricted",
@@ -552,19 +556,19 @@ public final class StatementRestrictions
expression.prepareValue(cfm, expressionType, boundNames);
- indexRestrictions.add(expression);
+ filterRestrictions.add(expression);
}
public RowFilter getRowFilter(SecondaryIndexManager indexManager, QueryOptions options)
{
- if (indexRestrictions.isEmpty())
+ if (filterRestrictions.isEmpty())
return RowFilter.NONE;
RowFilter filter = RowFilter.create();
- for (Restrictions restrictions : indexRestrictions.getRestrictions())
+ for (Restrictions restrictions : filterRestrictions.getRestrictions())
restrictions.addRowFilterTo(filter, indexManager, options);
- for (CustomIndexExpression expression : indexRestrictions.getCustomIndexExpressions())
+ for (CustomIndexExpression expression : filterRestrictions.getCustomIndexExpressions())
expression.addToRowFilter(filter, cfm, options);
return filter;
@@ -743,8 +747,8 @@ public final class StatementRestrictions
*/
public boolean needFiltering()
{
- int numberOfRestrictions = indexRestrictions.getCustomIndexExpressions().size();
- for (Restrictions restrictions : indexRestrictions.getRestrictions())
+ int numberOfRestrictions = filterRestrictions.getCustomIndexExpressions().size();
+ for (Restrictions restrictions : filterRestrictions.getRestrictions())
numberOfRestrictions += restrictions.size();
return numberOfRestrictions > 1
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a600920c/test/unit/org/apache/cassandra/cql3/validation/entities/FrozenCollectionsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/FrozenCollectionsTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/FrozenCollectionsTest.java
index 9df8ea0..4aa178a 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/FrozenCollectionsTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/FrozenCollectionsTest.java
@@ -633,14 +633,15 @@ public class FrozenCollectionsTest extends CQLTester
assertInvalidMessage("Cannot restrict clustering columns by a CONTAINS relation without a secondary index",
"SELECT * FROM %s WHERE b CONTAINS ?", 1);
- assertInvalidMessage("Cannot restrict clustering columns by a CONTAINS relation without a secondary index",
- "SELECT * FROM %s WHERE b CONTAINS ? ALLOW FILTERING", 1);
+ assertRows(execute("SELECT * FROM %s WHERE b CONTAINS ? ALLOW FILTERING", 1),
+ row(0, list(1, 2, 3), set(1, 2, 3), map(1, "a")),
+ row(1, list(1, 2, 3), set(4, 5, 6), map(2, "b")));
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
"SELECT * FROM %s WHERE d CONTAINS KEY ?", 1);
- assertInvalidMessage("Cannot restrict clustering columns by a CONTAINS relation without a secondary index",
- "SELECT * FROM %s WHERE b CONTAINS ? AND d CONTAINS KEY ? ALLOW FILTERING", 1, 1);
+ assertRows(execute("SELECT * FROM %s WHERE b CONTAINS ? AND d CONTAINS KEY ? ALLOW FILTERING", 1, 1),
+ row(0, list(1, 2, 3), set(1, 2, 3), map(1, "a")));
// index lookup on b
assertRows(execute("SELECT * FROM %s WHERE b=?", list(1, 2, 3)),