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 2015/03/05 19:35:11 UTC
[4/8] cassandra git commit: Merge branch 'cassandra-2.0' into
cassandra-2.1
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9c7a601b/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
index 25df030,e3ccba5..a4ee5d7
--- a/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
@@@ -17,65 -17,835 +17,221 @@@
*/
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)");
- }
-
- executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.multiple_clustering_with_indices (a int, b int, c int, d int, e int, PRIMARY KEY (a, b, c, d))");
- executeSchemaChange("CREATE INDEX ON %s.multiple_clustering_with_indices (b)");
- executeSchemaChange("CREATE INDEX ON %s.multiple_clustering_with_indices (e)");
-
- executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.partition_with_indices (a int, b int, c int, d int, e int, f int, PRIMARY KEY ((a, b), c, d, e))");
- executeSchemaChange("CREATE INDEX ON %s.partition_with_indices (c)");
- executeSchemaChange("CREATE INDEX ON %s.partition_with_indices (f)");
-
- clientState = ClientState.forInternalCalls();
- }
-
- @AfterClass
- public static void stopGossiper()
- {
- Gossiper.instance.stop();
- }
-
- private static void executeSchemaChange(String query) throws Throwable
+ @Test
+ public void testSingleClusteringInvalidQueries() throws Throwable
{
- try
- {
- process(String.format(query, keyspace), ConsistencyLevel.ONE);
- } catch (RuntimeException exc)
+ for (String compactOption : new String[]{"", " WITH COMPACT STORAGE"})
{
- throw exc.getCause();
+ createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY (a, b))" + compactOption);
+
+ 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);
++ assertInvalidMessage("Column \"b\" cannot be restricted by an equality relation and an inequality relation",
++ "SELECT * FROM %s WHERE a = 0 AND (b) = (?) AND (b) > (?)", 0, 0);
++ assertInvalidMessage("More than one restriction was found for the start bound on b",
++ "SELECT * FROM %s WHERE a = 0 AND (b) > (?) AND (b) > (?)", 0, 1);
++ assertInvalidMessage("Multi-column relations can only be applied to clustering columns: a",
++ "SELECT * FROM %s WHERE (a, b) = (?, ?)", 0, 0);
}
}
- private static UntypedResultSet execute(String query) throws Throwable
+ @Test
+ public void testMultiClusteringInvalidQueries() throws Throwable
{
- try
- {
- return processInternal(String.format(query, keyspace));
- } catch (RuntimeException exc)
+ for (String compactOption : new String[]{"", " WITH COMPACT STORAGE"})
{
- if (exc.getCause() != null)
- throw exc.getCause();
- throw exc;
+ createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c, d))" + compactOption);
+
+ 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);
++ assertInvalidMessage("Expected 2 elements in value tuple, but got 3: (?, ?, ?)",
++ "SELECT * FROM %s WHERE a = 0 AND (b, c) > (?, ?, ?)", 1, 2, 3);
++ assertInvalidMessage("Invalid null value in condition for column c",
++ "SELECT * FROM %s WHERE a = 0 AND (b, c) > (?, ?)", 1, null);
+
+ // 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);
++ assertInvalidMessage("Clustering columns must appear in the PRIMARY KEY order in multi-column relations: (d, c, b) = (?, ?, ?)",
++ "SELECT * FROM %s WHERE a = 0 AND (d, c, b) = (?, ?, ?)", 0, 0, 0);
++ assertInvalidMessage("Clustering columns must appear in the PRIMARY KEY order in multi-column relations: (d, c, b) > (?, ?, ?)",
++ "SELECT * FROM %s WHERE a = 0 AND (d, c, b) > (?, ?, ?)", 0, 0, 0);
+
+ // 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);
++ assertInvalidMessage("Expected 3 elements in value tuple, but got 2: (?, ?)",
++ "SELECT * FROM %s WHERE a=0 AND (b, c, d) IN ((?, ?))", 0, 1);
++ assertInvalidMessage("Expected 3 elements in value tuple, but got 5: (?, ?, ?, ?, ?)",
++ "SELECT * FROM %s WHERE a=0 AND (b, c, d) IN ((?, ?, ?, ?, ?))", 0, 1, 2, 3, 4);
+
+ // 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);
++ assertInvalidMessage("PRIMARY KEY column \"c\" cannot be restricted (preceding column \"b\" is not restricted)",
++ "SELECT * FROM %s WHERE a = 0 AND (c, d) = (?, ?)", 0, 0);
++ assertInvalidMessage("PRIMARY KEY column \"c\" cannot be restricted (preceding column \"b\" is not restricted)",
++ "SELECT * FROM %s WHERE a = 0 AND (c, d) > (?, ?)", 0, 0);
+
+ // Nulls
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c, d) IN ((?, ?, ?))", 1, 2, null);
++ assertInvalidMessage("Invalid null value in condition for column d",
++ "SELECT * FROM %s WHERE a = 0 AND (b, c, d) IN ((?, ?, ?))", 1, 2, null);
+
+ // Wrong type for 'd'
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c, d) = (?, ?, ?)", 1, 2, "foobar");
++ assertInvalidMessage("Expected 4 or 0 byte int (6)",
++ "SELECT * FROM %s WHERE a = 0 AND (b, c, d) = (?, ?, ?)", 1, 2, "foobar");
+
- assertInvalid("SELECT * FROM %s WHERE a = 0 AND b = (?, ?, ?)", 1, 2, 3);
++ assertInvalidMessage("Invalid tuple type literal for b of type int",
++ "SELECT * FROM %s WHERE a = 0 AND b = (?, ?, ?)", 1, 2, 3);
+
+ // 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);
++ assertInvalidMessage("Column \"b\" cannot be restricted by both a tuple notation inequality and a single column inequality (b < ?)",
++ "SELECT * FROM %s WHERE a = 0 AND (b, c, d) > (?, ?, ?) AND b < ?", 0, 1, 0, 1);
++ assertInvalidMessage("Column \"c\" cannot be restricted by both a tuple notation inequality and a single column inequality (c < ?)",
++ "SELECT * FROM %s WHERE a = 0 AND (b, c, d) > (?, ?, ?) AND c < ?", 0, 1, 0, 1);
++ assertInvalidMessage("Column \"b\" cannot have both tuple-notation inequalities and single-column inequalities: (b, c, d) < (?, ?, ?)",
++ "SELECT * FROM %s WHERE a = 0 AND b > ? AND (b, c, d) < (?, ?, ?)", 1, 1, 1, 0);
++ assertInvalidMessage("Column \"c\" cannot have both tuple-notation inequalities and single-column inequalities: (b, c, d) < (?, ?, ?)",
++ "SELECT * FROM %s WHERE a = 0 AND c > ? AND (b, c, d) < (?, ?, ?)", 1, 1, 1, 0);
++
++ assertInvalidMessage("Multi-column relations can only be applied to clustering columns: a",
++ "SELECT * FROM %s WHERE (a, b, c, d) IN ((?, ?, ?, ?))", 0, 1, 2, 3);
++ assertInvalidMessage("PRIMARY KEY column \"c\" cannot be restricted (preceding column \"b\" is not restricted)",
++ "SELECT * FROM %s WHERE (c, d) IN ((?, ?))", 0, 1);
++ assertInvalidMessage("PRIMARY KEY column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)",
++ "SELECT * FROM %s WHERE a = ? AND b > ? AND (c, d) IN ((?, ?))", 0, 0, 0, 0);
++
++ assertInvalidMessage("PRIMARY KEY column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)",
++ "SELECT * FROM %s WHERE a = ? AND b > ? AND (c, d) > (?, ?)", 0, 0, 0, 0);
++ assertInvalidMessage("PRIMARY KEY column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)",
++ "SELECT * FROM %s WHERE a = ? AND (c, d) > (?, ?) AND b > ? ", 0, 0, 0, 0);
++ assertInvalidMessage("Column \"c\" cannot be restricted by two tuple-notation inequalities not starting with the same column: (c) < (?)",
++ "SELECT * FROM %s WHERE a = ? AND (b, c) > (?, ?) AND (b) < (?) AND (c) < (?)", 0, 0, 0, 0, 0);
++ assertInvalidMessage("Column \"c\" cannot be restricted by two tuple-notation inequalities not starting with the same column: (b, c) > (?, ?)",
++ "SELECT * FROM %s WHERE a = ? AND (c) < (?) AND (b, c) > (?, ?) AND (b) < (?)", 0, 0, 0, 0, 0);
++ assertInvalidMessage("Column \"c\" cannot be restricted by two tuple-notation inequalities not starting with the same column: (b, c) > (?, ?)",
++ "SELECT * FROM %s WHERE a = ? AND (b) < (?) AND (c) < (?) AND (b, c) > (?, ?)", 0, 0, 0, 0, 0);
++
++ assertInvalidMessage("Column \"c\" cannot be restricted by two tuple-notation inequalities not starting with the same column: (c) < (?)",
++ "SELECT * FROM %s WHERE a = ? AND (b, c) > (?, ?) AND (c) < (?)", 0, 0, 0, 0);
++
++ assertInvalidMessage("PRIMARY KEY column \"d\" cannot be restricted (preceding column \"c\" is restricted by an IN tuple notation)",
++ "SELECT * FROM %s WHERE a = ? AND (b, c) in ((?, ?), (?, ?)) AND d > ?", 0, 0, 0, 0, 0, 0);
+ }
+ }
+
- 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=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
++ public void testMultiAndSingleColumnRelationMix() throws Throwable
+ {
- UntypedResultSet results = execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (b, c, d) IN ((1, 2, null))");
- assertTrue(results.isEmpty());
- }
++ for (String compactOption : new String[]{"", " WITH COMPACT STORAGE"})
++ {
++ createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c, d))" + compactOption);
+
- @Test(expected=InvalidRequestException.class)
- public void testPartitionKeyInequality() throws Throwable
- {
- execute("SELECT * FROM %s.single_partition WHERE (a) > (1)");
- }
++ 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);
+
- @Test(expected=InvalidRequestException.class)
- public void testPartitionKeyEquality() throws Throwable
- {
- execute("SELECT * FROM %s.single_partition WHERE (a) = (0)");
- }
++ 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);
+
- @Test(expected=InvalidRequestException.class)
- public void testRestrictNonPrimaryKey() throws Throwable
- {
- execute("SELECT * FROM %s.single_partition WHERE (b) = (0)");
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and b = ? and (c, d) = (?, ?)", 0, 1, 0, 0),
++ row(0, 1, 0, 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)");
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and b = ? and (c) IN ((?))", 0, 1, 0),
++ row(0, 1, 0, 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)");
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and b = ? and (c) IN ((?), (?))", 0, 1, 0, 1),
++ row(0, 1, 0, 0),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 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)");
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and b = ? and (c, d) IN ((?, ?))", 0, 1, 0, 0),
++ row(0, 1, 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)");
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and b = ? and (c, d) IN ((?, ?), (?, ?))", 0, 1, 0, 0, 1, 1),
++ row(0, 1, 0, 0),
++ row(0, 1, 1, 1));
+
- @Test(expected=InvalidRequestException.class)
- public void testSkipClusteringColumnInInequality() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND (c, d) > (0, 0)");
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and b = ? and (c, d) > (?, ?)", 0, 1, 0, 0),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 1));
+
- @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());
- }
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and b = ? and (c, d) > (?, ?) and (c) <= (?) ", 0, 1, 0, 0, 1),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 1));
+
- @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");
- }
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and b = ? and (c, d) >= (?, ?) and (c, d) < (?, ?)", 0, 1, 0, 0, 1, 1),
++ row(0, 1, 0, 0),
++ row(0, 1, 1, 0));
+
- @Test(expected=InvalidRequestException.class)
- public void testPartitionAndClusteringColumnEquality() throws Throwable
- {
- execute("SELECT * FROM %s.single_clustering WHERE (a, b) = (0, 0)");
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b, c) = (?, ?) and d = ?", 0, 0, 1, 0),
++ row(0, 0, 1, 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)");
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and b = ? and (c) = (?) and d = ?", 0, 0, 1, 0),
++ row(0, 0, 1, 0));
+
- @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')");
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b, c) = (?, ?) and d IN (?, ?)", 0, 0, 1, 0, 2),
++ row(0, 0, 1, 0));
+
- @Test(expected=SyntaxException.class)
- public void testSingleColumnTupleRelation() throws Throwable
- {
- execute("SELECT * FROM %s.multiple_clustering WHERE a=0 AND b = (1, 2, 3)");
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and b = ? and (c) = (?) and d IN (?, ?)", 0, 0, 1, 0, 2),
++ row(0, 0, 1, 0));
+
- @Test
- public void testInvalidMultiAndSingleColumnRelationMix() throws Throwable
- {
- for (String tableSuffix : new String[]{"", "_compact"})
- {
- 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)",
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE (a, b, c, d) IN ((0, 1, 2, 3))",
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE (c, d) IN ((0, 1))",
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a = 0 AND b > 0 AND (c, d) IN ((0, 0))",
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a = 0 AND b > 0 AND (c, d) > (0, 0)",
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a = 0 AND (c, d) > (0, 0) AND b > 0 ",
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a = 0 AND (b, c) > (0, 0) AND (b) < (0) AND (c) < (0)",
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a = 0 AND (c) < (0) AND (b, c) > (0, 0) AND (b) < (0)",
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a = 0 AND (b) < (0) AND (c) < (0) AND (b, c) > (0, 0)",
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a = 0 AND (b, c) > (0, 0) AND (c) < (0)",
- "SELECT * FROM %s.multiple_clustering" + tableSuffix + " WHERE a = 0 AND (b, c) in ((0, 0), (0, 0)) AND d > 0"
- };
-
- for (String query : queries)
- {
- try
- {
- execute(query);
- fail(String.format("Expected query \"%s\" to throw an InvalidRequestException", query));
- }
- catch (InvalidRequestException e)
- {
- }
- }
- }
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b, c) = (?, ?) and d >= ?", 0, 0, 1, 0),
++ row(0, 0, 1, 0),
++ row(0, 0, 1, 1));
+
- @Test
- public void testMultiAndSingleColumnRelationMix() 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)");
-
- 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 = 1 and (c, d) = (0, 0)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix
- + " WHERE a = 0 and b = 1 and (c) IN ((0))");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix
- + " WHERE a = 0 and b = 1 and (c) IN ((0), (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 = 1 and (c, d) IN ((0, 0))");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix
- + " WHERE a = 0 and b = 1 and (c, d) IN ((0, 0), (1, 1))");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix
- + " WHERE a = 0 and b = 1 and (c, d) > (0, 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 and (c, d) > (0, 0) and (c) <= (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 = 1 and (c, d) >= (0, 0) and (c, d) < (1, 1)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix
- + " WHERE a = 0 and (b, c) = (0, 1) and d = 0");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix
- + " WHERE a = 0 and b = 0 and (c) = (1) and d = 0");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix
- + " WHERE a = 0 and (b, c) = (0, 1) and d IN (0, 2)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix
- + " WHERE a = 0 and b = 0 and (c) = (1) and d IN (0, 2)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix
- + " WHERE a = 0 and (b, c) = (0, 1) and d >= 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 d < 1 and (b, c) = (0, 1) and d >= 0");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 0, 1, 0);
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and d < 1 and (b, c) = (?, ?) and d >= ?", 0, 0, 1, 0),
++ row(0, 0, 1, 0));
+ }
+ }
+
+ @Test
+ public void testMultipleMultiColumnRelation() throws Throwable
+ {
- 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) = (1) and (c, d) = (0, 0)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix
- + " WHERE a = 0 and (b) = (1) and (c) = (0) and (d) = (0)");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix
- + " WHERE a = 0 and (b) = (1) and (c) IN ((0))");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix
- + " WHERE a = 0 and (b) = (1) and (c) IN ((0), (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) = (1) and (c, d) IN ((0, 0))");
- assertEquals(1, results.size());
- checkRow(0, results, 0, 1, 0, 0);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix
- + " WHERE a = 0 and (b) = (1) and (c, d) IN ((0, 0), (1, 1))");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 1);
-
- results = execute("SELECT * FROM %s.multiple_clustering" + tableSuffix
- + " WHERE a = 0 and (b) = (1) and (c, d) > (0, 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) and (c, d) > (0, 0) and (c) <= (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) = (1) and (c, d) >= (0, 0) and (c, d) < (1, 1)");
- assertEquals(2, results.size());
- checkRow(0, results, 0, 1, 0, 0);
- checkRow(1, results, 0, 1, 1, 0);
- }
- }
++ createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c, d))" + 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);
- }
- }
++ 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);
+
- @Test
- public void testMultipleClusteringColumnInequality() 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)");
-
- 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);
++ 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);
+
- // 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);
- }
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b) = (?) and (c, d) = (?, ?)", 0, 1, 0, 0),
++ row(0, 1, 0, 0));
+
- @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);
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b) = (?) and (c) = (?) and (d) = (?)", 0, 1, 0, 0),
++ row(0, 1, 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());
- }
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b) = (?) and (c) IN ((?))", 0, 1, 0),
++ row(0, 1, 0, 0));
+
- @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)");
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b) = (?) and (c) IN ((?), (?))", 0, 1, 0, 1),
++ row(0, 1, 0, 0),
++ row(0, 1, 1, 0),
++ row(0, 1, 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);
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b) = (?) and (c, d) IN ((?, ?))", 0, 1, 0, 0),
++ row(0, 1, 0, 0));
+
- // 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);
- }
- }
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b) = (?) and (c, d) IN ((?, ?), (?, ?))", 0, 1, 0, 0, 1, 1),
++ row(0, 1, 0, 0),
++ row(0, 1, 1, 1));
+
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b) = (?) and (c, d) > (?, ?)", 0, 1, 0, 0),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 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)");
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b) = (?) and (c, d) > (?, ?) and (c) <= (?) ", 0, 1, 0, 0, 1),
++ row(0, 1, 1, 0),
++ row(0, 1, 1, 1));
- assertInvalid("SELECT * FROM %s WHERE (a, b, c, d) IN ((?, ?, ?, ?))", 0, 1, 2, 3);
- assertInvalid("SELECT * FROM %s WHERE (c, d) IN ((?, ?))", 0, 1);
- 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);
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b) = (?) and (c, d) >= (?, ?) and (c, d) < (?, ?)", 0, 1, 0, 0, 1, 1),
++ row(0, 1, 0, 0),
++ row(0, 1, 1, 0));
- assertInvalid("SELECT * FROM %s WHERE a = ? AND (b, c) in ((?, ?), (?, ?)) AND d > ?", 0, 0, 0, 0, 0, 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);
++ assertRows(execute("SELECT * FROM %s WHERE a = ? and (b, c) = (?, ?) and (d) = (?)", 0, 0, 1, 0),
++ row(0, 0, 1, 0));
}
}