http://git-wip-us.apache.org/repos/asf/cassandra/blob/9583b6b3/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
----------------------------------------------------------------------
diff --cc
test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
index c8df4c3,cef4635..ac1ba4c
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
@@@ -23,15 -23,18 +23,18 @@@ import java.util.UUID
import org.junit.Test;
import junit.framework.Assert;
-import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.cql3.UntypedResultSet;
-import org.apache.cassandra.cql3.CQLTester;
-import org.apache.cassandra.dht.Murmur3Partitioner;
+import org.apache.cassandra.cql3.restrictions.StatementRestrictions;
import org.apache.cassandra.exceptions.InvalidRequestException;
- import org.apache.cassandra.utils.ByteBufferUtil;
+
+import org.apache.cassandra.cql3.CQLTester;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+
+ import static org.apache.cassandra.utils.ByteBufferUtil.EMPTY_BYTE_BUFFER;
+ import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
+
/**
* Test column ranges and ordering with static column in table
*/
@@@ -1367,891 -1240,6 +1370,891 @@@ public class SelectTest extends CQLTest
}
@Test
+ public void testAlias() throws Throwable
+ {
+ createTable("CREATE TABLE %s (id int PRIMARY KEY, name text)");
+
+ for (int i = 0; i < 5; i++)
+ execute("INSERT INTO %s (id, name) VALUES (?, ?) USING TTL 10 AND
TIMESTAMP 0", i, Integer.toString(i));
+
+ assertInvalidMessage("Aliases aren't allowed in the where clause",
+ "SELECT id AS user_id, name AS user_name FROM %s
WHERE user_id = 0");
+
+ // test that select throws a meaningful exception for aliases in
order by clause
+ assertInvalidMessage("Aliases are not allowed in order by clause",
+ "SELECT id AS user_id, name AS user_name FROM %s
WHERE id IN (0) ORDER BY user_name");
+
+ }
+
+ @Test
+ public void testFilteringWithoutIndices() throws Throwable
+ {
+ createTable("CREATE TABLE %s (a int, b int, c int, d int, e map<int,
int>, PRIMARY KEY (a, b))");
+
+ // Checks filtering
+ assertInvalidMessage("Predicates on non-primary-key columns (c, d)
are not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = 1 AND d = 2 ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE a = 1 AND b = 1 AND c =
2 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 (2,
3) ALLOW FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > 2 ALLOW FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS 1 ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS KEY 1 ALLOW
FILTERING");
+
+ // Checks filtering with null
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS KEY null
ALLOW FILTERING");
+
+ // Checks filtering with unset
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = ? ALLOW FILTERING",
unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > ? ALLOW FILTERING",
unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS ? ALLOW
FILTERING", unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS KEY ? ALLOW
FILTERING", unset());
+
+ createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY(a))
WITH COMPACT STORAGE");
+
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 2, 4)");
+ execute("INSERT INTO %s (a, b, c) VALUES (2, 2, 8)");
+ execute("INSERT INTO %s (a, b, c) VALUES (3, 6, 4)");
+
+ assertRows(execute("SELECT * FROM %s WHERE c = 4 ALLOW FILTERING"),
+ row(1, 2, 4),
+ row(3, 6, 4));
+
+ // Checks filtering with null
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
"SELECT * FROM %s WHERE c = null");
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
"SELECT * FROM %s WHERE c > null");
+ assertInvalidMessage("Unsupported null value for column c", "SELECT *
FROM %s WHERE c = null ALLOW FILTERING");
+ assertInvalidMessage("Unsupported null value for column c", "SELECT *
FROM %s WHERE c > null ALLOW FILTERING");
+
+ // Checks filtering with unset
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c = ?", unset());
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > ?", unset());
+ assertInvalidMessage("Unsupported unset value for column c",
+ "SELECT * FROM %s WHERE c = ? ALLOW FILTERING",
unset());
+ assertInvalidMessage("Unsupported unset value for column c",
+ "SELECT * FROM %s WHERE c > ? ALLOW FILTERING",
unset());
+ }
+
+ @Test
+ public void testFilteringOnStaticColumnWithoutIndices() throws Throwable
+ {
+ createTable("CREATE TABLE %s (a int, b int, s int static, c int,
PRIMARY KEY (a, b))");
+
+ // Checks filtering
+ assertInvalidMessage("Predicates on non-primary-key columns (c, s)
are not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = 1 AND s = 2 ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (s) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE a = 1 AND b = 1 AND s =
2 ALLOW FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (s) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE s > 2 ALLOW FILTERING");
+
+ // Checks filtering with null
+ assertInvalidMessage("Predicates on non-primary-key columns (s) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE s = null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (s) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE s > null ALLOW
FILTERING");
+
+ // Checks filtering with unset
+ assertInvalidMessage("Predicates on non-primary-key columns (s) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE s = ? ALLOW FILTERING",
unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (s) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE s > ? ALLOW FILTERING",
unset());
+ }
+
+ @Test
+ public void testFilteringOnCompactTablesWithoutIndices() throws Throwable
+ {
+ //----------------------------------------------
+ // Test COMPACT table with clustering columns
+ //----------------------------------------------
+ createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY (a,
b)) WITH COMPACT STORAGE");
+
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 2, 4)");
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 3, 6)");
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 4, 4)");
+ execute("INSERT INTO %s (a, b, c) VALUES (2, 3, 7)");
+
+ // Lets add some tombstones to make sure that filtering handle them
properly
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 1, 4)");
+ execute("INSERT INTO %s (a, b, c) VALUES (2, 2, 7)");
+ execute("DELETE FROM %s WHERE a = 1 AND b = 1");
+ execute("DELETE FROM %s WHERE a = 2 AND b = 2");
+
+ flush();
+
+ // Checks filtering
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE a = 1 AND b = 4 AND c =
4 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("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > 4 ALLOW FILTERING");
+
+ // Checks filtering with null
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = null");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > null");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > null ALLOW
FILTERING");
+
+ // Checks filtering with unset
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > ? ALLOW FILTERING",
+ unset());
+
+ //----------------------------------------------
+ // Test COMPACT table without clustering columns
+ //----------------------------------------------
+ createTable("CREATE TABLE %s (a int PRIMARY KEY, b int, c int) WITH
COMPACT STORAGE");
+
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 2, 4)");
+ execute("INSERT INTO %s (a, b, c) VALUES (2, 1, 6)");
+ execute("INSERT INTO %s (a, b, c) VALUES (3, 2, 4)");
+ execute("INSERT INTO %s (a, b, c) VALUES (4, 1, 7)");
+
+ // Lets add some tombstones to make sure that filtering handle them
properly
+ execute("INSERT INTO %s (a, b, c) VALUES (0, 1, 4)");
+ execute("INSERT INTO %s (a, b, c) VALUES (5, 2, 7)");
+ execute("DELETE FROM %s WHERE a = 0");
+ execute("DELETE FROM %s WHERE a = 5");
+
+ flush();
+
+ // 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));
+
+ 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(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));
+
+
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));
+
+
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));
+
+ // Checks filtering with null
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c = null");
+ assertInvalidMessage("Unsupported null value for column c",
+ "SELECT * FROM %s WHERE c = null ALLOW
FILTERING");
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > null");
+ assertInvalidMessage("Unsupported null value for column c",
+ "SELECT * FROM %s WHERE c > null ALLOW
FILTERING");
+
+ // Checks filtering with unset
+ assertInvalidMessage("Unsupported unset value for column c",
+ "SELECT * FROM %s WHERE c = ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Unsupported unset value for column c",
+ "SELECT * FROM %s WHERE c > ? ALLOW FILTERING",
+ unset());
+ }
+
+ @Test
+ public void testFilteringWithoutIndicesWithCollections() throws Throwable
+ {
+ createTable("CREATE TABLE %s (a int, b int, c list<int>, d set<int>,
e map<int, int>, PRIMARY KEY (a, b))");
+
+ execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 2, [1, 6], {2,
12}, {1: 6})");
+ execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 3, [3, 2], {6, 4},
{3: 2})");
+ 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();
+
+ // Checks filtering for lists
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS 2 ALLOW
FILTERING");
+
+ // Checks filtering for sets
+ assertInvalidMessage("Predicates on non-primary-key columns (d) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE d CONTAINS 4 ALLOW
FILTERING");
+
+ // Checks filtering for maps
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS 2 ALLOW
FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS KEY 2 ALLOW
FILTERING");
+
+ // Checks filtering with null
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (d) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE d CONTAINS null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS KEY null
ALLOW FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e[null] = 2 ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e[1] = null ALLOW
FILTERING");
+
+ // Checks filtering with unset
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS ? ALLOW
FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (d) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE d CONTAINS ? ALLOW
FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS ? ALLOW
FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS KEY ? ALLOW
FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e[?] = 2 ALLOW
FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e[1] = ? ALLOW
FILTERING",
+ unset());
+ }
+
+ @Test
+ public void testFilteringWithoutIndicesWithFrozenCollections() throws
Throwable
+ {
+ createTable("CREATE TABLE %s (a int, b int, c frozen<list<int>>, d
frozen<set<int>>, e frozen<map<int, int>>, PRIMARY KEY (a, b))");
+
+ execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 2, [1, 6], {2,
12}, {1: 6})");
+ execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 3, [3, 2], {6, 4},
{3: 2})");
+ 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();
+
+ // Checks filtering for lists
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = [3, 2] ALLOW
FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > [1, 5] AND c < [3,
6] ALLOW FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS 2 ALLOW
FILTERING");
+
+ // Checks filtering for sets
+ assertInvalidMessage("Predicates on non-primary-key columns (d) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE d = {6, 4} ALLOW
FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (d) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE d > {4, 5} AND d < {6}
ALLOW FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (d) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE d CONTAINS 4 ALLOW
FILTERING");
+
+ // Checks filtering for maps
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e = {1 : 2} ALLOW
FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e > {1 : 4} AND e < {3 : 6} ALLOW
FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS 2 ALLOW
FILTERING");
+
+ assertInvalidMessage("Map-entry equality predicates on frozen map
column e are not supported",
+ "SELECT * FROM %s WHERE e[1] = 6 ALLOW
FILTERING");
+
+ // Checks filtering with null
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (d) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE d = null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (d) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE d CONTAINS null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e = null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS KEY null
ALLOW FILTERING");
+ assertInvalidMessage("Map-entry equality predicates on frozen map
column e are not supported",
+ "SELECT * FROM %s WHERE e[null] = 2 ALLOW
FILTERING");
+ assertInvalidMessage("Map-entry equality predicates on frozen map
column e are not supported",
+ "SELECT * FROM %s WHERE e[1] = null ALLOW
FILTERING");
+
+ // Checks filtering with unset
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS ? ALLOW
FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (d) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE d = ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (d) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE d CONTAINS ? ALLOW
FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e = ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS ? ALLOW
FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (e) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE e CONTAINS KEY ? ALLOW
FILTERING",
+ unset());
+ assertInvalidMessage("Map-entry equality predicates on frozen map
column e are not supported",
+ "SELECT * FROM %s WHERE e[?] = 2 ALLOW
FILTERING",
+ unset());
+ assertInvalidMessage("Map-entry equality predicates on frozen map
column e are not supported",
+ "SELECT * FROM %s WHERE e[1] = ? ALLOW
FILTERING",
+ unset());
+ }
+
+ @Test
+ public void testFilteringOnCompactTablesWithoutIndicesAndWithLists()
throws Throwable
+ {
+ //----------------------------------------------
+ // Test COMPACT table with clustering columns
+ //----------------------------------------------
+ createTable("CREATE TABLE %s (a int, b int, c frozen<list<int>>,
PRIMARY KEY (a, b)) WITH COMPACT STORAGE");
+
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 2, [4, 2])");
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 3, [6, 2])");
+ 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("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE a = 1 AND b = 4 AND c =
[4, 1] ALLOW FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > [4, 2] ALLOW
FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE b <= 3 AND c < [6, 2]
ALLOW FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS 2 ALLOW
FILTERING");
+
+ assertInvalidMessage("Cannot use CONTAINS KEY on non-map column c",
+ "SELECT * FROM %s WHERE c CONTAINS KEY 2 ALLOW
FILTERING");
+
+ // Checks filtering with null
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = null");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > null");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS null");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS null ALLOW
FILTERING");
+
+ // Checks filtering with unset
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS ? ALLOW
FILTERING",
+ unset());
+
+ //----------------------------------------------
+ // Test COMPACT table without clustering columns
+ //----------------------------------------------
+ createTable("CREATE TABLE %s (a int PRIMARY KEY, b int, c
frozen<list<int>>) WITH COMPACT STORAGE");
+
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 2, [4, 2])");
+ execute("INSERT INTO %s (a, b, c) VALUES (2, 1, [6, 2])");
+ 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();
+
+ // 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)));
+
+
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)));
+
+
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)));
+
+
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)));
+
+
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)));
+
+ 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)));
+
+ // Checks filtering with null
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c = null");
+ assertInvalidMessage("Unsupported null value for column c",
+ "SELECT * FROM %s WHERE c = null ALLOW
FILTERING");
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > null");
+ assertInvalidMessage("Unsupported null value for column c",
+ "SELECT * FROM %s WHERE c > null ALLOW
FILTERING");
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c CONTAINS null");
+ assertInvalidMessage("Unsupported null value for column c",
+ "SELECT * FROM %s WHERE c CONTAINS null ALLOW
FILTERING");
+
+ // Checks filtering with unset
+ assertInvalidMessage("Unsupported unset value for column c",
+ "SELECT * FROM %s WHERE c = ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Unsupported unset value for column c",
+ "SELECT * FROM %s WHERE c > ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Unsupported unset value for column c",
+ "SELECT * FROM %s WHERE c CONTAINS ? ALLOW
FILTERING",
+ unset());
+ }
+
+ @Test
+ public void testFilteringOnCompactTablesWithoutIndicesAndWithSets()
throws Throwable
+ {
+ //----------------------------------------------
+ // Test COMPACT table with clustering columns
+ //----------------------------------------------
+ createTable("CREATE TABLE %s (a int, b int, c frozen<set<int>>,
PRIMARY KEY (a, b)) WITH COMPACT STORAGE");
+
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 2, {4, 2})");
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 3, {6, 2})");
+ 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("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE a = 1 AND b = 4 AND c =
{4, 1} ALLOW FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > {4, 2} ALLOW
FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c >= {4, 2} AND c <= {6,
4} ALLOW FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS 2 ALLOW
FILTERING");
+
+ assertInvalidMessage("Cannot use CONTAINS KEY on non-map column c",
+ "SELECT * FROM %s WHERE c CONTAINS KEY 2 ALLOW
FILTERING");
+
+ // Checks filtering with null
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = null");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > null");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS null");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS null ALLOW
FILTERING");
+
+ // Checks filtering with unset
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS ? ALLOW
FILTERING",
+ unset());
+
+ //----------------------------------------------
+ // Test COMPACT table without clustering columns
+ //----------------------------------------------
+ createTable("CREATE TABLE %s (a int PRIMARY KEY, b int, c
frozen<set<int>>) WITH COMPACT STORAGE");
+
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 2, {4, 2})");
+ execute("INSERT INTO %s (a, b, c) VALUES (2, 1, {6, 2})");
+ 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();
+
+ // 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)));
+
+
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)));
+
+
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)));
+
+
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)));
+
+
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)));
+
+ 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)));
+
+ // Checks filtering with null
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c = null");
+ assertInvalidMessage("Unsupported null value for column c",
+ "SELECT * FROM %s WHERE c = null ALLOW
FILTERING");
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > null");
+ assertInvalidMessage("Unsupported null value for column c",
+ "SELECT * FROM %s WHERE c > null ALLOW
FILTERING");
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c CONTAINS null");
+ assertInvalidMessage("Unsupported null value for column c",
+ "SELECT * FROM %s WHERE c CONTAINS null ALLOW
FILTERING");
+
+ // Checks filtering with unset
+ assertInvalidMessage("Unsupported unset value for column c",
+ "SELECT * FROM %s WHERE c = ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Unsupported unset value for column c",
+ "SELECT * FROM %s WHERE c > ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Unsupported unset value for column c",
+ "SELECT * FROM %s WHERE c CONTAINS ? ALLOW
FILTERING",
+ unset());
+ }
+
+ @Test
+ public void testIndexQueryWithValueOver64K() throws Throwable
+ {
+ createTable("CREATE TABLE %s (a int, b int, c blob, PRIMARY KEY (a,
b))");
+ createIndex("CREATE INDEX test ON %s (c)");
+
- execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 0,
ByteBufferUtil.bytes(1));
- execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 1,
ByteBufferUtil.bytes(2));
++ execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 0, bytes(1));
++ execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 1, bytes(2));
+
+ assertInvalidMessage("Index expression values may not be larger than
64K",
+ "SELECT * FROM %s WHERE c = ? ALLOW FILTERING",
TOO_BIG);
+ }
+
+ @Test
+ public void testFilteringOnCompactTablesWithoutIndicesAndWithMaps()
throws Throwable
+ {
+ //----------------------------------------------
+ // Test COMPACT table with clustering columns
+ //----------------------------------------------
+ createTable("CREATE TABLE %s (a int, b int, c frozen<map<int, int>>,
PRIMARY KEY (a, b)) WITH COMPACT STORAGE");
+
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 2, {4 : 2})");
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 3, {6 : 2})");
+ 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("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE a = 1 AND b = 4 AND c =
{4 : 1} ALLOW FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > {4 : 2} ALLOW
FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE b <= 3 AND c < {6 : 2}
ALLOW FILTERING");
+
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS 2 ALLOW
FILTERING");
+
+ // Checks filtering with null
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = null");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > null");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS null");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS null ALLOW
FILTERING");
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS KEY null
ALLOW FILTERING");
+
+ // Checks filtering with unset
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c = ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c > ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS ? ALLOW
FILTERING",
+ unset());
+ assertInvalidMessage("Predicates on non-primary-key columns (c) are
not yet supported for non secondary index queries",
+ "SELECT * FROM %s WHERE c CONTAINS KEY ? ALLOW
FILTERING",
+ unset());
+
+ //----------------------------------------------
+ // Test COMPACT table without clustering columns
+ //----------------------------------------------
+ createTable("CREATE TABLE %s (a int PRIMARY KEY, b int, c
frozen<map<int, int>>) WITH COMPACT STORAGE");
+
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 2, {4 : 2})");
+ execute("INSERT INTO %s (a, b, c) VALUES (2, 1, {6 : 2})");
+ 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();
+
+ // 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)));
+
+
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)));
+
+
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)));
+
+
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)));
+
+
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 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)));
+
+ // Checks filtering with null
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c = null");
+ assertInvalidMessage("Unsupported null value for column c",
+ "SELECT * FROM %s WHERE c = null ALLOW
FILTERING");
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c > null");
+ assertInvalidMessage("Unsupported null value for column c",
+ "SELECT * FROM %s WHERE c > null ALLOW
FILTERING");
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c CONTAINS null");
+ assertInvalidMessage("Unsupported null value for column c",
+ "SELECT * FROM %s WHERE c CONTAINS null ALLOW
FILTERING");
+
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
+ "SELECT * FROM %s WHERE c CONTAINS KEY null");
+ assertInvalidMessage("Unsupported null value for column c",
+ "SELECT * FROM %s WHERE c CONTAINS KEY null
ALLOW FILTERING");
+
+ // Checks filtering with unset
+ assertInvalidMessage("Unsupported unset value for column c",
+ "SELECT * FROM %s WHERE c = ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Unsupported unset value for column c",
+ "SELECT * FROM %s WHERE c > ? ALLOW FILTERING",
+ unset());
+ assertInvalidMessage("Unsupported unset value for column c",
+ "SELECT * FROM %s WHERE c CONTAINS ? ALLOW
FILTERING",
+ unset());
+ assertInvalidMessage("Unsupported unset value for column c",
+ "SELECT * FROM %s WHERE c CONTAINS KEY ? ALLOW
FILTERING",
+ unset());
+ }
+
+ /**
+ * Check select with and without compact storage, with different column
+ * order. See CASSANDRA-10988
+ */
+ @Test
+ public void testClusteringOrderWithSlice() throws Throwable
+ {
+ for (String compactOption : new String[] { "", " COMPACT STORAGE AND"
})
+ {
+ // non-compound, ASC order
+ createTable("CREATE TABLE %s (a text, b int, PRIMARY KEY (a, b))
WITH" +
+ compactOption +
+ " CLUSTERING ORDER BY (b ASC)");
+
+ execute("INSERT INTO %s (a, b) VALUES ('a', 2)");
+ execute("INSERT INTO %s (a, b) VALUES ('a', 3)");
+ assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0"),
+ row("a", 2),
+ row("a", 3));
+
+ assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0
ORDER BY b DESC"),
+ row("a", 3),
+ row("a", 2));
+
+ // non-compound, DESC order
+ createTable("CREATE TABLE %s (a text, b int, PRIMARY KEY (a, b))
WITH" +
+ compactOption +
+ " CLUSTERING ORDER BY (b DESC)");
+
+ execute("INSERT INTO %s (a, b) VALUES ('a', 2)");
+ execute("INSERT INTO %s (a, b) VALUES ('a', 3)");
+ assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0"),
+ row("a", 3),
+ row("a", 2));
+
+ assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0
ORDER BY b ASC"),
+ row("a", 2),
+ row("a", 3));
+
+ // compound, first column DESC order
+ createTable("CREATE TABLE %s (a text, b int, c int, PRIMARY KEY
(a, b, c)) WITH" +
+ compactOption +
+ " CLUSTERING ORDER BY (b DESC)"
+ );
+
+ execute("INSERT INTO %s (a, b, c) VALUES ('a', 2, 4)");
+ execute("INSERT INTO %s (a, b, c) VALUES ('a', 3, 5)");
+ assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0"),
+ row("a", 3, 5),
+ row("a", 2, 4));
+
+ assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0
ORDER BY b ASC"),
+ row("a", 2, 4),
+ row("a", 3, 5));
+
+ // compound, mixed order
+ createTable("CREATE TABLE %s (a text, b int, c int, PRIMARY KEY
(a, b, c)) WITH" +
+ compactOption +
+ " CLUSTERING ORDER BY (b ASC, c DESC)"
+ );
+
+ execute("INSERT INTO %s (a, b, c) VALUES ('a', 2, 4)");
+ execute("INSERT INTO %s (a, b, c) VALUES ('a', 3, 5)");
+ assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0"),
+ row("a", 2, 4),
+ row("a", 3, 5));
+
+ assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0
ORDER BY b ASC"),
+ row("a", 2, 4),
+ row("a", 3, 5));
+ }
+ }
+
+ @Test
public void testOverlyLargeSelectPK() throws Throwable
{
createTable("CREATE TABLE %s (a text, b text, PRIMARY KEY ((a), b))");
@@@ -2339,4 -1330,375 +2342,367 @@@
row(1, 2, 3),
row(1, 1, 3));
}
+
+ @Test
+ public void testEmptyRestrictionValue() throws Throwable
+ {
+ for (String options : new String[] { "", " WITH COMPACT STORAGE" })
+ {
+ createTable("CREATE TABLE %s (pk blob, c blob, v blob, PRIMARY
KEY ((pk), c))" + options);
+ execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
+ bytes("foo123"), bytes("1"), bytes("1"));
+ execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
+ bytes("foo123"), bytes("2"), bytes("2"));
+
+ for (boolean flush : new boolean[]{false, true})
+ {
+ if (flush)
+ flush();
+
+ assertInvalidMessage("Key may not be empty", "SELECT * FROM
%s WHERE pk = textAsBlob('');");
+ assertInvalidMessage("Key may not be empty", "SELECT * FROM
%s WHERE pk IN (textAsBlob(''), textAsBlob('1'));");
+
+ assertInvalidMessage("Key may not be empty",
+ "INSERT INTO %s (pk, c, v) VALUES (?, ?,
?)",
+ EMPTY_BYTE_BUFFER, bytes("2"),
bytes("2"));
+
+ // Test clustering columns restrictions
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c = textAsBlob('');"));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c) = (textAsBlob(''));"));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c IN (textAsBlob(''), textAsBlob('1'));"),
+ row(bytes("foo123"), bytes("1"), bytes("1")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c) IN ((textAsBlob('')), (textAsBlob('1')));"),
+ row(bytes("foo123"), bytes("1"), bytes("1")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c > textAsBlob('');"),
+ row(bytes("foo123"), bytes("1"), bytes("1")),
+ row(bytes("foo123"), bytes("2"), bytes("2")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c) > (textAsBlob(''));"),
+ row(bytes("foo123"), bytes("1"), bytes("1")),
+ row(bytes("foo123"), bytes("2"), bytes("2")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c >= textAsBlob('');"),
+ row(bytes("foo123"), bytes("1"), bytes("1")),
+ row(bytes("foo123"), bytes("2"), bytes("2")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c) >= (textAsBlob(''));"),
+ row(bytes("foo123"), bytes("1"), bytes("1")),
+ row(bytes("foo123"), bytes("2"), bytes("2")));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c <= textAsBlob('');"));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c) <= (textAsBlob(''));"));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c < textAsBlob('');"));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c) < (textAsBlob(''));"));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c > textAsBlob('') AND c < textAsBlob('');"));
+ }
+
+ if (options.contains("COMPACT"))
+ {
+ assertInvalidMessage("Missing PRIMARY KEY part c",
+ "INSERT INTO %s (pk, c, v) VALUES (?, ?,
?)",
+ bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("4"));
-
- // Test restrictions on non-primary key value
- assertInvalidMessage("Predicates on the non-primary-key
column (v) of a COMPACT table are not yet supported",
- "SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND v = textAsBlob('') ALLOW FILTERING;");
+ }
+ else
+ {
+ execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
+ bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4"));
+
+ for (boolean flush : new boolean[]{false, true})
+ {
+ if (flush)
+ flush();
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c = textAsBlob('');"),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("4")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c) = (textAsBlob(''));"),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("4")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c IN (textAsBlob(''), textAsBlob('1'));"),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("4")),
+ row(bytes("foo123"), bytes("1"), bytes("1")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c) IN ((textAsBlob('')), (textAsBlob('1')));"),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("4")),
+ row(bytes("foo123"), bytes("1"), bytes("1")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c > textAsBlob('');"),
+ row(bytes("foo123"), bytes("1"), bytes("1")),
+ row(bytes("foo123"), bytes("2"), bytes("2")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c) > (textAsBlob(''));"),
+ row(bytes("foo123"), bytes("1"), bytes("1")),
+ row(bytes("foo123"), bytes("2"), bytes("2")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c >= textAsBlob('');"),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("4")),
+ row(bytes("foo123"), bytes("1"), bytes("1")),
+ row(bytes("foo123"), bytes("2"), bytes("2")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c) >= (textAsBlob(''));"),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("4")),
+ row(bytes("foo123"), bytes("1"), bytes("1")),
+ row(bytes("foo123"), bytes("2"), bytes("2")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c <= textAsBlob('');"),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("4")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c) <= (textAsBlob(''));"),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("4")));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c < textAsBlob('');"));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c) < (textAsBlob(''));"));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c >= textAsBlob('') AND c < textAsBlob('');"));
-
- // Test restrictions on non-primary key value
- assertInvalidMessage("No secondary indexes on the
restricted columns support the provided operators",
- "SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND v = textAsBlob('') ALLOW FILTERING;");
+ }
+ }
++
++ // Test restrictions on non-primary key value
++ assertInvalidMessage("Predicates on non-primary-key columns (v)
are not yet supported for non secondary index queries",
++ "SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND v = textAsBlob('') ALLOW FILTERING;");
+ }
+ }
+
+ @Test
+ public void testEmptyRestrictionValueWithMultipleClusteringColumns()
throws Throwable
+ {
+ for (String options : new String[] { "", " WITH COMPACT STORAGE" })
+ {
+ createTable("CREATE TABLE %s (pk blob, c1 blob, c2 blob, v blob,
PRIMARY KEY (pk, c1, c2))" + options);
+ execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)",
bytes("foo123"), bytes("1"), bytes("1"), bytes("1"));
+ execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)",
bytes("foo123"), bytes("1"), bytes("2"), bytes("2"));
+
+ for (boolean flush : new boolean[]{false, true})
+ {
+ if (flush)
+ flush();
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('');"));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 = textAsBlob('');"));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c1, c2) = (textAsBlob('1'), textAsBlob(''));"));
+
- assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 IN (textAsBlob(''),
textAsBlob('1'));"),
++ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 IN (textAsBlob(''), textAsBlob('1')) AND c2 =
textAsBlob('1');"),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")));
+
- assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('') AND c2 = textAsBlob('1');"));
++ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 IN (textAsBlob(''),
textAsBlob('1'));"),
++ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c1, c2) IN ((textAsBlob(''), textAsBlob('1')),
(textAsBlob('1'), textAsBlob('1')));"),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 > textAsBlob('');"),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")),
+ row(bytes("foo123"), bytes("1"), bytes("2"),
bytes("2")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 > textAsBlob('');"),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")),
+ row(bytes("foo123"), bytes("1"), bytes("2"),
bytes("2")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c1, c2) > (textAsBlob(''), textAsBlob('1'));"),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")),
+ row(bytes("foo123"), bytes("1"), bytes("2"),
bytes("2")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 >= textAsBlob('');"),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")),
+ row(bytes("foo123"), bytes("1"), bytes("2"),
bytes("2")));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 <= textAsBlob('');"));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c1, c2) <= (textAsBlob('1'), textAsBlob(''));"));
+ }
+
+ execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)",
+ bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"),
bytes("4"));
+
+ for (boolean flush : new boolean[]{false, true})
+ {
+ if (flush)
+ flush();
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('');"),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("1"), bytes("4")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('') AND c2 = textAsBlob('1');"),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("1"), bytes("4")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c1, c2) = (textAsBlob(''), textAsBlob('1'));"),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("1"), bytes("4")));
+
- assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('') AND c2 IN (textAsBlob(''),
textAsBlob('1'));"),
- row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("1"), bytes("4")));
-
- assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 IN (textAsBlob(''),
textAsBlob('1'));"),
++ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 IN (textAsBlob(''), textAsBlob('1')) AND c2 =
textAsBlob('1');"),
++ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("1"), bytes("4")),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c1, c2) IN ((textAsBlob(''), textAsBlob('1')),
(textAsBlob('1'), textAsBlob('1')));"),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("1"), bytes("4")),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c1, c2) > (textAsBlob(''), textAsBlob('1'));"),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")),
+ row(bytes("foo123"), bytes("1"), bytes("2"),
bytes("2")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c1, c2) >= (textAsBlob(''), textAsBlob('1'));"),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("1"), bytes("4")),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")),
+ row(bytes("foo123"), bytes("1"), bytes("2"),
bytes("2")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c1, c2) <= (textAsBlob(''), textAsBlob('1'));"),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("1"), bytes("4")));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c1, c2) < (textAsBlob(''), textAsBlob('1'));"));
+ }
+ }
+ }
+
+ @Test
+ public void testEmptyRestrictionValueWithOrderBy() throws Throwable
+ {
+ for (String options : new String[] { "",
+ " WITH COMPACT STORAGE",
+ " WITH CLUSTERING ORDER BY (c
DESC)",
+ " WITH COMPACT STORAGE AND
CLUSTERING ORDER BY (c DESC)"})
+ {
+ String orderingClause = options.contains("ORDER") ? "" : "ORDER
BY c DESC" ;
+
+ createTable("CREATE TABLE %s (pk blob, c blob, v blob, PRIMARY
KEY ((pk), c))" + options);
+ execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
+ bytes("foo123"),
+ bytes("1"),
+ bytes("1"));
+ execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
+ bytes("foo123"),
+ bytes("2"),
+ bytes("2"));
+
+ for (boolean flush : new boolean[]{false, true})
+ {
+ if (flush)
+ flush();
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c > textAsBlob('')" + orderingClause),
+ row(bytes("foo123"), bytes("2"), bytes("2")),
+ row(bytes("foo123"), bytes("1"), bytes("1")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c >= textAsBlob('')" + orderingClause),
+ row(bytes("foo123"), bytes("2"), bytes("2")),
+ row(bytes("foo123"), bytes("1"), bytes("1")));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c < textAsBlob('')" + orderingClause));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c <= textAsBlob('')" + orderingClause));
-
+ }
+
+ if (options.contains("COMPACT"))
+ {
+ assertInvalidMessage("Missing PRIMARY KEY part c",
+ "INSERT INTO %s (pk, c, v) VALUES (?, ?,
?)",
+ bytes("foo123"),
+ EMPTY_BYTE_BUFFER,
+ bytes("4"));
+ }
+ else
+ {
+ execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
+ bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4"));
+
+ for (boolean flush : new boolean[]{false, true})
+ {
+ if (flush)
+ flush();
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c IN (textAsBlob(''), textAsBlob('1'))" +
orderingClause),
+ row(bytes("foo123"), bytes("1"), bytes("1")),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("4")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c > textAsBlob('')" + orderingClause),
+ row(bytes("foo123"), bytes("2"), bytes("2")),
+ row(bytes("foo123"), bytes("1"), bytes("1")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c >= textAsBlob('')" + orderingClause),
+ row(bytes("foo123"), bytes("2"), bytes("2")),
+ row(bytes("foo123"), bytes("1"), bytes("1")),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("4")));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c < textAsBlob('')" + orderingClause));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c <= textAsBlob('')" + orderingClause),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("4")));
+ }
+ }
+ }
+ }
+
+ @Test
+ public void
testEmptyRestrictionValueWithMultipleClusteringColumnsAndOrderBy() throws
Throwable
+ {
+ for (String options : new String[] { "",
+ " WITH COMPACT STORAGE",
+ " WITH CLUSTERING ORDER BY (c1 DESC, c2 DESC)",
+ " WITH COMPACT STORAGE AND CLUSTERING ORDER BY (c1 DESC, c2
DESC)"})
+ {
+ String orderingClause = options.contains("ORDER") ? "" : "ORDER
BY c1 DESC, c2 DESC" ;
+
+ createTable("CREATE TABLE %s (pk blob, c1 blob, c2 blob, v blob,
PRIMARY KEY (pk, c1, c2))" + options);
+ execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)",
bytes("foo123"), bytes("1"), bytes("1"), bytes("1"));
+ execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)",
bytes("foo123"), bytes("1"), bytes("2"), bytes("2"));
+
+ for (boolean flush : new boolean[]{false, true})
+ {
+ if (flush)
+ flush();
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 > textAsBlob('')" + orderingClause),
+ row(bytes("foo123"), bytes("1"), bytes("2"),
bytes("2")),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 > textAsBlob('')" +
orderingClause),
+ row(bytes("foo123"), bytes("1"), bytes("2"),
bytes("2")),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c1, c2) > (textAsBlob(''), textAsBlob('1'))" +
orderingClause),
+ row(bytes("foo123"), bytes("1"), bytes("2"),
bytes("2")),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 >= textAsBlob('')" +
orderingClause),
+ row(bytes("foo123"), bytes("1"), bytes("2"),
bytes("2")),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")));
+ }
+
+ execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)",
+ bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"),
bytes("4"));
+
+ for (boolean flush : new boolean[]{false, true})
+ {
+ if (flush)
+ flush();
+
- assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 IN (textAsBlob(''),
textAsBlob('1'))" + orderingClause),
- row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")));
-
- assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 = textAsBlob('') AND c2 IN (textAsBlob(''),
textAsBlob('1'))" + orderingClause),
++ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND c1 IN (textAsBlob(''), textAsBlob('1')) AND c2 =
textAsBlob('1')" + orderingClause),
++ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("1"), bytes("4")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c1, c2) IN ((textAsBlob(''), textAsBlob('1')),
(textAsBlob('1'), textAsBlob('1')))" + orderingClause),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("1"), bytes("4")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c1, c2) > (textAsBlob(''), textAsBlob('1'))" +
orderingClause),
+ row(bytes("foo123"), bytes("1"), bytes("2"),
bytes("2")),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")));
+
+ assertRows(execute("SELECT * FROM %s WHERE pk =
textAsBlob('foo123') AND (c1, c2) >= (textAsBlob(''), textAsBlob('1'))" +
orderingClause),
+ row(bytes("foo123"), bytes("1"), bytes("2"),
bytes("2")),
+ row(bytes("foo123"), bytes("1"), bytes("1"),
bytes("1")),
+ row(bytes("foo123"), EMPTY_BYTE_BUFFER,
bytes("1"), bytes("4")));
+ }
+ }
+ }
}