You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ty...@apache.org on 2014/11/19 18:29:24 UTC
[1/4] cassandra git commit: Fix multicolumn relation + COMPACT
STORAGE issues
Repository: cassandra
Updated Branches:
refs/heads/cassandra-2.1 289314a60 -> 25a4c9e1f
http://git-wip-us.apache.org/repos/asf/cassandra/blob/084d93da/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java b/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
index 498d332..ea4f1a6 100644
--- a/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
@@ -57,11 +57,25 @@ public class MultiColumnRelationTest
{
SchemaLoader.loadSchema();
executeSchemaChange("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}");
- executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.single_partition (a int PRIMARY KEY, b int)");
- executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.compound_partition (a int, b int, c int, PRIMARY KEY ((a, b)))");
- executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.single_clustering (a int, b int, c int, PRIMARY KEY (a, b))");
- executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.multiple_clustering (a int, b int, c int, d int, PRIMARY KEY (a, b, c, d))");
- executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.multiple_clustering_reversed (a int, b int, c int, d int, PRIMARY KEY (a, b, c, d)) WITH CLUSTERING ORDER BY (b DESC, c ASC, d DESC)");
+ for (boolean isCompact : new boolean[]{false, true})
+ {
+ String tableSuffix = isCompact ? "_compact" : "";
+ String compactOption = isCompact ? " WITH COMPACT STORAGE" : "";
+
+ executeSchemaChange(
+ "CREATE TABLE IF NOT EXISTS %s.single_partition" + tableSuffix + "(a int PRIMARY KEY, b int)" + compactOption);
+ executeSchemaChange(
+ "CREATE TABLE IF NOT EXISTS %s.compound_partition" +tableSuffix + "(a int, b int, c int, PRIMARY KEY ((a, b)))" + compactOption);
+ executeSchemaChange(
+ "CREATE TABLE IF NOT EXISTS %s.single_clustering" + tableSuffix + "(a int, b int, c int, PRIMARY KEY (a, b))" + compactOption);
+ executeSchemaChange(
+ "CREATE TABLE IF NOT EXISTS %s.multiple_clustering" + tableSuffix + "(a int, b int, c int, d int, PRIMARY KEY (a, b, c, d))" + compactOption);
+
+ compactOption = isCompact ? " COMPACT STORAGE AND " : "";
+ executeSchemaChange(
+ "CREATE TABLE IF NOT EXISTS %s.multiple_clustering_reversed" + tableSuffix +
+ "(a int, b int, c int, d int, PRIMARY KEY (a, b, c, d)) WITH " + compactOption + " CLUSTERING ORDER BY (b DESC, c ASC, d DESC)");
+ }
clientState = ClientState.forInternalCalls();
}
@@ -207,40 +221,46 @@ public class MultiColumnRelationTest
@Test
public void testSingleClusteringColumnEquality() throws Throwable
{
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 0, 0)");
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 1, 0)");
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 2, 0)");
- UntypedResultSet results = execute("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) = (1)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) = (3)");
- assertEquals(0, results.size());
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + "(a, b, c) VALUES (0, 0, 0)");
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 1, 0)");
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 2, 0)");
+ UntypedResultSet results = execute("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) = (1)");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 0);
+
+ results = execute("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) = (3)");
+ assertEquals(0, results.size());
+ }
}
@Test
public void testMultipleClusteringColumnEquality() throws Throwable
{
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 1, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 1, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 1, 1, 1)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 2, 0, 0)");
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b) = (1)");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(2, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c) = (1, 1)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 1, 0);
- checkRow(1, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) = (1, 1, 1)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 1, 1);
- execute("DELETE FROM %s.multiple_clustering WHERE a=0 AND b=2 and c=0 and d=0");
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 1)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 2, 0, 0)");
+ UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) = (1)");
+ assertEquals(3, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 1, 1, 0);
+ checkRow(2, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) = (1, 1)");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 1, 1, 0);
+ checkRow(1, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) = (1, 1, 1)");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 1, 1);
+ execute("DELETE FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND b=2 and c=0 and d=0");
+ }
}
@Test(expected=InvalidRequestException.class)
@@ -270,372 +290,392 @@ public class MultiColumnRelationTest
@Test
public void testMixSingleAndTupleInequalities() throws Throwable
{
- String[] queries = new String[]{
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (0, 1, 0) AND b < 1",
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (0, 1, 0) AND c < 1",
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND b > 1 AND (b, c, d) < (1, 1, 0)",
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND c > 1 AND (b, c, d) < (1, 1, 0)",
- };
-
- for (String query : queries)
+ for (String tableSuffix : new String[]{"", "_compact"})
{
- try
+ String[] queries = new String[]{
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 0) AND b < 1",
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 0) AND c < 1",
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND b > 1 AND (b, c, d) < (1, 1, 0)",
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND c > 1 AND (b, c, d) < (1, 1, 0)",
+ };
+
+ for (String query : queries)
{
- execute(query);
- fail(String.format("Expected query \"%s\" to throw an InvalidRequestException", query));
+ try
+ {
+ execute(query);
+ fail(String.format("Expected query \"%s\" to throw an InvalidRequestException", query));
+ }
+ catch (InvalidRequestException e)
+ {
+ }
}
- catch (InvalidRequestException e) {}
}
}
@Test
public void testSingleClusteringColumnInequality() throws Throwable
{
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 0, 0)");
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 1, 0)");
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 2, 0)");
-
- UntypedResultSet results = execute("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) > (0)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0);
- checkRow(1, results, 0, 2, 0);
-
- results = execute("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) >= (1)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0);
- checkRow(1, results, 0, 2, 0);
-
- results = execute("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) < (2)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 0);
- checkRow(1, results, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) <= (1)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 0);
- checkRow(1, results, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) > (0) AND (b) < (2)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0);
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 0, 0)");
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 1, 0)");
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 2, 0)");
+
+ UntypedResultSet results = execute("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) > (0)");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 1, 0);
+ checkRow(1, results, 0, 2, 0);
+
+ results = execute("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) >= (1)");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 1, 0);
+ checkRow(1, results, 0, 2, 0);
+
+ results = execute("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) < (2)");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 0);
+ checkRow(1, results, 0, 1, 0);
+
+ results = execute("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) <= (1)");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 0);
+ checkRow(1, results, 0, 1, 0);
+
+ results = execute("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) > (0) AND (b) < (2)");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 0);
+ }
}
@Test
public void testMultipleClusteringColumnInequality() throws Throwable
{
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 1)");
-
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 1, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 1, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 1, 1, 1)");
-
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b) > (0)");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(2, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b) >= (0)");
- assertEquals(6, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
- checkRow(3, results, 0, 1, 0, 0);
- checkRow(4, results, 0, 1, 1, 0);
- checkRow(5, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c) > (1, 0)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 1, 0);
- checkRow(1, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c) >= (1, 0)");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(2, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (1, 1, 0)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) >= (1, 1, 0)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 1, 0);
- checkRow(1, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b) < (1)");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b) <= (1)");
- assertEquals(6, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
- checkRow(3, results, 0, 1, 0, 0);
- checkRow(4, results, 0, 1, 1, 0);
- checkRow(5, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c) < (0, 1)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c) <= (0, 1)");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) < (0, 1, 1)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) <= (0, 1, 1)");
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (0, 1, 0) AND (b) < (1)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (0, 1, 1) AND (b, c) < (1, 1)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (0, 1, 1) AND (b, c, d) < (1, 1, 0)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- // reversed
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b) > (0) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(3, results.size());
- checkRow(2, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b) >= (0) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(6, results.size());
- checkRow(5, results, 0, 0, 0, 0);
- checkRow(4, results, 0, 0, 1, 0);
- checkRow(3, results, 0, 0, 1, 1);
- checkRow(2, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c) > (1, 0) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(2, results.size());
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c) >= (1, 0) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(3, results.size());
- checkRow(2, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (1, 1, 0) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) >= (1, 1, 0) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(2, results.size());
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b) < (1) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(3, results.size());
- checkRow(2, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(0, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b) <= (1) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(6, results.size());
- checkRow(5, results, 0, 0, 0, 0);
- checkRow(4, results, 0, 0, 1, 0);
- checkRow(3, results, 0, 0, 1, 1);
- checkRow(2, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c) < (0, 1) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c) <= (0, 1) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(3, results.size());
- checkRow(2, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(0, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) < (0, 1, 1) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(2, results.size());
- checkRow(1, results, 0, 0, 0, 0);
- checkRow(0, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) <= (0, 1, 1) ORDER BY b DESC, c DESC, d DESC");
- checkRow(2, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(0, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (0, 1, 0) AND (b) < (1) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (0, 1, 1) AND (b, c) < (1, 1) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (0, 1, 1) AND (b, c, d) < (1, 1, 0) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
+
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 1)");
+
+ UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) > (0)");
+ assertEquals(3, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 1, 1, 0);
+ checkRow(2, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) >= (0)");
+ assertEquals(6, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 0);
+ checkRow(2, results, 0, 0, 1, 1);
+ checkRow(3, results, 0, 1, 0, 0);
+ checkRow(4, results, 0, 1, 1, 0);
+ checkRow(5, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) > (1, 0)");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 1, 1, 0);
+ checkRow(1, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) >= (1, 0)");
+ assertEquals(3, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 1, 1, 0);
+ checkRow(2, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (1, 1, 0)");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) >= (1, 1, 0)");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 1, 1, 0);
+ checkRow(1, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) < (1)");
+ assertEquals(3, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 0);
+ checkRow(2, results, 0, 0, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) <= (1)");
+ assertEquals(6, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 0);
+ checkRow(2, results, 0, 0, 1, 1);
+ checkRow(3, results, 0, 1, 0, 0);
+ checkRow(4, results, 0, 1, 1, 0);
+ checkRow(5, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) < (0, 1)");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) <= (0, 1)");
+ assertEquals(3, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 0);
+ checkRow(2, results, 0, 0, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) < (0, 1, 1)");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) <= (0, 1, 1)");
+ checkRow(0, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 0);
+ checkRow(2, results, 0, 0, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 0) AND (b) < (1)");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 0, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 1) AND (b, c) < (1, 1)");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 1) AND (b, c, d) < (1, 1, 0)");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+
+ // reversed
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) > (0) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(3, results.size());
+ checkRow(2, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 1, 1, 0);
+ checkRow(0, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) >= (0) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(6, results.size());
+ checkRow(5, results, 0, 0, 0, 0);
+ checkRow(4, results, 0, 0, 1, 0);
+ checkRow(3, results, 0, 0, 1, 1);
+ checkRow(2, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 1, 1, 0);
+ checkRow(0, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) > (1, 0) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(2, results.size());
+ checkRow(1, results, 0, 1, 1, 0);
+ checkRow(0, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) >= (1, 0) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(3, results.size());
+ checkRow(2, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 1, 1, 0);
+ checkRow(0, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (1, 1, 0) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) >= (1, 1, 0) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(2, results.size());
+ checkRow(1, results, 0, 1, 1, 0);
+ checkRow(0, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) < (1) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(3, results.size());
+ checkRow(2, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 0);
+ checkRow(0, results, 0, 0, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) <= (1) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(6, results.size());
+ checkRow(5, results, 0, 0, 0, 0);
+ checkRow(4, results, 0, 0, 1, 0);
+ checkRow(3, results, 0, 0, 1, 1);
+ checkRow(2, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 1, 1, 0);
+ checkRow(0, results, 0, 1, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) < (0, 1) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) <= (0, 1) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(3, results.size());
+ checkRow(2, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 0);
+ checkRow(0, results, 0, 0, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) < (0, 1, 1) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(2, results.size());
+ checkRow(1, results, 0, 0, 0, 0);
+ checkRow(0, results, 0, 0, 1, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) <= (0, 1, 1) ORDER BY b DESC, c DESC, d DESC");
+ checkRow(2, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 0);
+ checkRow(0, results, 0, 0, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 0) AND (b) < (1) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 0, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 1) AND (b, c) < (1, 1) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 1) AND (b, c, d) < (1, 1, 0) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+ }
}
@Test
public void testMultipleClusteringColumnInequalityReversedComponents() throws Throwable
{
- // b and d are reversed in the clustering order
- execute("INSERT INTO %s.multiple_clustering_reversed (a, b, c, d) VALUES (0, 1, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering_reversed (a, b, c, d) VALUES (0, 1, 1, 1)");
- execute("INSERT INTO %s.multiple_clustering_reversed (a, b, c, d) VALUES (0, 1, 1, 0)");
-
- execute("INSERT INTO %s.multiple_clustering_reversed (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering_reversed (a, b, c, d) VALUES (0, 0, 1, 1)");
- execute("INSERT INTO %s.multiple_clustering_reversed (a, b, c, d) VALUES (0, 0, 1, 0)");
-
-
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering_reversed WHERE a=0 AND (b) > (0)");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 1);
- checkRow(2, results, 0, 1, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed WHERE a=0 AND (b) >= (0)");
- assertEquals(6, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 1);
- checkRow(2, results, 0, 1, 1, 0);
- checkRow(3, results, 0, 0, 0, 0);
- checkRow(4, results, 0, 0, 1, 1);
- checkRow(5, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed WHERE a=0 AND (b) < (1)");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 1);
- checkRow(2, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed WHERE a=0 AND (b) <= (1)");
- assertEquals(6, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 1);
- checkRow(2, results, 0, 1, 1, 0);
- checkRow(3, results, 0, 0, 0, 0);
- checkRow(4, results, 0, 0, 1, 1);
- checkRow(5, results, 0, 0, 1, 0);
-
- // preserve pre-6875 behavior (even though the query result is technically incorrect)
- results = execute("SELECT * FROM %s.multiple_clustering_reversed WHERE a=0 AND (b, c) > (1, 0)");
- assertEquals(0, results.size());
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ // b and d are reversed in the clustering order
+ execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 1)");
+ execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 0)");
+
+ execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
+ execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
+
+
+ UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b) > (0)");
+ assertEquals(3, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 1, 1, 1);
+ checkRow(2, results, 0, 1, 1, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b) >= (0)");
+ assertEquals(6, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 1, 1, 1);
+ checkRow(2, results, 0, 1, 1, 0);
+ checkRow(3, results, 0, 0, 0, 0);
+ checkRow(4, results, 0, 0, 1, 1);
+ checkRow(5, results, 0, 0, 1, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b) < (1)");
+ assertEquals(3, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+ checkRow(2, results, 0, 0, 1, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b) <= (1)");
+ assertEquals(6, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 1, 1, 1);
+ checkRow(2, results, 0, 1, 1, 0);
+ checkRow(3, results, 0, 0, 0, 0);
+ checkRow(4, results, 0, 0, 1, 1);
+ checkRow(5, results, 0, 0, 1, 0);
+
+ // preserve pre-6875 behavior (even though the query result is technically incorrect)
+ results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b, c) > (1, 0)");
+ assertEquals(0, results.size());
+ }
}
@Test
public void testLiteralIn() throws Throwable
{
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 1)");
-
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN ((0, 1, 0), (0, 1, 1))");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
- // same query, but reversed order for the IN values
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN ((0, 1, 1), (0, 1, 0))");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 and (b, c) IN ((0, 1))");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 and (b) IN ((0))");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c) IN ((0, 1)) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 1);
- checkRow(1, results, 0, 0, 1, 0);
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
+
+ UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((0, 1, 0), (0, 1, 1))");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+
+ // same query, but reversed order for the IN values
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((0, 1, 1), (0, 1, 0))");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 and (b, c) IN ((0, 1))");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 and (b) IN ((0))");
+ assertEquals(3, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 0);
+ checkRow(2, results, 0, 0, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) IN ((0, 1)) ORDER BY b DESC, c DESC, d DESC");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 1);
+ checkRow(1, results, 0, 0, 1, 0);
+ }
}
@Test
public void testLiteralInReversed() throws Throwable
{
- execute("INSERT INTO %s.multiple_clustering_reversed (a, b, c, d) VALUES (0, 1, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering_reversed (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering_reversed (a, b, c, d) VALUES (0, 0, 1, 1)");
- execute("INSERT INTO %s.multiple_clustering_reversed (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering_reversed (a, b, c, d) VALUES (0, -1, 0, 0)");
-
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering_reversed WHERE a=0 AND (b, c, d) IN ((0, 1, 0), (0, 1, 1))");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 1);
- checkRow(1, results, 0, 0, 1, 0);
-
- // same query, but reversed order for the IN values
- results = execute("SELECT * FROM %s.multiple_clustering_reversed WHERE a=0 AND (b, c, d) IN ((0, 1, 1), (0, 1, 0))");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 1);
- checkRow(1, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed WHERE a=0 AND (b, c, d) IN ((1, 0, 0), (0, 0, 0), (0, 1, 1), (0, 1, 0), (-1, 0, 0))");
- assertEquals(5, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 0, 0, 0);
- checkRow(2, results, 0, 0, 1, 1);
- checkRow(3, results, 0, 0, 1, 0);
- checkRow(4, results, 0, -1, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed WHERE a=0 AND (b, c, d) IN ((0, 0, 0))");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed WHERE a=0 AND (b, c, d) IN ((0, 1, 1))");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed WHERE a=0 AND (b, c, d) IN ((0, 1, 0))");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed WHERE a=0 and (b, c) IN ((0, 1))");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 1);
- checkRow(1, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed WHERE a=0 and (b, c) IN ((0, 0))");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed WHERE a=0 and (b) IN ((0))");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 1);
- checkRow(2, results, 0, 0, 1, 0);
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
+ execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
+ execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, -1, 0, 0)");
+
+ UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((0, 1, 0), (0, 1, 1))");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 1);
+ checkRow(1, results, 0, 0, 1, 0);
+
+ // same query, but reversed order for the IN values
+ results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((0, 1, 1), (0, 1, 0))");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 1);
+ checkRow(1, results, 0, 0, 1, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((1, 0, 0), (0, 0, 0), (0, 1, 1), (0, 1, 0), (-1, 0, 0))");
+ assertEquals(5, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 0, 0, 0);
+ checkRow(2, results, 0, 0, 1, 1);
+ checkRow(3, results, 0, 0, 1, 0);
+ checkRow(4, results, 0, -1, 0, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((0, 0, 0))");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((0, 1, 1))");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 0, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((0, 1, 0))");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 and (b, c) IN ((0, 1))");
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 1);
+ checkRow(1, results, 0, 0, 1, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 and (b, c) IN ((0, 0))");
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+
+ results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 and (b) IN ((0))");
+ assertEquals(3, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+ checkRow(2, results, 0, 0, 1, 0);
+ }
}
@Test(expected=InvalidRequestException.class)
@@ -664,44 +704,47 @@ public class MultiColumnRelationTest
@Test
public void testPartitionAndClusteringInClauses() throws Throwable
{
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 1)");
-
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (1, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (1, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (1, 0, 1, 1)");
-
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering WHERE a IN (0, 1) AND (b, c, d) IN ((0, 1, 0), (0, 1, 1))");
- assertEquals(4, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
- checkRow(2, results, 1, 0, 1, 0);
- checkRow(3, results, 1, 0, 1, 1);
-
- // same query, but reversed order for the IN values
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a IN (1, 0) AND (b, c, d) IN ((0, 1, 1), (0, 1, 0))");
- assertEquals(4, results.size());
- checkRow(0, results, 1, 0, 1, 0);
- checkRow(1, results, 1, 0, 1, 1);
- checkRow(2, results, 0, 0, 1, 0);
- checkRow(3, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a IN (0, 1) and (b, c) IN ((0, 1))");
- assertEquals(4, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
- checkRow(2, results, 1, 0, 1, 0);
- checkRow(3, results, 1, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering WHERE a IN (0, 1) and (b) IN ((0))");
- assertEquals(6, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
- checkRow(3, results, 1, 0, 0, 0);
- checkRow(4, results, 1, 0, 1, 0);
- checkRow(5, results, 1, 0, 1, 1);
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
+
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (1, 0, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (1, 0, 1, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (1, 0, 1, 1)");
+
+ UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a IN (0, 1) AND (b, c, d) IN ((0, 1, 0), (0, 1, 1))");
+ assertEquals(4, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+ checkRow(2, results, 1, 0, 1, 0);
+ checkRow(3, results, 1, 0, 1, 1);
+
+ // same query, but reversed order for the IN values
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a IN (1, 0) AND (b, c, d) IN ((0, 1, 1), (0, 1, 0))");
+ assertEquals(4, results.size());
+ checkRow(0, results, 1, 0, 1, 0);
+ checkRow(1, results, 1, 0, 1, 1);
+ checkRow(2, results, 0, 0, 1, 0);
+ checkRow(3, results, 0, 0, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a IN (0, 1) and (b, c) IN ((0, 1))");
+ assertEquals(4, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+ checkRow(2, results, 1, 0, 1, 0);
+ checkRow(3, results, 1, 0, 1, 1);
+
+ results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a IN (0, 1) and (b) IN ((0))");
+ assertEquals(6, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 0);
+ checkRow(2, results, 0, 0, 1, 1);
+ checkRow(3, results, 1, 0, 0, 0);
+ checkRow(4, results, 1, 0, 1, 0);
+ checkRow(5, results, 1, 0, 1, 1);
+ }
}
// prepare statement tests
@@ -777,335 +820,362 @@ public class MultiColumnRelationTest
@Test
public void testPreparedClusteringColumnEquality() throws Throwable
{
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 0, 0)");
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 1, 0)");
- MD5Digest id = prepare("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) = (?)");
- UntypedResultSet results = executePrepared(id, makeIntOptions(0));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 0);
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 0, 0)");
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 1, 0)");
+ MD5Digest id = prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) = (?)");
+ UntypedResultSet results = executePrepared(id, makeIntOptions(0));
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 0, 0);
+ }
}
@Test
public void testPreparedClusteringColumnEqualitySingleMarker() throws Throwable
{
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 0, 0)");
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 1, 0)");
- MD5Digest id = prepare("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) = ?");
- UntypedResultSet results = executePrepared(id, options(tuple(0)));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 0);
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 0, 0)");
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 1, 0)");
+ MD5Digest id = prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) = ?");
+ UntypedResultSet results = executePrepared(id, options(tuple(0)));
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 0, 0);
+ }
}
@Test
public void testPreparedSingleClusteringColumnInequality() throws Throwable
{
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 0, 0)");
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 1, 0)");
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 2, 0)");
-
- MD5Digest id = prepare("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) > (?)");
- UntypedResultSet results = executePrepared(id, makeIntOptions(0));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0);
- checkRow(1, results, 0, 2, 0);
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) >= (?)"), makeIntOptions(1));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0);
- checkRow(1, results, 0, 2, 0);
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) < (?)"), makeIntOptions(2));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 0);
- checkRow(1, results, 0, 1, 0);
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) <= (?)"), makeIntOptions(1));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 0);
- checkRow(1, results, 0, 1, 0);
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) > (?) AND (b) < (?)"), makeIntOptions(0, 2));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0);
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 0, 0)");
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 1, 0)");
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 2, 0)");
+
+ MD5Digest id = prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) > (?)");
+ UntypedResultSet results = executePrepared(id, makeIntOptions(0));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 1, 0);
+ checkRow(1, results, 0, 2, 0);
+
+ results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) >= (?)"), makeIntOptions(1));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 1, 0);
+ checkRow(1, results, 0, 2, 0);
+
+ results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) < (?)"), makeIntOptions(2));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 0);
+ checkRow(1, results, 0, 1, 0);
+
+ results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) <= (?)"), makeIntOptions(1));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 0);
+ checkRow(1, results, 0, 1, 0);
+
+ results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) > (?) AND (b) < (?)"), makeIntOptions(0, 2));
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 0);
+ }
}
@Test
public void testPreparedSingleClusteringColumnInequalitySingleMarker() throws Throwable
{
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 0, 0)");
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 1, 0)");
- execute("INSERT INTO %s.single_clustering (a, b, c) VALUES (0, 2, 0)");
-
- MD5Digest id = prepare("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) > ?");
- UntypedResultSet results = executePrepared(id, options(tuple(0)));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0);
- checkRow(1, results, 0, 2, 0);
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) >= ?"), options(tuple(1)));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0);
- checkRow(1, results, 0, 2, 0);
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) < ?"), options(tuple(2)));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 0);
- checkRow(1, results, 0, 1, 0);
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) <= ?"), options(tuple(1)));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 0);
- checkRow(1, results, 0, 1, 0);
-
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) > ? AND (b) < ?"),
- options(tuple(0), tuple(2)));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0);
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 0, 0)");
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 1, 0)");
+ execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 2, 0)");
+
+ MD5Digest id = prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) > ?");
+ UntypedResultSet results = executePrepared(id, options(tuple(0)));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 1, 0);
+ checkRow(1, results, 0, 2, 0);
+
+ results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) >= ?"), options(tuple(1)));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 1, 0);
+ checkRow(1, results, 0, 2, 0);
+
+ results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) < ?"), options(tuple(2)));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 0);
+ checkRow(1, results, 0, 1, 0);
+
+ results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) <= ?"), options(tuple(1)));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 0);
+ checkRow(1, results, 0, 1, 0);
+
+
+ results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) > ? AND (b) < ?"),
+ options(tuple(0), tuple(2)));
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 0);
+ }
}
@Test
public void testPrepareMultipleClusteringColumnInequality() throws Throwable
{
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 1)");
-
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 1, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 1, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 1, 1, 1)");
-
- UntypedResultSet results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b) > (?)"), makeIntOptions(0));
- assertEquals(3, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(2, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c) > (?, ?)"), makeIntOptions(1, 0));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 1, 0);
- checkRow(1, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare
- ("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (?, ?, ?)"), makeIntOptions(1, 1, 0));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (?, ?, ?) AND (b) < (?)"),
- makeIntOptions(0, 1, 0, 1));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 1);
-
- results = executePrepared(prepare
- ("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (?, ?, ?) AND (b, c) < (?, ?)"),
- makeIntOptions(0, 1, 1, 1, 1));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (?, ?, ?) AND (b, c, d) < (?, ?, ?)"),
- makeIntOptions(0, 1, 1, 1, 1, 0));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- // reversed
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b) > (?) ORDER BY b DESC, c DESC, d DESC"),
- makeIntOptions(0));
- assertEquals(3, results.size());
- checkRow(2, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > (?, ?, ?) AND (b, c) < (?, ?) ORDER BY b DESC, c DESC, d DESC"),
- makeIntOptions(0, 1, 1, 1, 1));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
+
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 1)");
+
+ UntypedResultSet results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) > (?)"), makeIntOptions(0));
+ assertEquals(3, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 1, 1, 0);
+ checkRow(2, results, 0, 1, 1, 1);
+
+ results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) > (?, ?)"), makeIntOptions(1, 0));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 1, 1, 0);
+ checkRow(1, results, 0, 1, 1, 1);
+
+ results = executePrepared(prepare
+ ("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (?, ?, ?)"), makeIntOptions(1, 1, 0));
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 1, 1);
+
+ results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (?, ?, ?) AND (b) < (?)"),
+ makeIntOptions(0, 1, 0, 1));
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 0, 1, 1);
+
+ results = executePrepared(prepare
+ ("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (?, ?, ?) AND (b, c) < (?, ?)"),
+ makeIntOptions(0, 1, 1, 1, 1));
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+
+ results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (?, ?, ?) AND (b, c, d) < (?, ?, ?)"),
+ makeIntOptions(0, 1, 1, 1, 1, 0));
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+
+ // reversed
+ results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) > (?) ORDER BY b DESC, c DESC, d DESC"),
+ makeIntOptions(0));
+ assertEquals(3, results.size());
+ checkRow(2, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 1, 1, 0);
+ checkRow(0, results, 0, 1, 1, 1);
+
+ results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (?, ?, ?) AND (b, c) < (?, ?) ORDER BY b DESC, c DESC, d DESC"),
+ makeIntOptions(0, 1, 1, 1, 1));
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+ }
}
@Test
public void testPrepareMultipleClusteringColumnInequalitySingleMarker() throws Throwable
{
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 1)");
-
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 1, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 1, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 1, 1, 1)");
-
- UntypedResultSet results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b) > ?"), options(tuple(0)));
- assertEquals(3, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(2, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c) > ?"), options(tuple(1, 0)));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 1, 0);
- checkRow(1, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare
- ("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > ?"), options(tuple(1, 1, 0)));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > ? AND (b) < ?"),
- options(tuple(0, 1, 0), tuple(1)));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 1);
-
- results = executePrepared(prepare
- ("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > ? AND (b, c) < ?"),
- options(tuple(0, 1, 1), tuple(1, 1)));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > ? AND (b, c, d) < ?"),
- options(tuple(0, 1, 1), tuple(1, 1, 0)));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- // reversed
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b) > ? ORDER BY b DESC, c DESC, d DESC"),
- options(tuple(0)));
- assertEquals(3, results.size());
- checkRow(2, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) > ? AND (b, c) < ? ORDER BY b DESC, c DESC, d DESC"),
- options(tuple(0, 1, 1), tuple(1, 1)));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
+
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 1)");
+
+ UntypedResultSet results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) > ?"), options(tuple(0)));
+ assertEquals(3, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 1, 1, 0);
+ checkRow(2, results, 0, 1, 1, 1);
+
+ results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) > ?"), options(tuple(1, 0)));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 1, 1, 0);
+ checkRow(1, results, 0, 1, 1, 1);
+
+ results = executePrepared(prepare
+ ("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > ?"), options(tuple(1, 1, 0)));
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 1, 1);
+
+ results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > ? AND (b) < ?"),
+ options(tuple(0, 1, 0), tuple(1)));
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 0, 1, 1);
+
+ results = executePrepared(prepare
+ ("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > ? AND (b, c) < ?"),
+ options(tuple(0, 1, 1), tuple(1, 1)));
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+
+ results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > ? AND (b, c, d) < ?"),
+ options(tuple(0, 1, 1), tuple(1, 1, 0)));
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+
+ // reversed
+ results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) > ? ORDER BY b DESC, c DESC, d DESC"),
+ options(tuple(0)));
+ assertEquals(3, results.size());
+ checkRow(2, results, 0, 1, 0, 0);
+ checkRow(1, results, 0, 1, 1, 0);
+ checkRow(0, results, 0, 1, 1, 1);
+
+ results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > ? AND (b, c) < ? ORDER BY b DESC, c DESC, d DESC"),
+ options(tuple(0, 1, 1), tuple(1, 1)));
+ assertEquals(1, results.size());
+ checkRow(0, results, 0, 1, 0, 0);
+ }
}
@Test
public void testPrepareLiteralIn() throws Throwable
{
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 1)");
-
- UntypedResultSet results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN ((?, ?, ?), (?, ?, ?))"),
- makeIntOptions(0, 1, 0, 0, 1, 1));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
- // same query, but reversed order for the IN values
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN ((?, ?, ?), (?, ?, ?))"),
- makeIntOptions(0, 1, 1, 0, 1, 0));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
- results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering WHERE a=0 and (b, c) IN ((?, ?))"),
- makeIntOptions(0, 1));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
- results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering WHERE a=0 and (b) IN ((?))"),
- makeIntOptions(0));
- assertEquals(3, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
+
+ UntypedResultSet results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((?, ?, ?), (?, ?, ?))"),
+ makeIntOptions(0, 1, 0, 0, 1, 1));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+
+ // same query, but reversed order for the IN values
+ results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((?, ?, ?), (?, ?, ?))"),
+ makeIntOptions(0, 1, 1, 0, 1, 0));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+
+ results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 and (b, c) IN ((?, ?))"),
+ makeIntOptions(0, 1));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+
+ results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 and (b) IN ((?))"),
+ makeIntOptions(0));
+ assertEquals(3, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 0);
+ checkRow(2, results, 0, 0, 1, 1);
+ }
}
@Test
public void testPrepareInOneMarkerPerTuple() throws Throwable
{
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 1)");
-
- UntypedResultSet results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN (?, ?)"),
- options(tuple(0, 1, 0), tuple(0, 1, 1)));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
- // same query, but reversed order for the IN values
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN (?, ?)"),
- options(tuple(0, 1, 1), tuple(0, 1, 0)));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
-
- results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering WHERE a=0 and (b, c) IN (?)"),
- options(tuple(0, 1)));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
- results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering WHERE a=0 and (b) IN (?)"),
- options(tuple(0)));
- assertEquals(3, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
+
+ UntypedResultSet results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) IN (?, ?)"),
+ options(tuple(0, 1, 0), tuple(0, 1, 1)));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+
+ // same query, but reversed order for the IN values
+ results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) IN (?, ?)"),
+ options(tuple(0, 1, 1), tuple(0, 1, 0)));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+
+
+ results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 and (b, c) IN (?)"),
+ options(tuple(0, 1)));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+
+ results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 and (b) IN (?)"),
+ options(tuple(0)));
+ assertEquals(3, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 0);
+ checkRow(2, results, 0, 0, 1, 1);
+ }
}
@Test
public void testPrepareInOneMarker() throws Throwable
{
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering (a, b, c, d) VALUES (0, 0, 1, 1)");
-
- UntypedResultSet results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN ?"),
- options(list(tuple(0, 1, 0), tuple(0, 1, 1))));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
- // same query, but reversed order for the IN values
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN ?"),
- options(list(tuple(0, 1, 1), tuple(0, 1, 0))));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN ?"),
- options(list()));
- assertTrue(results.isEmpty());
-
- results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering WHERE a=0 and (b, c) IN ?"),
- options(list(tuple(0, 1))));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
- results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering WHERE a=0 and (b) IN ?"),
- options(list(tuple(0))));
- assertEquals(3, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
-
- results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering WHERE a=0 and (b) IN ?"),
- options(list()));
- assertTrue(results.isEmpty());
+ for (String tableSuffix : new String[]{"", "_compact"})
+ {
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
+ execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
+
+ UntypedResultSet results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ?"),
+ options(list(tuple(0, 1, 0), tuple(0, 1, 1))));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+
+ // same query, but reversed order for the IN values
+ results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ?"),
+ options(list(tuple(0, 1, 1), tuple(0, 1, 0))));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+
+ results = executePrepared(prepare(
+ "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ?"),
+ options(list()));
+ assertTrue(results.isEmpty());
+
+ results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 and (b, c) IN ?"),
+ options(list(tuple(0, 1))));
+ assertEquals(2, results.size());
+ checkRow(0, results, 0, 0, 1, 0);
+ checkRow(1, results, 0, 0, 1, 1);
+
+ results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 and (b) IN ?"),
+ options(list(tuple(0))));
+ assertEquals(3, results.size());
+ checkRow(0, results, 0, 0, 0, 0);
+ checkRow(1, results, 0, 0, 1, 0);
+ checkRow(2, results, 0, 0, 1, 1);
+
+ results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 and (b) IN ?"),
+ options(list()));
+ assertTrue(results.isEmpty());
+ }
}
@Test(expected=InvalidRequestException.class)
[3/4] cassandra git commit: Merge branch 'cassandra-2.0' into
cassandra-2.1
Posted by ty...@apache.org.
http://git-wip-us.apache.org/repos/asf/cassandra/blob/25a4c9e1/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
index bcf4f27,ea4f1a6..4c3ba2a
--- a/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
@@@ -17,522 -17,1234 +17,542 @@@
*/
package org.apache.cassandra.cql3;
-import org.apache.cassandra.SchemaLoader;
-import org.apache.cassandra.db.ConsistencyLevel;
-import org.apache.cassandra.db.marshal.*;
-import org.apache.cassandra.exceptions.InvalidRequestException;
-import org.apache.cassandra.exceptions.RequestExecutionException;
-import org.apache.cassandra.exceptions.RequestValidationException;
-import org.apache.cassandra.exceptions.SyntaxException;
-import org.apache.cassandra.gms.Gossiper;
-import org.apache.cassandra.service.ClientState;
-import org.apache.cassandra.service.QueryState;
-import org.apache.cassandra.transport.messages.ResultMessage;
-import org.apache.cassandra.utils.ByteBufferUtil;
-import org.apache.cassandra.utils.MD5Digest;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import java.nio.ByteBuffer;
-import java.util.*;
-
-import static org.apache.cassandra.cql3.QueryProcessor.process;
-import static org.apache.cassandra.cql3.QueryProcessor.processInternal;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertEquals;
-import static com.google.common.collect.Lists.newArrayList;
-import static org.junit.Assert.fail;
-
-public class MultiColumnRelationTest
+public class MultiColumnRelationTest extends CQLTester
{
- private static final Logger logger = LoggerFactory.getLogger(MultiColumnRelationTest.class);
- static ClientState clientState;
- static String keyspace = "multi_column_relation_test";
-
- @BeforeClass
- public static void setUpClass() throws Throwable
- {
- SchemaLoader.loadSchema();
- executeSchemaChange("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}");
- for (boolean isCompact : new boolean[]{false, true})
- {
- String tableSuffix = isCompact ? "_compact" : "";
- String compactOption = isCompact ? " WITH COMPACT STORAGE" : "";
-
- executeSchemaChange(
- "CREATE TABLE IF NOT EXISTS %s.single_partition" + tableSuffix + "(a int PRIMARY KEY, b int)" + compactOption);
- executeSchemaChange(
- "CREATE TABLE IF NOT EXISTS %s.compound_partition" +tableSuffix + "(a int, b int, c int, PRIMARY KEY ((a, b)))" + compactOption);
- executeSchemaChange(
- "CREATE TABLE IF NOT EXISTS %s.single_clustering" + tableSuffix + "(a int, b int, c int, PRIMARY KEY (a, b))" + compactOption);
- executeSchemaChange(
- "CREATE TABLE IF NOT EXISTS %s.multiple_clustering" + tableSuffix + "(a int, b int, c int, d int, PRIMARY KEY (a, b, c, d))" + compactOption);
-
- compactOption = isCompact ? " COMPACT STORAGE AND " : "";
- executeSchemaChange(
- "CREATE TABLE IF NOT EXISTS %s.multiple_clustering_reversed" + tableSuffix +
- "(a int, b int, c int, d int, PRIMARY KEY (a, b, c, d)) WITH " + compactOption + " CLUSTERING ORDER BY (b DESC, c ASC, d DESC)");
- }
- clientState = ClientState.forInternalCalls();
- }
-
- @AfterClass
- public static void stopGossiper()
- {
- Gossiper.instance.stop();
- }
-
- private static void executeSchemaChange(String query) throws Throwable
- {
- try
- {
- process(String.format(query, keyspace), ConsistencyLevel.ONE);
- } catch (RuntimeException exc)
- {
- throw exc.getCause();
- }
- }
-
- private static UntypedResultSet execute(String query) throws Throwable
- {
- try
- {
- return processInternal(String.format(query, keyspace));
- } catch (RuntimeException exc)
- {
- if (exc.getCause() != null)
- throw exc.getCause();
- throw exc;
- }
- }
-
- private MD5Digest prepare(String query) throws RequestValidationException
- {
- ResultMessage.Prepared prepared = QueryProcessor.prepare(String.format(query, keyspace), clientState, false);
- return prepared.statementId;
- }
-
- private UntypedResultSet executePrepared(MD5Digest statementId, QueryOptions options) throws RequestValidationException, RequestExecutionException
- {
- CQLStatement statement = QueryProcessor.instance.getPrepared(statementId);
- ResultMessage message = statement.executeInternal(QueryState.forInternalCalls(), options);
-
- if (message instanceof ResultMessage.Rows)
- return new UntypedResultSet(((ResultMessage.Rows)message).result);
- else
- return null;
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testMixMultiColumnRelationsAndSingleColumn() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE a = 1 AND (b) in ((2),(3)) AND c > 4");
- }
-
- @Test(expected=SyntaxException.class)
- public void testEmptyIdentifierTuple() throws Throwable
- {
- execute("SELECT * FROM %s.single_clustering WHERE () = (1, 2)");
- }
-
- @Test(expected=SyntaxException.class)
- public void testEmptyValueTuple() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE (b, c) > ()");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testDifferentTupleLengths() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE (b, c) > (1, 2, 3)");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testNullInTuple() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE (b, c) > (1, null)");
- }
-
- @Test
- public void testEmptyIN() throws Throwable
- {
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN ()");
- assertTrue(results.isEmpty());
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testNullInINValues() throws Throwable
- {
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN ((1, 2, null))");
- assertTrue(results.isEmpty());
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testPartitionKeyInequality() throws Throwable
- {
- execute("SELECT * FROM %s.single_partition WHERE (a) > (1)");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testPartitionKeyEquality() throws Throwable
- {
- execute("SELECT * FROM %s.single_partition WHERE (a) = (0)");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testRestrictNonPrimaryKey() throws Throwable
- {
- execute("SELECT * FROM %s.single_partition WHERE (b) = (0)");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testMixEqualityAndInequality() throws Throwable
- {
- execute("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) = (0) AND (b) > (0)");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testMixMultipleInequalitiesOnSameBound() throws Throwable
- {
- execute("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) > (0) AND (b) > (1)");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testClusteringColumnsOutOfOrderInInequality() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (d, c, b) > (0, 0, 0)");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testSkipClusteringColumnInEquality() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (c, d) = (0, 0)");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testSkipClusteringColumnInInequality() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (c, d) > (0, 0)");
- }
-
- @Test
- public void testSingleClusteringColumnEquality() throws Throwable
- {
- for (String tableSuffix : new String[]{"", "_compact"})
- {
- execute("INSERT INTO %s.single_clustering" + tableSuffix + "(a, b, c) VALUES (0, 0, 0)");
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 1, 0)");
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 2, 0)");
- UntypedResultSet results = execute("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) = (1)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) = (3)");
- assertEquals(0, results.size());
- }
- }
-
- @Test
- public void testMultipleClusteringColumnEquality() throws Throwable
- {
- for (String tableSuffix : new String[]{"", "_compact"})
- {
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 1)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 2, 0, 0)");
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) = (1)");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(2, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) = (1, 1)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 1, 0);
- checkRow(1, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) = (1, 1, 1)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 1, 1);
- execute("DELETE FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND b=2 and c=0 and d=0");
- }
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testPartitionAndClusteringColumnEquality() throws Throwable
- {
- execute("SELECT * FROM %s.single_clustering WHERE (a, b) = (0, 0)");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testClusteringColumnsOutOfOrderInEquality() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (d, c, b) = (3, 2, 1)");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testBadType() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) = (1, 2, 'foobar')");
- }
-
- @Test(expected=SyntaxException.class)
- public void testSingleColumnTupleRelation() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND b = (1, 2, 3)");
- }
-
@Test
- public void testMixSingleAndTupleInequalities() throws Throwable
+ public void testSingleClusteringInvalidQueries() throws Throwable
{
- createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY (a, b))");
-
- assertInvalidSyntax("SELECT * FROM %s WHERE () = (?, ?)", 1, 2);
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b) = (?) AND (b) > (?)", 0, 0);
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b) > (?) AND (b) > (?)", 0, 1);
- assertInvalid("SELECT * FROM %s WHERE (a, b) = (?, ?)", 0, 0);
- for (String tableSuffix : new String[]{"", "_compact"})
++ for (String compactOption : new String[]{"", " WITH COMPACT STORAGE"})
+ {
- String[] queries = new String[]{
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 0) AND b < 1",
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 0) AND c < 1",
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND b > 1 AND (b, c, d) < (1, 1, 0)",
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND c > 1 AND (b, c, d) < (1, 1, 0)",
- };
-
- for (String query : queries)
- {
- try
- {
- execute(query);
- fail(String.format("Expected query \"%s\" to throw an InvalidRequestException", query));
- }
- catch (InvalidRequestException e)
- {
- }
- }
- }
- }
++ createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY (a, b))" + compactOption);
+
- @Test
- public void testSingleClusteringColumnInequality() throws Throwable
- {
- for (String tableSuffix : new String[]{"", "_compact"})
- {
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 0, 0)");
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 1, 0)");
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 2, 0)");
-
- UntypedResultSet results = execute("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) > (0)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0);
- checkRow(1, results, 0, 2, 0);
-
- results = execute("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) >= (1)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0);
- checkRow(1, results, 0, 2, 0);
-
- results = execute("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) < (2)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 0);
- checkRow(1, results, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) <= (1)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 0);
- checkRow(1, results, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) > (0) AND (b) < (2)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0);
++ assertInvalidSyntax("SELECT * FROM %s WHERE () = (?, ?)", 1, 2);
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b) = (?) AND (b) > (?)", 0, 0);
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b) > (?) AND (b) > (?)", 0, 1);
++ assertInvalid("SELECT * FROM %s WHERE (a, b) = (?, ?)", 0, 0);
+ }
}
@Test
- public void testMultipleClusteringColumnInequality() throws Throwable
+ public void testMultiClusteringInvalidQueries() throws Throwable
{
- createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c, d))");
-
- assertInvalidSyntax("SELECT * FROM %s WHERE a = 0 AND (b, c) > ()");
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c) > (?, ?, ?)", 1, 2, 3);
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c) > (?, ?)", 1, null);
- for (String tableSuffix : new String[]{"", "_compact"})
++ for (String compactOption : new String[]{"", " WITH COMPACT STORAGE"})
+ {
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
-
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 1)");
-
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) > (0)");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(2, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) >= (0)");
- assertEquals(6, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
- checkRow(3, results, 0, 1, 0, 0);
- checkRow(4, results, 0, 1, 1, 0);
- checkRow(5, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) > (1, 0)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 1, 0);
- checkRow(1, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) >= (1, 0)");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(2, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (1, 1, 0)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) >= (1, 1, 0)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 1, 0);
- checkRow(1, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) < (1)");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) <= (1)");
- assertEquals(6, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
- checkRow(3, results, 0, 1, 0, 0);
- checkRow(4, results, 0, 1, 1, 0);
- checkRow(5, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) < (0, 1)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) <= (0, 1)");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) < (0, 1, 1)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) <= (0, 1, 1)");
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 0) AND (b) < (1)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 1) AND (b, c) < (1, 1)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 1) AND (b, c, d) < (1, 1, 0)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
++ createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c, d))" + compactOption);
- // Wrong order of columns
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (d, c, b) = (?, ?, ?)", 0, 0, 0);
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (d, c, b) > (?, ?, ?)", 0, 0, 0);
- // reversed
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) > (0) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(3, results.size());
- checkRow(2, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) >= (0) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(6, results.size());
- checkRow(5, results, 0, 0, 0, 0);
- checkRow(4, results, 0, 0, 1, 0);
- checkRow(3, results, 0, 0, 1, 1);
- checkRow(2, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) > (1, 0) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(2, results.size());
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) >= (1, 0) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(3, results.size());
- checkRow(2, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (1, 1, 0) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) >= (1, 1, 0) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(2, results.size());
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) < (1) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(3, results.size());
- checkRow(2, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(0, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) <= (1) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(6, results.size());
- checkRow(5, results, 0, 0, 0, 0);
- checkRow(4, results, 0, 0, 1, 0);
- checkRow(3, results, 0, 0, 1, 1);
- checkRow(2, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) < (0, 1) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) <= (0, 1) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(3, results.size());
- checkRow(2, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(0, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) < (0, 1, 1) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(2, results.size());
- checkRow(1, results, 0, 0, 0, 0);
- checkRow(0, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) <= (0, 1, 1) ORDER BY b DESC, c DESC, d DESC");
- checkRow(2, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(0, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 0) AND (b) < (1) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 1) AND (b, c) < (1, 1) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (0, 1, 1) AND (b, c, d) < (1, 1, 0) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- }
- }
++ assertInvalidSyntax("SELECT * FROM %s WHERE a = 0 AND (b, c) > ()");
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c) > (?, ?, ?)", 1, 2, 3);
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c) > (?, ?)", 1, null);
- // Wrong number of values
- assertInvalid("SELECT * FROM %s WHERE a=0 AND (b, c, d) IN ((?, ?))", 0, 1);
- assertInvalid("SELECT * FROM %s WHERE a=0 AND (b, c, d) IN ((?, ?, ?, ?, ?))", 0, 1, 2, 3, 4);
- @Test
- public void testMultipleClusteringColumnInequalityReversedComponents() throws Throwable
- {
- for (String tableSuffix : new String[]{"", "_compact"})
- {
- // b and d are reversed in the clustering order
- execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 1)");
- execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 0)");
-
- execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
- execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
-
-
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b) > (0)");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 1);
- checkRow(2, results, 0, 1, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b) >= (0)");
- assertEquals(6, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 1);
- checkRow(2, results, 0, 1, 1, 0);
- checkRow(3, results, 0, 0, 0, 0);
- checkRow(4, results, 0, 0, 1, 1);
- checkRow(5, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b) < (1)");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 1);
- checkRow(2, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b) <= (1)");
- assertEquals(6, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 1);
- checkRow(2, results, 0, 1, 1, 0);
- checkRow(3, results, 0, 0, 0, 0);
- checkRow(4, results, 0, 0, 1, 1);
- checkRow(5, results, 0, 0, 1, 0);
++ // Wrong order of columns
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND (d, c, b) = (?, ?, ?)", 0, 0, 0);
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND (d, c, b) > (?, ?, ?)", 0, 0, 0);
- // Missing first clustering column
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (c, d) = (?, ?)", 0, 0);
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (c, d) > (?, ?)", 0, 0);
- // preserve pre-6875 behavior (even though the query result is technically incorrect)
- results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b, c) > (1, 0)");
- assertEquals(0, results.size());
- }
- }
++ // Wrong number of values
++ assertInvalid("SELECT * FROM %s WHERE a=0 AND (b, c, d) IN ((?, ?))", 0, 1);
++ assertInvalid("SELECT * FROM %s WHERE a=0 AND (b, c, d) IN ((?, ?, ?, ?, ?))", 0, 1, 2, 3, 4);
- // Nulls
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c, d) IN ((?, ?, ?))", 1, 2, null);
- @Test
- public void testLiteralIn() throws Throwable
- {
- for (String tableSuffix : new String[]{"", "_compact"})
- {
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
++ // Missing first clustering column
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND (c, d) = (?, ?)", 0, 0);
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND (c, d) > (?, ?)", 0, 0);
- // Wrong type for 'd'
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c, d) = (?, ?, ?)", 1, 2, "foobar");
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((0, 1, 0), (0, 1, 1))");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
++ // Nulls
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c, d) IN ((?, ?, ?))", 1, 2, null);
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND b = (?, ?, ?)", 1, 2, 3);
- // same query, but reversed order for the IN values
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((0, 1, 1), (0, 1, 0))");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 and (b, c) IN ((0, 1))");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 and (b) IN ((0))");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) IN ((0, 1)) ORDER BY b DESC, c DESC, d DESC");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 1);
- checkRow(1, results, 0, 0, 1, 0);
- }
- }
++ // Wrong type for 'd'
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c, d) = (?, ?, ?)", 1, 2, "foobar");
- // Mix single and tuple inequalities
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c, d) > (?, ?, ?) AND b < ?", 0, 1, 0, 1);
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c, d) > (?, ?, ?) AND c < ?", 0, 1, 0, 1);
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND b > ? AND (b, c, d) < (?, ?, ?)", 1, 1, 1, 0);
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND c > ? AND (b, c, d) < (?, ?, ?)", 1, 1, 1, 0);
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND b = (?, ?, ?)", 1, 2, 3);
- assertInvalid("SELECT * FROM %s WHERE (a, b, c, d) IN ((?, ?, ?, ?))", 0, 1, 2, 3);
- assertInvalid("SELECT * FROM %s WHERE (c, d) IN ((?, ?))", 0, 1);
- @Test
- public void testLiteralInReversed() throws Throwable
- {
- for (String tableSuffix : new String[]{"", "_compact"})
- {
- execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
- execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering_reversed" + tableSuffix + " (a, b, c, d) VALUES (0, -1, 0, 0)");
++ // Mix single and tuple inequalities
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c, d) > (?, ?, ?) AND b < ?", 0, 1, 0, 1);
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c, d) > (?, ?, ?) AND c < ?", 0, 1, 0, 1);
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND b > ? AND (b, c, d) < (?, ?, ?)", 1, 1, 1, 0);
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND c > ? AND (b, c, d) < (?, ?, ?)", 1, 1, 1, 0);
- assertInvalid("SELECT * FROM %s WHERE a = ? AND (b, c) in ((?, ?), (?, ?)) AND d > ?", 0, 0, 0, 0, 0, 0);
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((0, 1, 0), (0, 1, 1))");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 1);
- checkRow(1, results, 0, 0, 1, 0);
++ assertInvalid("SELECT * FROM %s WHERE (a, b, c, d) IN ((?, ?, ?, ?))", 0, 1, 2, 3);
++ assertInvalid("SELECT * FROM %s WHERE (c, d) IN ((?, ?))", 0, 1);
- // same query, but reversed order for the IN values
- results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((0, 1, 1), (0, 1, 0))");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 1);
- checkRow(1, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((1, 0, 0), (0, 0, 0), (0, 1, 1), (0, 1, 0), (-1, 0, 0))");
- assertEquals(5, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 0, 0, 0);
- checkRow(2, results, 0, 0, 1, 1);
- checkRow(3, results, 0, 0, 1, 0);
- checkRow(4, results, 0, -1, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((0, 0, 0))");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((0, 1, 1))");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((0, 1, 0))");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 and (b, c) IN ((0, 1))");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 1);
- checkRow(1, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 and (b, c) IN ((0, 0))");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering_reversed" + tableSuffix + " WHERE a=0 and (b) IN ((0))");
- assertEquals(3, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 1);
- checkRow(2, results, 0, 0, 1, 0);
++ assertInvalid("SELECT * FROM %s WHERE a = ? AND (b, c) in ((?, ?), (?, ?)) AND d > ?", 0, 0, 0, 0, 0, 0);
+ }
}
- @Test(expected=InvalidRequestException.class)
- public void testLiteralInWithShortTuple() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN ((0, 1))");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testLiteralInWithLongTuple() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN ((0, 1, 2, 3, 4))");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testLiteralInWithPartitionKey() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE (a, b, c, d) IN ((0, 1, 2, 3))");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testLiteralInSkipsClusteringColumn() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE (c, d) IN ((0, 1))");
- }
@Test
- public void testPartitionAndClusteringInClauses() throws Throwable
+ public void testSinglePartitionInvalidQueries() throws Throwable
{
- createTable("CREATE TABLE %s (a int PRIMARY KEY, b int)");
-
- assertInvalid("SELECT * FROM %s WHERE (a) > (?)", 0);
- assertInvalid("SELECT * FROM %s WHERE (a) = (?)", 0);
- assertInvalid("SELECT * FROM %s WHERE (b) = (?)", 0);
- for (String tableSuffix : new String[]{"", "_compact"})
++ for (String compactOption : new String[]{"", " WITH COMPACT STORAGE"})
+ {
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
-
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (1, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (1, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (1, 0, 1, 1)");
-
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a IN (0, 1) AND (b, c, d) IN ((0, 1, 0), (0, 1, 1))");
- assertEquals(4, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
- checkRow(2, results, 1, 0, 1, 0);
- checkRow(3, results, 1, 0, 1, 1);
++ createTable("CREATE TABLE %s (a int PRIMARY KEY, b int)" + compactOption);
+
- // same query, but reversed order for the IN values
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a IN (1, 0) AND (b, c, d) IN ((0, 1, 1), (0, 1, 0))");
- assertEquals(4, results.size());
- checkRow(0, results, 1, 0, 1, 0);
- checkRow(1, results, 1, 0, 1, 1);
- checkRow(2, results, 0, 0, 1, 0);
- checkRow(3, results, 0, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a IN (0, 1) and (b, c) IN ((0, 1))");
- assertEquals(4, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
- checkRow(2, results, 1, 0, 1, 0);
- checkRow(3, results, 1, 0, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a IN (0, 1) and (b) IN ((0))");
- assertEquals(6, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
- checkRow(3, results, 1, 0, 0, 0);
- checkRow(4, results, 1, 0, 1, 0);
- checkRow(5, results, 1, 0, 1, 1);
++ assertInvalid("SELECT * FROM %s WHERE (a) > (?)", 0);
++ assertInvalid("SELECT * FROM %s WHERE (a) = (?)", 0);
++ assertInvalid("SELECT * FROM %s WHERE (b) = (?)", 0);
+ }
}
- // prepare statement tests
-
- @Test(expected=InvalidRequestException.class)
- public void testPreparePartitionAndClusteringColumnEquality() throws Throwable
- {
- prepare("SELECT * FROM %s.single_clustering WHERE (a, b) = (?, ?)");
- }
-
- @Test(expected=InvalidRequestException.class)
- public void testPrepareDifferentTupleLengths() throws Throwable
- {
- prepare("SELECT * FROM %s.multiple_clustering WHERE (b, c) > (?, ?, ?)");
- }
-
@Test
- public void testPrepareEmptyIN() throws Throwable
+ public void testSingleClustering() throws Throwable
{
- createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY (a, b))");
- MD5Digest id = prepare("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN ()");
- UntypedResultSet results = executePrepared(id, makeIntOptions());
- assertTrue(results.isEmpty());
- }
++ for (String compactOption : new String[]{"", " WITH COMPACT STORAGE"})
++ {
++ createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY (a, b))" + compactOption);
- execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 0, 0);
- execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 1, 0);
- execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 2, 0);
- @Test(expected=InvalidRequestException.class)
- public void testPreparePartitionKeyInequality() throws Throwable
- {
- prepare("SELECT * FROM %s.single_partition WHERE (a) > (?)");
- }
++ execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 0, 0);
++ execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 1, 0);
++ execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 2, 0);
- // Equalities
- @Test(expected=InvalidRequestException.class)
- public void testPreparePartitionKeyEquality() throws Throwable
- {
- prepare("SELECT * FROM %s.single_partition WHERE (a) = (?)");
- }
++ // Equalities
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) = (?)", 0, 1),
- row(0, 1, 0)
- );
- @Test(expected=InvalidRequestException.class)
- public void testPrepareRestrictNonPrimaryKey() throws Throwable
- {
- prepare("SELECT * FROM %s.single_partition WHERE (b) = (?)");
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) = (?)", 0, 1),
++ row(0, 1, 0)
++ );
- // Same but check the whole tuple can be prepared
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) = ?", 0, tuple(1)),
- row(0, 1, 0)
- );
- @Test(expected=InvalidRequestException.class)
- public void testPrepareMixEqualityAndInequality() throws Throwable
- {
- prepare("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) = (?) AND (b) > (?)");
- }
++ // Same but check the whole tuple can be prepared
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) = ?", 0, tuple(1)),
++ row(0, 1, 0)
++ );
- assertEmpty(execute("SELECT * FROM %s WHERE a = ? AND (b) = (?)", 0, 3));
- @Test(expected=InvalidRequestException.class)
- public void testPrepareMixMultipleInequalitiesOnSameBound() throws Throwable
- {
- prepare("SELECT * FROM %s.single_clustering WHERE a=0 AND (b) > (?) AND (b) > (?)");
- }
++ assertEmpty(execute("SELECT * FROM %s WHERE a = ? AND (b) = (?)", 0, 3));
- // Inequalities
- @Test(expected=InvalidRequestException.class)
- public void testPrepareClusteringColumnsOutOfOrderInInequality() throws Throwable
- {
- prepare("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (d, c, b) > (?, ?, ?)");
- }
++ // Inequalities
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) > (?)", 0, 0),
- row(0, 1, 0),
- row(0, 2, 0)
- );
- @Test(expected=InvalidRequestException.class)
- public void testPrepareSkipClusteringColumnInEquality() throws Throwable
- {
- prepare("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (c, d) = (?, ?)");
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) > (?)", 0, 0),
++ row(0, 1, 0),
++ row(0, 2, 0)
++ );
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) >= (?)", 0, 1),
- row(0, 1, 0),
- row(0, 2, 0)
- );
- @Test(expected=InvalidRequestException.class)
- public void testPrepareSkipClusteringColumnInInequality() throws Throwable
- {
- prepare("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (c, d) > (?, ?)");
- }
-
- @Test
- public void testPreparedClusteringColumnEquality() throws Throwable
- {
- for (String tableSuffix : new String[]{"", "_compact"})
- {
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 0, 0)");
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 1, 0)");
- MD5Digest id = prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) = (?)");
- UntypedResultSet results = executePrepared(id, makeIntOptions(0));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 0);
- }
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) >= (?)", 0, 1),
++ row(0, 1, 0),
++ row(0, 2, 0)
++ );
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) < (?)", 0, 2),
- row(0, 0, 0),
- row(0, 1, 0)
- );
- @Test
- public void testPreparedClusteringColumnEqualitySingleMarker() throws Throwable
- {
- for (String tableSuffix : new String[]{"", "_compact"})
- {
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 0, 0)");
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 1, 0)");
- MD5Digest id = prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) = ?");
- UntypedResultSet results = executePrepared(id, options(tuple(0)));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 0);
- }
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) < (?)", 0, 2),
++ row(0, 0, 0),
++ row(0, 1, 0)
++ );
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) <= (?)", 0, 1),
- row(0, 0, 0),
- row(0, 1, 0)
- );
- @Test
- public void testPreparedSingleClusteringColumnInequality() throws Throwable
- {
- for (String tableSuffix : new String[]{"", "_compact"})
- {
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 0, 0)");
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 1, 0)");
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 2, 0)");
-
- MD5Digest id = prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) > (?)");
- UntypedResultSet results = executePrepared(id, makeIntOptions(0));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0);
- checkRow(1, results, 0, 2, 0);
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) >= (?)"), makeIntOptions(1));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0);
- checkRow(1, results, 0, 2, 0);
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) < (?)"), makeIntOptions(2));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 0);
- checkRow(1, results, 0, 1, 0);
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) <= (?)"), makeIntOptions(1));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 0);
- checkRow(1, results, 0, 1, 0);
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) > (?) AND (b) < (?)"), makeIntOptions(0, 2));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0);
- }
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) <= (?)", 0, 1),
++ row(0, 0, 0),
++ row(0, 1, 0)
++ );
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) > (?) AND (b) < (?)", 0, 0, 2),
- row(0, 1, 0)
- );
- @Test
- public void testPreparedSingleClusteringColumnInequalitySingleMarker() throws Throwable
- {
- for (String tableSuffix : new String[]{"", "_compact"})
- {
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 0, 0)");
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 1, 0)");
- execute("INSERT INTO %s.single_clustering" + tableSuffix + " (a, b, c) VALUES (0, 2, 0)");
-
- MD5Digest id = prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) > ?");
- UntypedResultSet results = executePrepared(id, options(tuple(0)));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0);
- checkRow(1, results, 0, 2, 0);
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) >= ?"), options(tuple(1)));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0);
- checkRow(1, results, 0, 2, 0);
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) < ?"), options(tuple(2)));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 0);
- checkRow(1, results, 0, 1, 0);
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) <= ?"), options(tuple(1)));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 0);
- checkRow(1, results, 0, 1, 0);
-
-
- results = executePrepared(prepare("SELECT * FROM %s.single_clustering" + tableSuffix + " WHERE a=0 AND (b) > ? AND (b) < ?"),
- options(tuple(0), tuple(2)));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0);
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) > (?) AND (b) < (?)", 0, 0, 2),
++ row(0, 1, 0)
++ );
+ }
}
@Test
- public void testPrepareMultipleClusteringColumnInequality() throws Throwable
+ public void testNonEqualsRelation() throws Throwable
{
- createTable("CREATE TABLE %s (a int PRIMARY KEY, b int)");
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b) != (0)");
- for (String tableSuffix : new String[]{"", "_compact"})
++ for (String compactOption : new String[]{"", " WITH COMPACT STORAGE"})
+ {
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
-
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 1)");
-
- UntypedResultSet results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) > (?)"), makeIntOptions(0));
- assertEquals(3, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(2, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) > (?, ?)"), makeIntOptions(1, 0));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 1, 0);
- checkRow(1, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare
- ("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (?, ?, ?)"), makeIntOptions(1, 1, 0));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (?, ?, ?) AND (b) < (?)"),
- makeIntOptions(0, 1, 0, 1));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 1);
-
- results = executePrepared(prepare
- ("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (?, ?, ?) AND (b, c) < (?, ?)"),
- makeIntOptions(0, 1, 1, 1, 1));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (?, ?, ?) AND (b, c, d) < (?, ?, ?)"),
- makeIntOptions(0, 1, 1, 1, 1, 0));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- // reversed
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) > (?) ORDER BY b DESC, c DESC, d DESC"),
- makeIntOptions(0));
- assertEquals(3, results.size());
- checkRow(2, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > (?, ?, ?) AND (b, c) < (?, ?) ORDER BY b DESC, c DESC, d DESC"),
- makeIntOptions(0, 1, 1, 1, 1));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
++ createTable("CREATE TABLE %s (a int PRIMARY KEY, b int)" + compactOption);
++ assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b) != (0)");
+ }
}
@Test
- public void testPrepareMultipleClusteringColumnInequalitySingleMarker() throws Throwable
+ public void testMultipleClustering() throws Throwable
{
- createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c, d))");
-
- execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0);
- execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 0);
- execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 1);
-
- execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 0, 0);
- execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 1, 0);
- execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 1, 1);
-
- // Empty query
- assertEmpty(execute("SELECT * FROM %s WHERE a = 0 AND (b, c, d) IN ()"));
-
- // Equalities
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) = (?)", 0, 1),
- row(0, 1, 0, 0),
- row(0, 1, 1, 0),
- row(0, 1, 1, 1)
- );
-
- // Same with whole tuple prepared
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) = ?", 0, tuple(1)),
- row(0, 1, 0, 0),
- row(0, 1, 1, 0),
- row(0, 1, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) = (?, ?)", 0, 1, 1),
- row(0, 1, 1, 0),
- row(0, 1, 1, 1)
- );
-
- // Same with whole tuple prepared
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) = ?", 0, tuple(1, 1)),
- row(0, 1, 1, 0),
- row(0, 1, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) = (?, ?, ?)", 0, 1, 1, 1),
- row(0, 1, 1, 1)
- );
-
- // Same with whole tuple prepared
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) = ?", 0, tuple(1, 1, 1)),
- row(0, 1, 1, 1)
- );
-
- // Inequalities
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) > (?)", 0, 0),
- row(0, 1, 0, 0),
- row(0, 1, 1, 0),
- row(0, 1, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) >= (?)", 0, 0),
- row(0, 0, 0, 0),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1),
- row(0, 1, 0, 0),
- row(0, 1, 1, 0),
- row(0, 1, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) > (?, ?)", 0, 1, 0),
- row(0, 1, 1, 0),
- row(0, 1, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) >= (?, ?)", 0, 1, 0),
- row(0, 1, 0, 0),
- row(0, 1, 1, 0),
- row(0, 1, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?)", 0, 1, 1, 0),
- row(0, 1, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) >= (?, ?, ?)", 0, 1, 1, 0),
- row(0, 1, 1, 0),
- row(0, 1, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) < (?)", 0, 1),
- row(0, 0, 0, 0),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) <= (?)", 0, 1),
- row(0, 0, 0, 0),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1),
- row(0, 1, 0, 0),
- row(0, 1, 1, 0),
- row(0, 1, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) < (?, ?)", 0, 0, 1),
- row(0, 0, 0, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) <= (?, ?)", 0, 0, 1),
- row(0, 0, 0, 0),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) < (?, ?, ?)", 0, 0, 1, 1),
- row(0, 0, 0, 0),
- row(0, 0, 1, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) <= (?, ?, ?)", 0, 0, 1, 1),
- row(0, 0, 0, 0),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?) AND (b) < (?)", 0, 0, 1, 0, 1),
- row(0, 0, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?) AND (b, c) < (?, ?)", 0, 0, 1, 1, 1, 1),
- row(0, 1, 0, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?) AND (b, c, d) < (?, ?, ?)", 0, 0, 1, 1, 1, 1, 0),
- row(0, 1, 0, 0)
- );
-
- // Same with whole tuple prepared
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > ? AND (b, c, d) < ?", 0, tuple(0, 1, 1), tuple(1, 1, 0)),
- row(0, 1, 0, 0)
- );
-
- // reversed
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) > (?) ORDER BY b DESC, c DESC, d DESC", 0, 0),
- row(0, 1, 1, 1),
- row(0, 1, 1, 0),
- row(0, 1, 0, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) >= (?) ORDER BY b DESC, c DESC, d DESC", 0, 0),
- row(0, 1, 1, 1),
- row(0, 1, 1, 0),
- row(0, 1, 0, 0),
- row(0, 0, 1, 1),
- row(0, 0, 1, 0),
- row(0, 0, 0, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) > (?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 1, 0),
- row(0, 1, 1, 1),
- row(0, 1, 1, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) >= (?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 1, 0),
- row(0, 1, 1, 1),
- row(0, 1, 1, 0),
- row(0, 1, 0, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 1, 1, 0),
- row(0, 1, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) >= (?, ?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 1, 1, 0),
- row(0, 1, 1, 1),
- row(0, 1, 1, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) < (?) ORDER BY b DESC, c DESC, d DESC", 0, 1),
- row(0, 0, 1, 1),
- row(0, 0, 1, 0),
- row(0, 0, 0, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) <= (?) ORDER BY b DESC, c DESC, d DESC", 0, 1),
- row(0, 1, 1, 1),
- row(0, 1, 1, 0),
- row(0, 1, 0, 0),
- row(0, 0, 1, 1),
- row(0, 0, 1, 0),
- row(0, 0, 0, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) < (?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1),
- row(0, 0, 0, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) <= (?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1),
- row(0, 0, 1, 1),
- row(0, 0, 1, 0),
- row(0, 0, 0, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) < (?, ?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1, 1),
- row(0, 0, 1, 0),
- row(0, 0, 0, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) <= (?, ?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1, 1),
- row(0, 0, 1, 1),
- row(0, 0, 1, 0),
- row(0, 0, 0, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?) AND (b) < (?) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1, 0, 1),
- row(0, 0, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?) AND (b, c) < (?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1, 1, 1, 1),
- row(0, 1, 0, 0)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?) AND (b, c, d) < (?, ?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1, 1, 1, 1, 0),
- row(0, 1, 0, 0)
- );
-
- // IN
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) IN ((?, ?, ?), (?, ?, ?))", 0, 0, 1, 0, 0, 1, 1),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1)
- );
-
- // same query but with whole tuple prepared
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) IN (?, ?)", 0, tuple(0, 1, 0), tuple(0, 1, 1)),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1)
- );
-
- // same query but with whole IN list prepared
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) IN ?", 0, list(tuple(0, 1, 0), tuple(0, 1, 1))),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1)
- );
-
- // same query, but reversed order for the IN values
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) IN (?, ?)", 0, tuple(0, 1, 1), tuple(0, 1, 0)),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? and (b, c) IN ((?, ?))", 0, 0, 1),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? and (b) IN ((?))", 0, 0),
- row(0, 0, 0, 0),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) IN ((?, ?)) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1),
- row(0, 0, 1, 1),
- row(0, 0, 1, 0)
- );
-
- // IN on both partition key and clustering key
- execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 1, 0, 0, 0);
- execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 1, 0, 1, 0);
- execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 1, 0, 1, 1);
-
- assertRows(execute("SELECT * FROM %s WHERE a IN (?, ?) AND (b, c, d) IN (?, ?)", 0, 1, tuple(0, 1, 0), tuple(0, 1, 1)),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1),
- row(1, 0, 1, 0),
- row(1, 0, 1, 1)
- );
-
- // same but with whole IN lists prepared
- assertRows(execute("SELECT * FROM %s WHERE a IN ? AND (b, c, d) IN ?", list(0, 1), list(tuple(0, 1, 0), tuple(0, 1, 1))),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1),
- row(1, 0, 1, 0),
- row(1, 0, 1, 1)
- );
-
- // same query, but reversed order for the IN values
- assertRows(execute("SELECT * FROM %s WHERE a IN (?, ?) AND (b, c, d) IN (?, ?)", 1, 0, tuple(0, 1, 1), tuple(0, 1, 0)),
- row(1, 0, 1, 0),
- row(1, 0, 1, 1),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a IN (?, ?) and (b, c) IN ((?, ?))", 0, 1, 0, 1),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1),
- row(1, 0, 1, 0),
- row(1, 0, 1, 1)
- );
-
- assertRows(execute("SELECT * FROM %s WHERE a IN (?, ?) and (b) IN ((?))", 0, 1, 0),
- row(0, 0, 0, 0),
- row(0, 0, 1, 0),
- row(0, 0, 1, 1),
- row(1, 0, 0, 0),
- row(1, 0, 1, 0),
- row(1, 0, 1, 1)
- );
- for (String tableSuffix : new String[]{"", "_compact"})
++ for (String compactOption : new String[]{"", " WITH COMPACT STORAGE"})
+ {
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
-
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 1, 1, 1)");
-
- UntypedResultSet results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) > ?"), options(tuple(0)));
- assertEquals(3, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(2, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c) > ?"), options(tuple(1, 0)));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 1, 0);
- checkRow(1, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare
- ("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > ?"), options(tuple(1, 1, 0)));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > ? AND (b) < ?"),
- options(tuple(0, 1, 0), tuple(1)));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 1);
-
- results = executePrepared(prepare
- ("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > ? AND (b, c) < ?"),
- options(tuple(0, 1, 1), tuple(1, 1)));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > ? AND (b, c, d) < ?"),
- options(tuple(0, 1, 1), tuple(1, 1, 0)));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
++ createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c, d))" + compactOption);
++
++ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0);
++ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 0);
++ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 1);
++
++ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 0, 0);
++ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 1, 0);
++ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 1, 1);
++
++ // Empty query
++ assertEmpty(execute("SELECT * FROM %s WHERE a = 0 AND (b, c, d) IN ()"));
++
++ // Equalities
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) = (?)", 0, 1),
++ row(0, 1, 0, 0),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 1)
++ );
++
++ // Same with whole tuple prepared
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) = ?", 0, tuple(1)),
++ row(0, 1, 0, 0),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) = (?, ?)", 0, 1, 1),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 1)
++ );
++
++ // Same with whole tuple prepared
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) = ?", 0, tuple(1, 1)),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) = (?, ?, ?)", 0, 1, 1, 1),
++ row(0, 1, 1, 1)
++ );
++
++ // Same with whole tuple prepared
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) = ?", 0, tuple(1, 1, 1)),
++ row(0, 1, 1, 1)
++ );
++
++ // Inequalities
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) > (?)", 0, 0),
++ row(0, 1, 0, 0),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) >= (?)", 0, 0),
++ row(0, 0, 0, 0),
++ row(0, 0, 1, 0),
++ row(0, 0, 1, 1),
++ row(0, 1, 0, 0),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) > (?, ?)", 0, 1, 0),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) >= (?, ?)", 0, 1, 0),
++ row(0, 1, 0, 0),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?)", 0, 1, 1, 0),
++ row(0, 1, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) >= (?, ?, ?)", 0, 1, 1, 0),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) < (?)", 0, 1),
++ row(0, 0, 0, 0),
++ row(0, 0, 1, 0),
++ row(0, 0, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) <= (?)", 0, 1),
++ row(0, 0, 0, 0),
++ row(0, 0, 1, 0),
++ row(0, 0, 1, 1),
++ row(0, 1, 0, 0),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) < (?, ?)", 0, 0, 1),
++ row(0, 0, 0, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) <= (?, ?)", 0, 0, 1),
++ row(0, 0, 0, 0),
++ row(0, 0, 1, 0),
++ row(0, 0, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) < (?, ?, ?)", 0, 0, 1, 1),
++ row(0, 0, 0, 0),
++ row(0, 0, 1, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) <= (?, ?, ?)", 0, 0, 1, 1),
++ row(0, 0, 0, 0),
++ row(0, 0, 1, 0),
++ row(0, 0, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?) AND (b) < (?)", 0, 0, 1, 0, 1),
++ row(0, 0, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?) AND (b, c) < (?, ?)", 0, 0, 1, 1, 1, 1),
++ row(0, 1, 0, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?) AND (b, c, d) < (?, ?, ?)", 0, 0, 1, 1, 1, 1, 0),
++ row(0, 1, 0, 0)
++ );
++
++ // Same with whole tuple prepared
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > ? AND (b, c, d) < ?", 0, tuple(0, 1, 1), tuple(1, 1, 0)),
++ row(0, 1, 0, 0)
++ );
+
+ // reversed
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b) > ? ORDER BY b DESC, c DESC, d DESC"),
- options(tuple(0)));
- assertEquals(3, results.size());
- checkRow(2, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- checkRow(0, results, 0, 1, 1, 1);
-
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) > ? AND (b, c) < ? ORDER BY b DESC, c DESC, d DESC"),
- options(tuple(0, 1, 1), tuple(1, 1)));
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- }
- }
-
- @Test
- public void testPrepareLiteralIn() throws Throwable
- {
- for (String tableSuffix : new String[]{"", "_compact"})
- {
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
-
- UntypedResultSet results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((?, ?, ?), (?, ?, ?))"),
- makeIntOptions(0, 1, 0, 0, 1, 1));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) > (?) ORDER BY b DESC, c DESC, d DESC", 0, 0),
++ row(0, 1, 1, 1),
++ row(0, 1, 1, 0),
++ row(0, 1, 0, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) >= (?) ORDER BY b DESC, c DESC, d DESC", 0, 0),
++ row(0, 1, 1, 1),
++ row(0, 1, 1, 0),
++ row(0, 1, 0, 0),
++ row(0, 0, 1, 1),
++ row(0, 0, 1, 0),
++ row(0, 0, 0, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) > (?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 1, 0),
++ row(0, 1, 1, 1),
++ row(0, 1, 1, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) >= (?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 1, 0),
++ row(0, 1, 1, 1),
++ row(0, 1, 1, 0),
++ row(0, 1, 0, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 1, 1, 0),
++ row(0, 1, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) >= (?, ?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 1, 1, 0),
++ row(0, 1, 1, 1),
++ row(0, 1, 1, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) < (?) ORDER BY b DESC, c DESC, d DESC", 0, 1),
++ row(0, 0, 1, 1),
++ row(0, 0, 1, 0),
++ row(0, 0, 0, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) <= (?) ORDER BY b DESC, c DESC, d DESC", 0, 1),
++ row(0, 1, 1, 1),
++ row(0, 1, 1, 0),
++ row(0, 1, 0, 0),
++ row(0, 0, 1, 1),
++ row(0, 0, 1, 0),
++ row(0, 0, 0, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) < (?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1),
++ row(0, 0, 0, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) <= (?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1),
++ row(0, 0, 1, 1),
++ row(0, 0, 1, 0),
++ row(0, 0, 0, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) < (?, ?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1, 1),
++ row(0, 0, 1, 0),
++ row(0, 0, 0, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) <= (?, ?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1, 1),
++ row(0, 0, 1, 1),
++ row(0, 0, 1, 0),
++ row(0, 0, 0, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?) AND (b) < (?) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1, 0, 1),
++ row(0, 0, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?) AND (b, c) < (?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1, 1, 1, 1),
++ row(0, 1, 0, 0)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) > (?, ?, ?) AND (b, c, d) < (?, ?, ?) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1, 1, 1, 1, 0),
++ row(0, 1, 0, 0)
++ );
++
++ // IN
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) IN ((?, ?, ?), (?, ?, ?))", 0, 0, 1, 0, 0, 1, 1),
++ row(0, 0, 1, 0),
++ row(0, 0, 1, 1)
++ );
++
++ // same query but with whole tuple prepared
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) IN (?, ?)", 0, tuple(0, 1, 0), tuple(0, 1, 1)),
++ row(0, 0, 1, 0),
++ row(0, 0, 1, 1)
++ );
++
++ // same query but with whole IN list prepared
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) IN ?", 0, list(tuple(0, 1, 0), tuple(0, 1, 1))),
++ row(0, 0, 1, 0),
++ row(0, 0, 1, 1)
++ );
+
+ // same query, but reversed order for the IN values
- results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) IN ((?, ?, ?), (?, ?, ?))"),
- makeIntOptions(0, 1, 1, 0, 1, 0));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
- results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 and (b, c) IN ((?, ?))"),
- makeIntOptions(0, 1));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
-
- results = executePrepared(prepare("SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 and (b) IN ((?))"),
- makeIntOptions(0));
- assertEquals(3, results.size());
- checkRow(0, results, 0, 0, 0, 0);
- checkRow(1, results, 0, 0, 1, 0);
- checkRow(2, results, 0, 0, 1, 1);
- }
- }
-
- @Test
- public void testPrepareInOneMarkerPerTuple() throws Throwable
- {
- for (String tableSuffix : new String[]{"", "_compact"})
- {
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 0, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 0)");
- execute("INSERT INTO %s.multiple_clustering" + tableSuffix + " (a, b, c, d) VALUES (0, 0, 1, 1)");
-
- UntypedResultSet results = executePrepared(prepare(
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a=0 AND (b, c, d) IN (?, ?)"),
- options(tuple(0, 1, 0), tuple(0, 1, 1)));
- assertEquals(2, results.size());
- checkRow(0, results, 0, 0, 1, 0);
- checkRow(1, results, 0, 0, 1, 1);
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c, d) IN (?, ?)", 0, tuple(0, 1, 1), tuple(0, 1, 0)),
++ row(0, 0, 1, 0),
++ row(0, 0, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b, c) IN ((?, ?))", 0, 0, 1),
++ row(0, 0, 1, 0),
++ row(0, 0, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b) IN ((?))", 0, 0),
++ row(0, 0, 0, 0),
++ row(0, 0, 1, 0),
++ row(0, 0, 1, 1)
++ );
++
++ assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) IN ((?, ?)) ORDER BY b DESC, c DESC, d DESC", 0, 0, 1),
++ row(0, 0, 1, 1),
++ row(0, 0, 1, 0)
++ );
++
++ // IN on both partition key and clustering key
++ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 1, 0, 0, 0);
++ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 1, 0, 1, 0);
++ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 1, 0, 1, 1);
++
++ assertRows(execute("SELECT * FROM %s WHERE a IN (?, ?) AND (b, c, d) IN (?, ?)", 0, 1, tuple(0, 1, 0), tuple(0, 1, 1)),
++ row(0, 0, 1, 0),
++ row(0, 0, 1, 1),
++ row(1, 0, 1, 0),
++
<TRUNCATED>
[2/4] cassandra git commit: Fix multicolumn relation + COMPACT
STORAGE issues
Posted by ty...@apache.org.
Fix multicolumn relation + COMPACT STORAGE issues
Patch by Tyler Hobbs; reviewed by Benjamin Lerer for CASSANDRA-8264
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/084d93da
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/084d93da
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/084d93da
Branch: refs/heads/cassandra-2.1
Commit: 084d93daf6b6031909fc318e57a2a205ad32c237
Parents: 1945384
Author: Tyler Hobbs <ty...@datastax.com>
Authored: Wed Nov 19 11:25:09 2014 -0600
Committer: Tyler Hobbs <ty...@datastax.com>
Committed: Wed Nov 19 11:25:09 2014 -0600
----------------------------------------------------------------------
CHANGES.txt | 2 +
.../cql3/statements/SelectStatement.java | 95 +-
.../cassandra/cql3/MultiColumnRelationTest.java | 1464 +++++++++---------
3 files changed, 840 insertions(+), 721 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/084d93da/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index fff6d3a..01ea887 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
2.0.12:
+ * Fix some failing queries that use multi-column relations
+ on COMPACT STORAGE tables (CASSANDRA-8264)
* Fix InvalidRequestException with ORDER BY (CASSANDRA-8286)
* Disable SSLv3 for POODLE (CASSANDRA-8265)
* Fix millisecond timestamps in Tracing (CASSANDRA-8297)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/084d93da/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index f1d1aab..db25716 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -713,9 +713,9 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
CFDefinition.Name name = idIter.next();
assert r != null && !r.isSlice();
- List<ByteBuffer> values = r.values(variables);
- if (values.size() == 1)
+ if (r.isEQ())
{
+ List<ByteBuffer> values = r.values(variables);
ByteBuffer val = values.get(0);
if (val == null)
throw new InvalidRequestException(String.format("Invalid null value for clustering key part %s", name.name));
@@ -723,26 +723,56 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
}
else
{
- // We have a IN, which we only support for the last column.
- // If compact, just add all values and we're done. Otherwise,
- // for each value of the IN, creates all the columns corresponding to the selection.
- if (values.isEmpty())
- return null;
- SortedSet<ByteBuffer> columns = new TreeSet<ByteBuffer>(cfDef.cfm.comparator);
- Iterator<ByteBuffer> iter = values.iterator();
- while (iter.hasNext())
+ if (!r.isMultiColumn())
{
- ByteBuffer val = iter.next();
- ColumnNameBuilder b = iter.hasNext() ? builder.copy() : builder;
- if (val == null)
- throw new InvalidRequestException(String.format("Invalid null value for clustering key part %s", name.name));
- b.add(val);
- if (cfDef.isCompact)
- columns.add(b.build());
- else
- columns.addAll(addSelectedColumns(b));
+ // We have a IN, which we only support for the last column.
+ // If compact, just add all values and we're done. Otherwise,
+ // for each value of the IN, creates all the columns corresponding to the selection.
+ List<ByteBuffer> values = r.values(variables);
+ if (values.isEmpty())
+ return null;
+ SortedSet<ByteBuffer> columns = new TreeSet<ByteBuffer>(cfDef.cfm.comparator);
+ Iterator<ByteBuffer> iter = values.iterator();
+ while (iter.hasNext())
+ {
+ ByteBuffer val = iter.next();
+ ColumnNameBuilder b = iter.hasNext() ? builder.copy() : builder;
+ if (val == null)
+ throw new InvalidRequestException(String.format("Invalid null value for clustering key part %s", name.name));
+ b.add(val);
+ if (cfDef.isCompact)
+ columns.add(b.build());
+ else
+ columns.addAll(addSelectedColumns(b));
+ }
+ return columns;
+ }
+ else
+ {
+ // we have a multi-column IN restriction
+ List<List<ByteBuffer>> values = ((MultiColumnRestriction.IN) r).splitValues(variables);
+ if (values.isEmpty())
+ return null;
+ TreeSet<ByteBuffer> inValues = new TreeSet<>(cfDef.cfm.comparator);
+ for (List<ByteBuffer> components : values)
+ {
+ ColumnNameBuilder b = builder.copy();
+ for (int i = 0; i < components.size(); i++)
+ {
+ if (components.get(i) == null)
+ {
+ List<CFDefinition.Name> clusteringCols = new ArrayList<>(cfDef.clusteringColumns());
+ throw new InvalidRequestException("Invalid null value in condition for clustering column " + clusteringCols.get(i + name.position));
+ }
+ b.add(components.get(i));
+ }
+ if (cfDef.isCompact)
+ inValues.add(b.build());
+ else
+ inValues.addAll(addSelectedColumns(b));
+ }
+ return inValues;
}
- return columns;
}
}
@@ -1127,10 +1157,27 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
{
Comparator<ByteBuffer> comp = cfDef.cfm.comparator;
// For dynamic CF, the column could be out of the requested bounds, filter here
- if (!sliceRestriction.isInclusive(Bound.START) && comp.compare(c.name(), sliceRestriction.bound(Bound.START, variables)) == 0)
- continue;
- if (!sliceRestriction.isInclusive(Bound.END) && comp.compare(c.name(), sliceRestriction.bound(Bound.END, variables)) == 0)
- continue;
+
+ if (!sliceRestriction.isInclusive(Bound.START))
+ {
+ // even though it's a multi-column restriction, we know it can only contain a bound for one
+ // column because we've already checked that the comparator is not composite
+ ByteBuffer bounds = sliceRestriction.isMultiColumn()
+ ? ((MultiColumnRestriction.Slice) sliceRestriction).componentBounds(Bound.START, variables).get(0)
+ : sliceRestriction.bound(Bound.START, variables);
+ if (comp.compare(c.name(), bounds) == 0)
+ continue;
+ }
+
+ if (!sliceRestriction.isInclusive(Bound.END))
+ {
+ // see the above comment on using the first bound from the multi-column restriction
+ ByteBuffer bounds = sliceRestriction.isMultiColumn()
+ ? ((MultiColumnRestriction.Slice) sliceRestriction).componentBounds(Bound.END, variables).get(0)
+ : sliceRestriction.bound(Bound.END, variables);
+ if (comp.compare(c.name(), bounds) == 0)
+ continue;
+ }
}
result.newRow();
[4/4] cassandra git commit: Merge branch 'cassandra-2.0' into
cassandra-2.1
Posted by ty...@apache.org.
Merge branch 'cassandra-2.0' into cassandra-2.1
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/25a4c9e1
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/25a4c9e1
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/25a4c9e1
Branch: refs/heads/cassandra-2.1
Commit: 25a4c9e1f7388b35d7c51bdb36766618026cb0c7
Parents: 289314a 084d93d
Author: Tyler Hobbs <ty...@datastax.com>
Authored: Wed Nov 19 11:28:51 2014 -0600
Committer: Tyler Hobbs <ty...@datastax.com>
Committed: Wed Nov 19 11:28:51 2014 -0600
----------------------------------------------------------------------
CHANGES.txt | 2 +
.../cql3/statements/SelectStatement.java | 15 +-
.../cassandra/cql3/MultiColumnRelationTest.java | 938 ++++++++++---------
3 files changed, 494 insertions(+), 461 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/25a4c9e1/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index 80c6872,01ea887..8dbcbc8
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -1,12 -1,6 +1,14 @@@
-2.0.12:
+2.1.3
+ * Do more aggressive entire-sstable TTL expiry checks (CASSANDRA-8243)
+ * Add more log info if readMeter is null (CASSANDRA-8238)
+ * add check of the system wall clock time at startup (CASSANDRA-8305)
+ * Support for frozen collections (CASSANDRA-7859)
+ * Fix overflow on histogram computation (CASSANDRA-8028)
+ * Have paxos reuse the timestamp generation of normal queries (CASSANDRA-7801)
+ * Fix incremental repair not remove parent session on remote (CASSANDRA-8291)
+Merged from 2.0:
+ * Fix some failing queries that use multi-column relations
+ on COMPACT STORAGE tables (CASSANDRA-8264)
* Fix InvalidRequestException with ORDER BY (CASSANDRA-8286)
* Disable SSLv3 for POODLE (CASSANDRA-8265)
* Fix millisecond timestamps in Tracing (CASSANDRA-8297)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/25a4c9e1/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index 09d1e52,db25716..688d1d5
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@@ -1120,45 -1077,15 +1120,56 @@@ public class SelectStatement implement
return expressions;
}
- private void validateIndexExpressionValue(ByteBuffer value, CFDefinition.Name name) throws InvalidRequestException
+ private static ByteBuffer validateIndexedValue(ColumnDefinition def, ByteBuffer value) throws InvalidRequestException
{
if (value == null)
- throw new InvalidRequestException(String.format("Unsupported null value for indexed column %s", name));
+ throw new InvalidRequestException(String.format("Unsupported null value for indexed column %s", def.name));
if (value.remaining() > 0xFFFF)
throw new InvalidRequestException("Index expression values may not be larger than 64K");
+ return value;
}
- private static IndexOperator reverse(IndexOperator op)
++ private CellName makeExclusiveSliceBound(Bound bound, CellNameType type, QueryOptions options) throws InvalidRequestException
++ {
++ if (sliceRestriction.isInclusive(bound))
++ return null;
++
++ if (sliceRestriction.isMultiColumn())
++ return type.makeCellName(((MultiColumnRestriction.Slice) sliceRestriction).componentBounds(bound, options).toArray());
++ else
++ return type.makeCellName(sliceRestriction.bound(bound, options));
++ }
++
+ private Iterator<Cell> applySliceRestriction(final Iterator<Cell> cells, final QueryOptions options) throws InvalidRequestException
+ {
+ assert sliceRestriction != null;
+
+ final CellNameType type = cfm.comparator;
- final CellName excludedStart = sliceRestriction.isInclusive(Bound.START) ? null : type.makeCellName(sliceRestriction.bound(Bound.START, options));
- final CellName excludedEnd = sliceRestriction.isInclusive(Bound.END) ? null : type.makeCellName(sliceRestriction.bound(Bound.END, options));
++ final CellName excludedStart = makeExclusiveSliceBound(Bound.START, type, options);
++ final CellName excludedEnd = makeExclusiveSliceBound(Bound.END, type, options);
+
+ return new AbstractIterator<Cell>()
+ {
+ protected Cell computeNext()
+ {
+ while (cells.hasNext())
+ {
+ Cell c = cells.next();
+
+ // For dynamic CF, the column could be out of the requested bounds (because we don't support strict bounds internally (unless
+ // the comparator is composite that is)), filter here
+ if ( (excludedStart != null && type.compare(c.name(), excludedStart) == 0)
+ || (excludedEnd != null && type.compare(c.name(), excludedEnd) == 0) )
+ continue;
+
+ return c;
+ }
+ return endOfData();
+ }
+ };
+ }
+
+ private static Operator reverse(Operator op)
{
switch (op)
{