You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jm...@apache.org on 2015/06/24 18:15:04 UTC
[11/32] cassandra git commit: 2.2 commit for CASSANDRA-9160
http://git-wip-us.apache.org/repos/asf/cassandra/blob/01115f72/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
new file mode 100644
index 0000000..506bdaf
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
@@ -0,0 +1,1336 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.cql3.validation.operations;
+
+import java.nio.ByteBuffer;
+import java.util.UUID;
+
+import org.junit.Test;
+
+import junit.framework.Assert;
+import org.apache.cassandra.cql3.UntypedResultSet;
+import org.apache.cassandra.cql3.CQLTester;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test column ranges and ordering with static column in table
+ */
+public class SelectTest extends CQLTester
+{
+ @Test
+ public void testSingleClustering() throws Throwable
+ {
+ createTable("CREATE TABLE %s (p text, c text, v text, s text static, PRIMARY KEY (p, c))");
+
+ execute("INSERT INTO %s(p, c, v, s) values (?, ?, ?, ?)", "p1", "k1", "v1", "sv1");
+ execute("INSERT INTO %s(p, c, v) values (?, ?, ?)", "p1", "k2", "v2");
+ execute("INSERT INTO %s(p, s) values (?, ?)", "p2", "sv2");
+
+ assertRows(execute("SELECT * FROM %s WHERE p=?", "p1"),
+ row("p1", "k1", "sv1", "v1"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=?", "p2"),
+ row("p2", null, "sv2", null)
+ );
+
+ // Ascending order
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? ORDER BY c ASC", "p1"),
+ row("p1", "k1", "sv1", "v1"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? ORDER BY c ASC", "p2"),
+ row("p2", null, "sv2", null)
+ );
+
+ // Descending order
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? ORDER BY c DESC", "p1"),
+ row("p1", "k2", "sv1", "v2"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? ORDER BY c DESC", "p2"),
+ row("p2", null, "sv2", null)
+ );
+
+ // No order with one relation
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c>=?", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c>=?", "p1", "k2"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertEmpty(execute("SELECT * FROM %s WHERE p=? AND c>=?", "p1", "k3"));
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c =?", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c<=?", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertEmpty(execute("SELECT * FROM %s WHERE p=? AND c<=?", "p1", "k0"));
+
+ // Ascending with one relation
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c>=? ORDER BY c ASC", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c>=? ORDER BY c ASC", "p1", "k2"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertEmpty(execute("SELECT * FROM %s WHERE p=? AND c>=? ORDER BY c ASC", "p1", "k3"));
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c =? ORDER BY c ASC", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c<=? ORDER BY c ASC", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertEmpty(execute("SELECT * FROM %s WHERE p=? AND c<=? ORDER BY c ASC", "p1", "k0"));
+
+ // Descending with one relation
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c>=? ORDER BY c DESC", "p1", "k1"),
+ row("p1", "k2", "sv1", "v2"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c>=? ORDER BY c DESC", "p1", "k2"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertEmpty(execute("SELECT * FROM %s WHERE p=? AND c>=? ORDER BY c DESC", "p1", "k3"));
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c =? ORDER BY c DESC", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c<=? ORDER BY c DESC", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertEmpty(execute("SELECT * FROM %s WHERE p=? AND c<=? ORDER BY c DESC", "p1", "k0"));
+
+ // IN
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c IN (?, ?)", "p1", "k1", "k2"),
+ row("p1", "k1", "sv1", "v1"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c IN (?, ?) ORDER BY c ASC", "p1", "k1", "k2"),
+ row("p1", "k1", "sv1", "v1"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c IN (?, ?) ORDER BY c DESC", "p1", "k1", "k2"),
+ row("p1", "k2", "sv1", "v2"),
+ row("p1", "k1", "sv1", "v1")
+ );
+ }
+
+ @Test
+ public void testSingleClusteringReversed() throws Throwable
+ {
+ createTable("CREATE TABLE %s (p text, c text, v text, s text static, PRIMARY KEY (p, c)) WITH CLUSTERING ORDER BY (c DESC)");
+
+ execute("INSERT INTO %s(p, c, v, s) values (?, ?, ?, ?)", "p1", "k1", "v1", "sv1");
+ execute("INSERT INTO %s(p, c, v) values (?, ?, ?)", "p1", "k2", "v2");
+ execute("INSERT INTO %s(p, s) values (?, ?)", "p2", "sv2");
+
+ assertRows(execute("SELECT * FROM %s WHERE p=?", "p1"),
+ row("p1", "k2", "sv1", "v2"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=?", "p2"),
+ row("p2", null, "sv2", null)
+ );
+
+ // Ascending order
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? ORDER BY c ASC", "p1"),
+ row("p1", "k1", "sv1", "v1"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? ORDER BY c ASC", "p2"),
+ row("p2", null, "sv2", null)
+ );
+
+ // Descending order
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? ORDER BY c DESC", "p1"),
+ row("p1", "k2", "sv1", "v2"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? ORDER BY c DESC", "p2"),
+ row("p2", null, "sv2", null)
+ );
+
+ // No order with one relation
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c>=?", "p1", "k1"),
+ row("p1", "k2", "sv1", "v2"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c>=?", "p1", "k2"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertEmpty(execute("SELECT * FROM %s WHERE p=? AND c>=?", "p1", "k3"));
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c=?", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c<=?", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertEmpty(execute("SELECT * FROM %s WHERE p=? AND c<=?", "p1", "k0"));
+
+ // Ascending with one relation
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c>=? ORDER BY c ASC", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c>=? ORDER BY c ASC", "p1", "k2"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertEmpty(execute("SELECT * FROM %s WHERE p=? AND c>=? ORDER BY c ASC", "p1", "k3"));
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c=? ORDER BY c ASC", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c<=? ORDER BY c ASC", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertEmpty(execute("SELECT * FROM %s WHERE p=? AND c<=? ORDER BY c ASC", "p1", "k0"));
+
+ // Descending with one relation
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c>=? ORDER BY c DESC", "p1", "k1"),
+ row("p1", "k2", "sv1", "v2"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c>=? ORDER BY c DESC", "p1", "k2"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertEmpty(execute("SELECT * FROM %s WHERE p=? AND c>=? ORDER BY c DESC", "p1", "k3"));
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c=? ORDER BY c DESC", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c<=? ORDER BY c DESC", "p1", "k1"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertEmpty(execute("SELECT * FROM %s WHERE p=? AND c<=? ORDER BY c DESC", "p1", "k0"));
+
+ // IN
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c IN (?, ?)", "p1", "k1", "k2"),
+ row("p1", "k2", "sv1", "v2"),
+ row("p1", "k1", "sv1", "v1")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c IN (?, ?) ORDER BY c ASC", "p1", "k1", "k2"),
+ row("p1", "k1", "sv1", "v1"),
+ row("p1", "k2", "sv1", "v2")
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE p=? AND c IN (?, ?) ORDER BY c DESC", "p1", "k1", "k2"),
+ row("p1", "k2", "sv1", "v2"),
+ row("p1", "k1", "sv1", "v1")
+ );
+ }
+
+ /**
+ * Check query with KEY IN clause
+ * migrated from cql_tests.py:TestCQL.select_key_in_test()
+ */
+ @Test
+ public void testSelectKeyIn() throws Throwable
+ {
+ createTable("CREATE TABLE %s (userid uuid PRIMARY KEY, firstname text, lastname text, age int)");
+
+ UUID id1 = UUID.fromString("550e8400-e29b-41d4-a716-446655440000");
+ UUID id2 = UUID.fromString("f47ac10b-58cc-4372-a567-0e02b2c3d479");
+
+ execute("INSERT INTO %s (userid, firstname, lastname, age) VALUES (?, 'Frodo', 'Baggins', 32)", id1);
+ execute("INSERT INTO %s (userid, firstname, lastname, age) VALUES (?, 'Samwise', 'Gamgee', 33)", id2);
+
+ assertRowCount(execute("SELECT firstname, lastname FROM %s WHERE userid IN (?, ?)", id1, id2), 2);
+ }
+
+ /**
+ * Check query with KEY IN clause for wide row tables
+ * migrated from cql_tests.py:TestCQL.in_clause_wide_rows_test()
+ */
+ @Test
+ public void testSelectKeyInForWideRows() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int, c int, v int, PRIMARY KEY (k, c)) WITH COMPACT STORAGE");
+
+ for (int i = 0; i < 10; i++)
+ execute("INSERT INTO %s (k, c, v) VALUES (0, ?, ?)", i, i);
+
+ assertRows(execute("SELECT v FROM %s WHERE k = 0 AND c IN (5, 2, 8)"),
+ row(2), row(5), row(8));
+
+ createTable("CREATE TABLE %s (k int, c1 int, c2 int, v int, PRIMARY KEY (k, c1, c2)) WITH COMPACT STORAGE");
+
+ for (int i = 0; i < 10; i++)
+ execute("INSERT INTO %s (k, c1, c2, v) VALUES (0, 0, ?, ?)", i, i);
+
+ assertEmpty(execute("SELECT v FROM %s WHERE k = 0 AND c1 IN (5, 2, 8) AND c2 = 3"));
+
+ assertRows(execute("SELECT v FROM %s WHERE k = 0 AND c1 = 0 AND c2 IN (5, 2, 8)"),
+ row(2), row(5), row(8));
+ }
+
+ /**
+ * Check SELECT respects inclusive and exclusive bounds
+ * migrated from cql_tests.py:TestCQL.exclusive_slice_test()
+ */
+ @Test
+ public void testSelectBounds() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int, c int, v int, PRIMARY KEY (k, c)) WITH COMPACT STORAGE");
+
+ for (int i = 0; i < 10; i++)
+ execute("INSERT INTO %s (k, c, v) VALUES (0, ?, ?)", i, i);
+
+ assertRowCount(execute("SELECT v FROM %s WHERE k = 0"), 10);
+
+ assertRows(execute("SELECT v FROM %s WHERE k = 0 AND c >= 2 AND c <= 6"),
+ row(2), row(3), row(4), row(5), row(6));
+
+ assertRows(execute("SELECT v FROM %s WHERE k = 0 AND c > 2 AND c <= 6"),
+ row(3), row(4), row(5), row(6));
+
+ assertRows(execute("SELECT v FROM %s WHERE k = 0 AND c >= 2 AND c < 6"),
+ row(2), row(3), row(4), row(5));
+
+ assertRows(execute("SELECT v FROM %s WHERE k = 0 AND c > 2 AND c < 6"),
+ row(3), row(4), row(5));
+
+ assertRows(execute("SELECT v FROM %s WHERE k = 0 AND c > 2 AND c <= 6 LIMIT 2"),
+ row(3), row(4));
+
+ assertRows(execute("SELECT v FROM %s WHERE k = 0 AND c >= 2 AND c < 6 ORDER BY c DESC LIMIT 2"),
+ row(5), row(4));
+ }
+
+ @Test
+ public void testSetContains() throws Throwable
+ {
+ createTable("CREATE TABLE %s (account text, id int, categories set<text>, PRIMARY KEY (account, id))");
+ createIndex("CREATE INDEX ON %s(categories)");
+
+ execute("INSERT INTO %s (account, id , categories) VALUES (?, ?, ?)", "test", 5, set("lmn"));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS ?", "xyz", "lmn"));
+
+ assertRows(execute("SELECT * FROM %s WHERE categories CONTAINS ?", "lmn"),
+ row("test", 5, set("lmn"))
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS ?", "test", "lmn"),
+ row("test", 5, set("lmn"))
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS ?", "test", 5, "lmn"),
+ row("test", 5, set("lmn"))
+ );
+
+ assertInvalidMessage("Unsupported null value for indexed column categories",
+ "SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS ?", "test", 5, null);
+
+ assertInvalidMessage("Unsupported unset value for indexed column categories",
+ "SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS ?", "test", 5, unset());
+
+ assertInvalidMessage("Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING",
+ "SELECT * FROM %s WHERE account = ? AND categories CONTAINS ? AND categories CONTAINS ?", "xyz", "lmn", "notPresent");
+ assertEmpty(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS ? AND categories CONTAINS ? ALLOW FILTERING", "xyz", "lmn", "notPresent"));
+ }
+
+ @Test
+ public void testListContains() throws Throwable
+ {
+ createTable("CREATE TABLE %s (account text, id int, categories list<text>, PRIMARY KEY (account, id))");
+ createIndex("CREATE INDEX ON %s(categories)");
+
+ execute("INSERT INTO %s (account, id , categories) VALUES (?, ?, ?)", "test", 5, list("lmn"));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS ?", "xyz", "lmn"));
+
+ assertRows(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS ?;", "test", "lmn"),
+ row("test", 5, list("lmn"))
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE categories CONTAINS ?", "lmn"),
+ row("test", 5, list("lmn"))
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS ?;", "test", 5, "lmn"),
+ row("test", 5, list("lmn"))
+ );
+
+ assertInvalidMessage("Unsupported null value for indexed column categories",
+ "SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS ?", "test", 5, null);
+
+ assertInvalidMessage("Unsupported unset value for indexed column categories",
+ "SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS ?", "test", 5, unset());
+
+ assertInvalidMessage("Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING",
+ "SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS ? AND categories CONTAINS ?",
+ "test", 5, "lmn", "notPresent");
+ assertEmpty(execute("SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS ? AND categories CONTAINS ? ALLOW FILTERING",
+ "test", 5, "lmn", "notPresent"));
+ }
+
+ @Test
+ public void testListContainsWithFiltering() throws Throwable
+ {
+ createTable("CREATE TABLE %s (e int PRIMARY KEY, f list<text>, s int)");
+ createIndex("CREATE INDEX ON %s(f)");
+ for(int i = 0; i < 3; i++)
+ {
+ execute("INSERT INTO %s (e, f, s) VALUES (?, ?, ?)", i, list("Dubai"), 4);
+ }
+ for(int i = 3; i < 5; i++)
+ {
+ execute("INSERT INTO %s (e, f, s) VALUES (?, ?, ?)", i, list("Dubai"), 3);
+ }
+ assertRows(execute("SELECT * FROM %s WHERE f CONTAINS ? AND s=? allow filtering", "Dubai", 3),
+ row(4, list("Dubai"), 3),
+ row(3, list("Dubai"), 3));
+ }
+
+ @Test
+ public void testMapKeyContains() throws Throwable
+ {
+ createTable("CREATE TABLE %s (account text, id int, categories map<text,text>, PRIMARY KEY (account, id))");
+ createIndex("CREATE INDEX ON %s(keys(categories))");
+
+ execute("INSERT INTO %s (account, id , categories) VALUES (?, ?, ?)", "test", 5, map("lmn", "foo"));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS KEY ?", "xyz", "lmn"));
+
+ assertRows(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS KEY ?", "test", "lmn"),
+ row("test", 5, map("lmn", "foo"))
+ );
+ assertRows(execute("SELECT * FROM %s WHERE categories CONTAINS KEY ?", "lmn"),
+ row("test", 5, map("lmn", "foo"))
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS KEY ?", "test", 5, "lmn"),
+ row("test", 5, map("lmn", "foo"))
+ );
+
+ assertInvalidMessage("Unsupported null value for indexed column categories",
+ "SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS KEY ?", "test", 5, null);
+
+ assertInvalidMessage("Unsupported unset value for indexed column categories",
+ "SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS KEY ?", "test", 5, unset());
+
+ assertInvalidMessage("Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING",
+ "SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS KEY ? AND categories CONTAINS KEY ?",
+ "test", 5, "lmn", "notPresent");
+ assertEmpty(execute("SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS KEY ? AND categories CONTAINS KEY ? ALLOW FILTERING",
+ "test", 5, "lmn", "notPresent"));
+
+ assertInvalidMessage("Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING",
+ "SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS KEY ? AND categories CONTAINS ?",
+ "test", 5, "lmn", "foo");
+ }
+
+ @Test
+ public void testMapValueContains() throws Throwable
+ {
+ createTable("CREATE TABLE %s (account text, id int, categories map<text,text>, PRIMARY KEY (account, id))");
+ createIndex("CREATE INDEX ON %s(categories)");
+
+ execute("INSERT INTO %s (account, id , categories) VALUES (?, ?, ?)", "test", 5, map("lmn", "foo"));
+
+ assertEmpty(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS ?", "xyz", "foo"));
+
+ assertRows(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS ?", "test", "foo"),
+ row("test", 5, map("lmn", "foo"))
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE categories CONTAINS ?", "foo"),
+ row("test", 5, map("lmn", "foo"))
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS ?", "test", 5, "foo"),
+ row("test", 5, map("lmn", "foo"))
+ );
+
+ assertInvalidMessage("Unsupported null value for indexed column categories",
+ "SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS ?", "test", 5, null);
+
+ assertInvalidMessage("Unsupported unset value for indexed column categories",
+ "SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS ?", "test", 5, unset());
+
+ assertInvalidMessage("Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING",
+ "SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS ? AND categories CONTAINS ?"
+ , "test", 5, "foo", "notPresent");
+
+ assertEmpty(execute("SELECT * FROM %s WHERE account = ? AND id = ? AND categories CONTAINS ? AND categories CONTAINS ? ALLOW FILTERING"
+ , "test", 5, "foo", "notPresent"));
+ }
+
+ // See CASSANDRA-7525
+ @Test
+ public void testQueryMultipleIndexTypes() throws Throwable
+ {
+ createTable("CREATE TABLE %s (account text, id int, categories map<text,text>, PRIMARY KEY (account, id))");
+
+ // create an index on
+ createIndex("CREATE INDEX id_index ON %s(id)");
+ createIndex("CREATE INDEX categories_values_index ON %s(categories)");
+
+ execute("INSERT INTO %s (account, id , categories) VALUES (?, ?, ?)", "test", 5, map("lmn", "foo"));
+
+ assertRows(execute("SELECT * FROM %s WHERE categories CONTAINS ? AND id = ? ALLOW FILTERING", "foo", 5),
+ row("test", 5, map("lmn", "foo"))
+ );
+
+ assertRows(
+ execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS ? AND id = ? ALLOW FILTERING", "test", "foo", 5),
+ row("test", 5, map("lmn", "foo"))
+ );
+ }
+
+ // See CASSANDRA-8033
+ @Test
+ public void testFilterForContains() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k1 int, k2 int, v set<int>, PRIMARY KEY ((k1, k2)))");
+ createIndex("CREATE INDEX ON %s(k2)");
+
+ execute("INSERT INTO %s (k1, k2, v) VALUES (?, ?, ?)", 0, 0, set(1, 2, 3));
+ execute("INSERT INTO %s (k1, k2, v) VALUES (?, ?, ?)", 0, 1, set(2, 3, 4));
+ execute("INSERT INTO %s (k1, k2, v) VALUES (?, ?, ?)", 1, 0, set(3, 4, 5));
+ execute("INSERT INTO %s (k1, k2, v) VALUES (?, ?, ?)", 1, 1, set(4, 5, 6));
+
+ assertRows(execute("SELECT * FROM %s WHERE k2 = ?", 1),
+ row(0, 1, set(2, 3, 4)),
+ row(1, 1, set(4, 5, 6))
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE k2 = ? AND v CONTAINS ? ALLOW FILTERING", 1, 6),
+ row(1, 1, set(4, 5, 6))
+ );
+
+ assertEmpty(execute("SELECT * FROM %s WHERE k2 = ? AND v CONTAINS ? ALLOW FILTERING", 1, 7));
+ }
+
+ // See CASSANDRA-8073
+ @Test
+ public void testIndexLookupWithClusteringPrefix() throws Throwable
+ {
+ createTable("CREATE TABLE %s (a int, b int, c int, d set<int>, PRIMARY KEY (a, b, c))");
+ createIndex("CREATE INDEX ON %s(d)");
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, set(1, 2, 3));
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, set(3, 4, 5));
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 0, set(1, 2, 3));
+ execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 1, set(3, 4, 5));
+
+ assertRows(execute("SELECT * FROM %s WHERE a=? AND b=? AND d CONTAINS ?", 0, 1, 3),
+ row(0, 1, 0, set(1, 2, 3)),
+ row(0, 1, 1, set(3, 4, 5))
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE a=? AND b=? AND d CONTAINS ?", 0, 1, 2),
+ row(0, 1, 0, set(1, 2, 3))
+ );
+
+ assertRows(execute("SELECT * FROM %s WHERE a=? AND b=? AND d CONTAINS ?", 0, 1, 5),
+ row(0, 1, 1, set(3, 4, 5))
+ );
+ }
+
+ @Test
+ public void testContainsKeyAndContainsWithIndexOnMapKey() throws Throwable
+ {
+ createTable("CREATE TABLE %s (account text, id int, categories map<text,text>, PRIMARY KEY (account, id))");
+ createIndex("CREATE INDEX ON %s(keys(categories))");
+
+ execute("INSERT INTO %s (account, id , categories) VALUES (?, ?, ?)", "test", 5, map("lmn", "foo"));
+ execute("INSERT INTO %s (account, id , categories) VALUES (?, ?, ?)", "test", 6, map("lmn", "foo2"));
+
+ assertInvalidMessage("No secondary indexes on the restricted columns support the provided operators: 'categories CONTAINS <value>'",
+ "SELECT * FROM %s WHERE account = ? AND categories CONTAINS ?", "test", "foo");
+
+ assertRows(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS KEY ?", "test", "lmn"),
+ row("test", 5, map("lmn", "foo")),
+ row("test", 6, map("lmn", "foo2")));
+ assertRows(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS KEY ? AND categories CONTAINS ? ALLOW FILTERING",
+ "test", "lmn", "foo"),
+ row("test", 5, map("lmn", "foo")));
+ assertRows(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS ? AND categories CONTAINS KEY ? ALLOW FILTERING",
+ "test", "foo", "lmn"),
+ row("test", 5, map("lmn", "foo")));
+ }
+
+ @Test
+ public void testContainsKeyAndContainsWithIndexOnMapValue() throws Throwable
+ {
+ createTable("CREATE TABLE %s (account text, id int, categories map<text,text>, PRIMARY KEY (account, id))");
+ createIndex("CREATE INDEX ON %s(categories)");
+
+ execute("INSERT INTO %s (account, id , categories) VALUES (?, ?, ?)", "test", 5, map("lmn", "foo"));
+ execute("INSERT INTO %s (account, id , categories) VALUES (?, ?, ?)", "test", 6, map("lmn2", "foo"));
+
+ assertInvalidMessage("No secondary indexes on the restricted columns support the provided operators: 'categories CONTAINS KEY <value>'",
+ "SELECT * FROM %s WHERE account = ? AND categories CONTAINS KEY ?", "test", "lmn");
+
+ assertRows(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS ?", "test", "foo"),
+ row("test", 5, map("lmn", "foo")),
+ row("test", 6, map("lmn2", "foo")));
+ assertRows(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS KEY ? AND categories CONTAINS ? ALLOW FILTERING",
+ "test", "lmn", "foo"),
+ row("test", 5, map("lmn", "foo")));
+ assertRows(execute("SELECT * FROM %s WHERE account = ? AND categories CONTAINS ? AND categories CONTAINS KEY ? ALLOW FILTERING",
+ "test", "foo", "lmn"),
+ row("test", 5, map("lmn", "foo")));
+ }
+
+ /**
+ * Test token ranges
+ * migrated from cql_tests.py:TestCQL.token_range_test()
+ */
+ @Test
+ public void testTokenRange() throws Throwable
+ {
+ createTable(" CREATE TABLE %s (k int PRIMARY KEY, c int, v int)");
+
+ int c = 100;
+ for (int i = 0; i < c; i++)
+ execute("INSERT INTO %s (k, c, v) VALUES (?, ?, ?)", i, i, i);
+
+ Object[][] res = getRows(execute("SELECT k FROM %s"));
+ assertEquals(c, res.length);
+
+ Object[] inOrder = new Object[res.length];
+ for (int i = 0; i < res.length; i++)
+ inOrder[i] = res[i][0];
+
+ Long min_token = Long.MIN_VALUE;
+
+ res = getRows(execute(String.format("SELECT k FROM %s.%s WHERE token(k) >= %d",
+ keyspace(), currentTable(), min_token)));
+ assertEquals(c, res.length);
+
+ res = getRows(execute(String.format("SELECT k FROM %s.%s WHERE token(k) >= token(%d) AND token(k) < token(%d)",
+ keyspace(), currentTable(), inOrder[32], inOrder[65])));
+
+ for (int i = 32; i < 65; i++)
+ Assert.assertEquals(inOrder[i], res[i - 32][0]);
+ }
+
+ /**
+ * Test select count
+ * migrated from cql_tests.py:TestCQL.count_test()
+ */
+ @Test
+ public void testSelectCount() throws Throwable
+ {
+ createTable(" CREATE TABLE %s (kind text, time int, value1 int, value2 int, PRIMARY KEY(kind, time))");
+
+ execute("INSERT INTO %s (kind, time, value1, value2) VALUES ('ev1', ?, ?, ?)", 0, 0, 0);
+ execute("INSERT INTO %s (kind, time, value1, value2) VALUES ('ev1', ?, ?, ?)", 1, 1, 1);
+ execute("INSERT INTO %s (kind, time, value1) VALUES ('ev1', ?, ?)", 2, 2);
+ execute("INSERT INTO %s (kind, time, value1, value2) VALUES ('ev1', ?, ?, ?)", 3, 3, 3);
+ execute("INSERT INTO %s (kind, time, value1) VALUES ('ev1', ?, ?)", 4, 4);
+ execute("INSERT INTO %s (kind, time, value1, value2) VALUES ('ev2', 0, 0, 0)");
+
+ assertRows(execute("SELECT COUNT(*) FROM %s WHERE kind = 'ev1'"),
+ row(5L));
+
+ assertRows(execute("SELECT COUNT(1) FROM %s WHERE kind IN ('ev1', 'ev2') AND time=0"),
+ row(2L));
+ }
+
+ /**
+ * Range test query from #4372
+ * migrated from cql_tests.py:TestCQL.range_query_test()
+ */
+ @Test
+ public void testRangeQuery() throws Throwable
+ {
+ createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, f text, PRIMARY KEY (a, b, c, d, e) )");
+
+ execute("INSERT INTO %s (a, b, c, d, e, f) VALUES (1, 1, 1, 1, 2, '2')");
+ execute("INSERT INTO %s (a, b, c, d, e, f) VALUES (1, 1, 1, 1, 1, '1')");
+ execute("INSERT INTO %s (a, b, c, d, e, f) VALUES (1, 1, 1, 2, 1, '1')");
+ execute("INSERT INTO %s (a, b, c, d, e, f) VALUES (1, 1, 1, 1, 3, '3')");
+ execute("INSERT INTO %s (a, b, c, d, e, f) VALUES (1, 1, 1, 1, 5, '5')");
+
+ assertRows(execute("SELECT a, b, c, d, e, f FROM %s WHERE a = 1 AND b = 1 AND c = 1 AND d = 1 AND e >= 2"),
+ row(1, 1, 1, 1, 2, "2"),
+ row(1, 1, 1, 1, 3, "3"),
+ row(1, 1, 1, 1, 5, "5"));
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.composite_row_key_test()
+ */
+ @Test
+ public void testCompositeRowKey() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k1 int, k2 int, c int, v int, PRIMARY KEY ((k1, k2), c))");
+
+ for (int i = 0; i < 4; i++)
+ execute("INSERT INTO %s (k1, k2, c, v) VALUES (?, ?, ?, ?)", 0, i, i, i);
+
+ assertRows(execute("SELECT * FROM %s"),
+ row(0, 2, 2, 2),
+ row(0, 3, 3, 3),
+ row(0, 0, 0, 0),
+ row(0, 1, 1, 1));
+
+ assertRows(execute("SELECT * FROM %s WHERE k1 = 0 and k2 IN (1, 3)"),
+ row(0, 1, 1, 1),
+ row(0, 3, 3, 3));
+
+ assertInvalid("SELECT * FROM %s WHERE k2 = 3");
+
+ assertRows(execute("SELECT * FROM %s WHERE token(k1, k2) = token(0, 1)"),
+ row(0, 1, 1, 1));
+
+
+ assertRows(execute("SELECT * FROM %s WHERE token(k1, k2) > ?", Long.MIN_VALUE),
+ row(0, 2, 2, 2),
+ row(0, 3, 3, 3),
+ row(0, 0, 0, 0),
+ row(0, 1, 1, 1));
+ }
+
+ /**
+ * Test for #4532, NPE when trying to select a slice from a composite table
+ * migrated from cql_tests.py:TestCQL.bug_4532_test()
+ */
+ @Test
+ public void testSelectSliceFromComposite() throws Throwable
+ {
+ createTable("CREATE TABLE %s (status ascii, ctime bigint, key ascii, nil ascii, PRIMARY KEY (status, ctime, key))");
+
+ execute("INSERT INTO %s (status,ctime,key,nil) VALUES ('C',12345678,'key1','')");
+ execute("INSERT INTO %s (status,ctime,key,nil) VALUES ('C',12345678,'key2','')");
+ execute("INSERT INTO %s (status,ctime,key,nil) VALUES ('C',12345679,'key3','')");
+ execute("INSERT INTO %s (status,ctime,key,nil) VALUES ('C',12345679,'key4','')");
+ execute("INSERT INTO %s (status,ctime,key,nil) VALUES ('C',12345679,'key5','')");
+ execute("INSERT INTO %s (status,ctime,key,nil) VALUES ('C',12345680,'key6','')");
+
+ assertInvalid("SELECT * FROM %s WHERE ctime>=12345679 AND key='key3' AND ctime<=12345680 LIMIT 3;");
+ assertInvalid("SELECT * FROM %s WHERE ctime=12345679 AND key='key3' AND ctime<=12345680 LIMIT 3");
+ }
+
+ /**
+ * Test for #4716 bug and more generally for good behavior of ordering,
+ * migrated from cql_tests.py:TestCQL.reversed_compact_test()
+ */
+ @Test
+ public void testReverseCompact() throws Throwable
+ {
+ createTable("CREATE TABLE %s ( k text, c int, v int, PRIMARY KEY (k, c) ) WITH COMPACT STORAGE AND CLUSTERING ORDER BY (c DESC)");
+
+ for (int i = 0; i < 10; i++)
+ execute("INSERT INTO %s (k, c, v) VALUES ('foo', ?, ?)", i, i);
+
+ assertRows(execute("SELECT c FROM %s WHERE c > 2 AND c < 6 AND k = 'foo'"),
+ row(5), row(4), row(3));
+
+ assertRows(execute("SELECT c FROM %s WHERE c >= 2 AND c <= 6 AND k = 'foo'"),
+ row(6), row(5), row(4), row(3), row(2));
+
+ assertRows(execute("SELECT c FROM %s WHERE c > 2 AND c < 6 AND k = 'foo' ORDER BY c ASC"),
+ row(3), row(4), row(5));
+
+ assertRows(execute("SELECT c FROM %s WHERE c >= 2 AND c <= 6 AND k = 'foo' ORDER BY c ASC"),
+ row(2), row(3), row(4), row(5), row(6));
+
+ assertRows(execute("SELECT c FROM %s WHERE c > 2 AND c < 6 AND k = 'foo' ORDER BY c DESC"),
+ row(5), row(4), row(3));
+
+ assertRows(execute("SELECT c FROM %s WHERE c >= 2 AND c <= 6 AND k = 'foo' ORDER BY c DESC"),
+ row(6), row(5), row(4), row(3), row(2));
+
+ createTable("CREATE TABLE %s ( k text, c int, v int, PRIMARY KEY (k, c) ) WITH COMPACT STORAGE");
+
+ for (int i = 0; i < 10; i++)
+ execute("INSERT INTO %s(k, c, v) VALUES ('foo', ?, ?)", i, i);
+
+ assertRows(execute("SELECT c FROM %s WHERE c > 2 AND c < 6 AND k = 'foo'"),
+ row(3), row(4), row(5));
+
+ assertRows(execute("SELECT c FROM %s WHERE c >= 2 AND c <= 6 AND k = 'foo'"),
+ row(2), row(3), row(4), row(5), row(6));
+
+ assertRows(execute("SELECT c FROM %s WHERE c > 2 AND c < 6 AND k = 'foo' ORDER BY c ASC"),
+ row(3), row(4), row(5));
+
+ assertRows(execute("SELECT c FROM %s WHERE c >= 2 AND c <= 6 AND k = 'foo' ORDER BY c ASC"),
+ row(2), row(3), row(4), row(5), row(6));
+
+ assertRows(execute("SELECT c FROM %s WHERE c > 2 AND c < 6 AND k = 'foo' ORDER BY c DESC"),
+ row(5), row(4), row(3));
+
+ assertRows(execute("SELECT c FROM %s WHERE c >= 2 AND c <= 6 AND k = 'foo' ORDER BY c DESC"),
+ row(6), row(5), row(4), row(3), row(2));
+ }
+
+ /**
+ * Test for the bug from #4760 and #4759,
+ * migrated from cql_tests.py:TestCQL.reversed_compact_multikey_test()
+ */
+ @Test
+ public void testReversedCompactMultikey() throws Throwable
+ {
+ createTable("CREATE TABLE %s (key text, c1 int, c2 int, value text, PRIMARY KEY(key, c1, c2) ) WITH COMPACT STORAGE AND CLUSTERING ORDER BY(c1 DESC, c2 DESC)");
+
+ for (int i = 0; i < 3; i++)
+ for (int j = 0; j < 3; j++)
+ execute("INSERT INTO %s (key, c1, c2, value) VALUES ('foo', ?, ?, 'bar')", i, j);
+
+ // Equalities
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 = 1"),
+ row(1, 2), row(1, 1), row(1, 0));
+
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 = 1 ORDER BY c1 ASC, c2 ASC"),
+ row(1, 0), row(1, 1), row(1, 2));
+
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 = 1 ORDER BY c1 DESC, c2 DESC"),
+ row(1, 2), row(1, 1), row(1, 0));
+
+ // GT
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 > 1"),
+ row(2, 2), row(2, 1), row(2, 0));
+
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 > 1 ORDER BY c1 ASC, c2 ASC"),
+ row(2, 0), row(2, 1), row(2, 2));
+
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 > 1 ORDER BY c1 DESC, c2 DESC"),
+ row(2, 2), row(2, 1), row(2, 0));
+
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 >= 1"),
+ row(2, 2), row(2, 1), row(2, 0), row(1, 2), row(1, 1), row(1, 0));
+
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 >= 1 ORDER BY c1 ASC, c2 ASC"),
+ row(1, 0), row(1, 1), row(1, 2), row(2, 0), row(2, 1), row(2, 2));
+
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 >= 1 ORDER BY c1 ASC"),
+ row(1, 0), row(1, 1), row(1, 2), row(2, 0), row(2, 1), row(2, 2));
+
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 >= 1 ORDER BY c1 DESC, c2 DESC"),
+ row(2, 2), row(2, 1), row(2, 0), row(1, 2), row(1, 1), row(1, 0));
+
+ // LT
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 < 1"),
+ row(0, 2), row(0, 1), row(0, 0));
+
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 < 1 ORDER BY c1 ASC, c2 ASC"),
+ row(0, 0), row(0, 1), row(0, 2));
+
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 < 1 ORDER BY c1 DESC, c2 DESC"),
+ row(0, 2), row(0, 1), row(0, 0));
+
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 <= 1"),
+ row(1, 2), row(1, 1), row(1, 0), row(0, 2), row(0, 1), row(0, 0));
+
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 <= 1 ORDER BY c1 ASC, c2 ASC"),
+ row(0, 0), row(0, 1), row(0, 2), row(1, 0), row(1, 1), row(1, 2));
+
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 <= 1 ORDER BY c1 ASC"),
+ row(0, 0), row(0, 1), row(0, 2), row(1, 0), row(1, 1), row(1, 2));
+
+ assertRows(execute("SELECT c1, c2 FROM %s WHERE key='foo' AND c1 <= 1 ORDER BY c1 DESC, c2 DESC"),
+ row(1, 2), row(1, 1), row(1, 0), row(0, 2), row(0, 1), row(0, 0));
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.bug_4882_test()
+ */
+ @Test
+ public void testDifferentOrdering() throws Throwable
+ {
+ createTable(" CREATE TABLE %s ( k int, c1 int, c2 int, v int, PRIMARY KEY (k, c1, c2) ) WITH CLUSTERING ORDER BY (c1 ASC, c2 DESC)");
+
+ execute("INSERT INTO %s (k, c1, c2, v) VALUES (0, 0, 0, 0)");
+ execute("INSERT INTO %s (k, c1, c2, v) VALUES (0, 1, 1, 1)");
+ execute("INSERT INTO %s (k, c1, c2, v) VALUES (0, 0, 2, 2)");
+ execute("INSERT INTO %s (k, c1, c2, v) VALUES (0, 1, 3, 3)");
+
+ assertRows(execute("select * from %s where k = 0 limit 1"),
+ row(0, 0, 2, 2));
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.allow_filtering_test()
+ */
+ @Test
+ public void testAllowFiltering() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int, c int, v int, PRIMARY KEY (k, c))");
+
+ for (int i = 0; i < 3; i++)
+ for (int j = 0; j < 3; j++)
+ execute("INSERT INTO %s (k, c, v) VALUES (?, ?, ?)", i, j, j);
+
+ // Don't require filtering, always allowed
+ String[] queries = new String[]
+ {
+ "SELECT * FROM %s WHERE k = 1",
+ "SELECT * FROM %s WHERE k = 1 AND c > 2",
+ "SELECT * FROM %s WHERE k = 1 AND c = 2"
+ };
+
+ for (String q : queries)
+ {
+ execute(q);
+ execute(q + " ALLOW FILTERING");
+ }
+
+ // Require filtering, allowed only with ALLOW FILTERING
+ queries = new String[]
+ {
+ "SELECT * FROM %s WHERE c = 2",
+ "SELECT * FROM %s WHERE c > 2 AND c <= 4"
+ };
+
+ for (String q : queries)
+ {
+ assertInvalid(q);
+ execute(q + " ALLOW FILTERING");
+ }
+
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, a int, b int,)");
+ createIndex("CREATE INDEX ON %s (a)");
+
+ for (int i = 0; i < 5; i++)
+ execute("INSERT INTO %s (k, a, b) VALUES (?, ?, ?)", i, i * 10, i * 100);
+
+ // Don't require filtering, always allowed
+ queries = new String[]
+ {
+ "SELECT * FROM %s WHERE k = 1",
+ "SELECT * FROM %s WHERE a = 20"
+ };
+
+ for (String q : queries)
+ {
+ execute(q);
+ execute(q + " ALLOW FILTERING");
+ }
+
+ // Require filtering, allowed only with ALLOW FILTERING
+ queries = new String[]
+ {
+ "SELECT * FROM %s WHERE a = 20 AND b = 200"
+ };
+
+ for (String q : queries)
+ {
+ assertInvalid(q);
+ execute(q + " ALLOW FILTERING");
+ }
+ }
+
+ /**
+ * Test for bug from #5122,
+ * migrated from cql_tests.py:TestCQL.composite_partition_key_validation_test()
+ */
+ @Test
+ public void testSelectOnCompositeInvalid() throws Throwable
+ {
+ createTable("CREATE TABLE %s (a int, b text, c uuid, PRIMARY KEY ((a, b)))");
+
+ execute("INSERT INTO %s (a, b , c ) VALUES (1, 'aze', 4d481800-4c5f-11e1-82e0-3f484de45426)");
+ execute("INSERT INTO %s (a, b , c ) VALUES (1, 'ert', 693f5800-8acb-11e3-82e0-3f484de45426)");
+ execute("INSERT INTO %s (a, b , c ) VALUES (1, 'opl', d4815800-2d8d-11e0-82e0-3f484de45426)");
+
+ assertRowCount(execute("SELECT * FROM %s"), 3);
+ assertInvalid("SELECT * FROM %s WHERE a=1");
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.multi_in_test()
+ */
+ @Test
+ public void testMultiSelects() throws Throwable
+ {
+ doTestVariousSelects(false);
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.multi_in_compact_test()
+ */
+ @Test
+ public void testMultiSelectsCompactStorage() throws Throwable
+ {
+ doTestVariousSelects(true);
+ }
+
+
+ public void doTestVariousSelects(boolean compact) throws Throwable
+ {
+ createTable(
+ "CREATE TABLE %s (group text, zipcode text, state text, fips_regions int, city text, PRIMARY KEY (group, zipcode, state, fips_regions))"
+ + (compact
+ ? " WITH COMPACT STORAGE"
+ : ""));
+
+ String str = "INSERT INTO %s (group, zipcode, state, fips_regions, city) VALUES (?, ?, ?, ?, ?)";
+ execute(str, "test", "06029", "CT", 9, "Ellington");
+ execute(str, "test", "06031", "CT", 9, "Falls Village");
+ execute(str, "test", "06902", "CT", 9, "Stamford");
+ execute(str, "test", "06927", "CT", 9, "Stamford");
+ execute(str, "test", "10015", "NY", 36, "New York");
+ execute(str, "test", "07182", "NJ", 34, "Newark");
+ execute(str, "test", "73301", "TX", 48, "Austin");
+ execute(str, "test", "94102", "CA", 06, "San Francisco");
+
+ execute(str, "test2", "06029", "CT", 9, "Ellington");
+ execute(str, "test2", "06031", "CT", 9, "Falls Village");
+ execute(str, "test2", "06902", "CT", 9, "Stamford");
+ execute(str, "test2", "06927", "CT", 9, "Stamford");
+ execute(str, "test2", "10015", "NY", 36, "New York");
+ execute(str, "test2", "07182", "NJ", 34, "Newark");
+ execute(str, "test2", "73301", "TX", 48, "Austin");
+ execute(str, "test2", "94102", "CA", 06, "San Francisco");
+
+ assertRowCount(execute("select zipcode from %s"), 16);
+ assertRowCount(execute("select zipcode from %s where group='test'"), 8);
+ assertInvalid("select zipcode from %s where zipcode='06902'");
+ assertRowCount(execute("select zipcode from %s where zipcode='06902' ALLOW FILTERING"), 2);
+ assertRowCount(execute("select zipcode from %s where group='test' and zipcode='06902'"), 1);
+ assertRowCount(execute("select zipcode from %s where group='test' and zipcode IN ('06902','73301','94102')"), 3);
+ assertRowCount(execute("select zipcode from %s where group='test' AND zipcode IN ('06902','73301','94102') and state IN ('CT','CA')"), 2);
+ assertRowCount(execute("select zipcode from %s where group='test' AND zipcode IN ('06902','73301','94102') and state IN ('CT','CA') and fips_regions = 9"), 1);
+ assertRowCount(execute("select zipcode from %s where group='test' AND zipcode IN ('06902','73301','94102') and state IN ('CT','CA') ORDER BY zipcode DESC"), 2);
+ assertRowCount(execute("select zipcode from %s where group='test' AND zipcode IN ('06902','73301','94102') and state IN ('CT','CA') and fips_regions > 0"), 2);
+ assertEmpty(execute("select zipcode from %s where group='test' AND zipcode IN ('06902','73301','94102') and state IN ('CT','CA') and fips_regions < 0"));
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.multi_in_compact_non_composite_test()
+ */
+ @Test
+ public void testMultiSelectsNonCompositeCompactStorage() throws Throwable
+ {
+ createTable("CREATE TABLE %s (key int, c int, v int, PRIMARY KEY (key, c)) WITH COMPACT STORAGE");
+
+ execute("INSERT INTO %s (key, c, v) VALUES (0, 0, 0)");
+ execute("INSERT INTO %s (key, c, v) VALUES (0, 1, 1)");
+ execute("INSERT INTO %s (key, c, v) VALUES (0, 2, 2)");
+
+ assertRows(execute("SELECT * FROM %s WHERE key=0 AND c IN (0, 2)"),
+ row(0, 0, 0), row(0, 2, 2));
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.ticket_5230_test()
+ */
+ @Test
+ public void testMultipleClausesOnPrimaryKey() throws Throwable
+ {
+ createTable("CREATE TABLE %s (key text, c text, v text, PRIMARY KEY(key, c))");
+
+ execute("INSERT INTO %s (key, c, v) VALUES ('foo', '1', '1')");
+ execute("INSERT INTO %s(key, c, v) VALUES ('foo', '2', '2')");
+ execute("INSERT INTO %s(key, c, v) VALUES ('foo', '3', '3')");
+
+ assertRows(execute("SELECT c FROM %s WHERE key = 'foo' AND c IN ('1', '2')"),
+ row("1"), row("2"));
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.bug_5404()
+ */
+ @Test
+ public void testSelectWithToken() throws Throwable
+ {
+ createTable("CREATE TABLE %s (key text PRIMARY KEY)");
+
+ // We just want to make sure this doesn 't NPE server side
+ assertInvalid("select * from %s where token(key) > token(int(3030343330393233)) limit 1");
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.clustering_order_and_functions_test()
+ */
+ @Test
+ public void testFunctionsWithClusteringDesc() throws Throwable
+ {
+ createTable("CREATE TABLE %s ( k int, t timeuuid, PRIMARY KEY (k, t) ) WITH CLUSTERING ORDER BY (t DESC)");
+
+ for (int i = 0; i < 5; i++)
+ execute("INSERT INTO %s (k, t) VALUES (?, now())", i);
+
+ execute("SELECT dateOf(t) FROM %s");
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.select_with_alias_test()
+ */
+ @Test
+ public void testSelectWithAlias() throws Throwable
+ {
+ createTable("CREATE TABLE %s (id int PRIMARY KEY, name text)");
+
+ for (int id = 0; id < 5; id++)
+ execute("INSERT INTO %s (id, name) VALUES (?, ?) USING TTL 10 AND TIMESTAMP 0", id, "name" + id);
+
+ // test aliasing count( *)
+ UntypedResultSet rs = execute("SELECT count(*) AS user_count FROM %s");
+ assertEquals("user_count", rs.metadata().get(0).name.toString());
+ assertEquals(5L, rs.one().getLong(rs.metadata().get(0).name.toString()));
+
+ // test aliasing regular value
+ rs = execute("SELECT name AS user_name FROM %s WHERE id = 0");
+ assertEquals("user_name", rs.metadata().get(0).name.toString());
+ assertEquals("name0", rs.one().getString(rs.metadata().get(0).name.toString()));
+
+ // test aliasing writetime
+ rs = execute("SELECT writeTime(name) AS name_writetime FROM %s WHERE id = 0");
+ assertEquals("name_writetime", rs.metadata().get(0).name.toString());
+ assertEquals(0, rs.one().getInt(rs.metadata().get(0).name.toString()));
+
+ // test aliasing ttl
+ rs = execute("SELECT ttl(name) AS name_ttl FROM %s WHERE id = 0");
+ assertEquals("name_ttl", rs.metadata().get(0).name.toString());
+ int ttl = rs.one().getInt(rs.metadata().get(0).name.toString());
+ assertTrue(ttl == 9 || ttl == 10);
+
+ // test aliasing a regular function
+ rs = execute("SELECT intAsBlob(id) AS id_blob FROM %s WHERE id = 0");
+ assertEquals("id_blob", rs.metadata().get(0).name.toString());
+ assertEquals(ByteBuffer.wrap(new byte[4]), rs.one().getBlob(rs.metadata().get(0).name.toString()));
+
+ // test that select throws a meaningful exception for aliases in where clause
+ assertInvalidMessage("Aliases aren't allowed in the where clause",
+ "SELECT id AS user_id, name AS user_name FROM %s WHERE user_id = 0");
+
+ // test that select throws a meaningful exception for aliases in order by clause
+ assertInvalidMessage("Aliases are not allowed in order by clause",
+ "SELECT id AS user_id, name AS user_name FROM %s WHERE id IN (0) ORDER BY user_name");
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.select_distinct_test()
+ */
+ @Test
+ public void testSelectDistinct() throws Throwable
+ {
+ // Test a regular(CQL3) table.
+ createTable("CREATE TABLE %s (pk0 int, pk1 int, ck0 int, val int, PRIMARY KEY((pk0, pk1), ck0))");
+
+ for (int i = 0; i < 3; i++)
+ {
+ execute("INSERT INTO %s (pk0, pk1, ck0, val) VALUES (?, ?, 0, 0)", i, i);
+ execute("INSERT INTO %s (pk0, pk1, ck0, val) VALUES (?, ?, 1, 1)", i, i);
+ }
+
+ assertRows(execute("SELECT DISTINCT pk0, pk1 FROM %s LIMIT 1"),
+ row(0, 0));
+
+ assertRows(execute("SELECT DISTINCT pk0, pk1 FROM %s LIMIT 3"),
+ row(0, 0),
+ row(2, 2),
+ row(1, 1));
+
+ // Test selection validation.
+ assertInvalidMessage("queries must request all the partition key columns", "SELECT DISTINCT pk0 FROM %s");
+ assertInvalidMessage("queries must only request partition key columns", "SELECT DISTINCT pk0, pk1, ck0 FROM %s");
+
+ //Test a 'compact storage' table.
+ createTable("CREATE TABLE %s (pk0 int, pk1 int, val int, PRIMARY KEY((pk0, pk1))) WITH COMPACT STORAGE");
+
+ for (int i = 0; i < 3; i++)
+ execute("INSERT INTO %s (pk0, pk1, val) VALUES (?, ?, ?)", i, i, i);
+
+ assertRows(execute("SELECT DISTINCT pk0, pk1 FROM %s LIMIT 1"),
+ row(0, 0));
+
+ assertRows(execute("SELECT DISTINCT pk0, pk1 FROM %s LIMIT 3"),
+ row(0, 0),
+ row(2, 2),
+ row(1, 1));
+
+ // Test a 'wide row' thrift table.
+ createTable("CREATE TABLE %s (pk int, name text, val int, PRIMARY KEY(pk, name)) WITH COMPACT STORAGE");
+
+ for (int i = 0; i < 3; i++)
+ {
+ execute("INSERT INTO %s (pk, name, val) VALUES (?, 'name0', 0)", i);
+ execute("INSERT INTO %s (pk, name, val) VALUES (?, 'name1', 1)", i);
+ }
+
+ assertRows(execute("SELECT DISTINCT pk FROM %s LIMIT 1"),
+ row(1));
+
+ assertRows(execute("SELECT DISTINCT pk FROM %s LIMIT 3"),
+ row(1),
+ row(0),
+ row(2));
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.select_distinct_with_deletions_test()
+ */
+ @Test
+ public void testSelectDistinctWithDeletions() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, c int, v int)");
+
+ for (int i = 0; i < 10; i++)
+ execute("INSERT INTO %s (k, c, v) VALUES (?, ?, ?)", i, i, i);
+
+ Object[][] rows = getRows(execute("SELECT DISTINCT k FROM %s"));
+ Assert.assertEquals(10, rows.length);
+ Object key_to_delete = rows[3][0];
+
+ execute("DELETE FROM %s WHERE k=?", key_to_delete);
+
+ rows = getRows(execute("SELECT DISTINCT k FROM %s"));
+ Assert.assertEquals(9, rows.length);
+
+ rows = getRows(execute("SELECT DISTINCT k FROM %s LIMIT 5"));
+ Assert.assertEquals(5, rows.length);
+
+ rows = getRows(execute("SELECT DISTINCT k FROM %s"));
+ Assert.assertEquals(9, rows.length);
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.bug_6327_test()
+ */
+ @Test
+ public void testSelectInClauseAtOne() throws Throwable
+ {
+ createTable("CREATE TABLE %s ( k int, v int, PRIMARY KEY (k, v))");
+
+ execute("INSERT INTO %s (k, v) VALUES (0, 0)");
+
+ flush();
+
+ assertRows(execute("SELECT v FROM %s WHERE k=0 AND v IN (1, 0)"),
+ row(0));
+ }
+
+ /**
+ * Test for the #6579 'select count' paging bug,
+ * migrated from cql_tests.py:TestCQL.select_count_paging_test()
+ */
+ @Test
+ public void testSelectCountPaging() throws Throwable
+ {
+ createTable("create table %s (field1 text, field2 timeuuid, field3 boolean, primary key(field1, field2))");
+ createIndex("create index test_index on %s (field3)");
+
+ execute("insert into %s (field1, field2, field3) values ('hola', now(), false)");
+ execute("insert into %s (field1, field2, field3) values ('hola', now(), false)");
+
+ assertRows(execute("select count(*) from %s where field3 = false limit 1"),
+ row(2L));
+ }
+
+ /**
+ * Test for #7105 bug,
+ * migrated from cql_tests.py:TestCQL.clustering_order_in_test()
+ */
+ @Test
+ public void testClusteringOrder() throws Throwable
+ {
+ createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY ((a, b), c) ) with clustering order by (c desc)");
+
+ execute("INSERT INTO %s (a, b, c) VALUES (1, 2, 3)");
+ execute("INSERT INTO %s (a, b, c) VALUES (4, 5, 6)");
+
+ assertRows(execute("SELECT * FROM %s WHERE a=1 AND b=2 AND c IN (3)"),
+ row(1, 2, 3));
+ assertRows(execute("SELECT * FROM %s WHERE a=1 AND b=2 AND c IN (3, 4)"),
+ row(1, 2, 3));
+ }
+
+ /**
+ * Test for #7105 bug,
+ * SELECT with IN on final column of composite and compound primary key fails
+ * migrated from cql_tests.py:TestCQL.bug7105_test()
+ */
+ @Test
+ public void testSelectInFinalColumn() throws Throwable
+ {
+ createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b))");
+
+ execute("INSERT INTO %s (a, b, c, d) VALUES (1, 2, 3, 3)");
+ execute("INSERT INTO %s (a, b, c, d) VALUES (1, 4, 6, 5)");
+
+ assertRows(execute("SELECT * FROM %s WHERE a=1 AND b=2 ORDER BY b DESC"),
+ row(1, 2, 3, 3));
+ }
+
+ @Test
+ public void testAlias() throws Throwable
+ {
+ createTable("CREATE TABLE %s (id int PRIMARY KEY, name text)");
+
+ for (int i = 0; i < 5; i++)
+ execute("INSERT INTO %s (id, name) VALUES (?, ?) USING TTL 10 AND TIMESTAMP 0", i, Integer.toString(i));
+
+ assertInvalidMessage("Aliases aren't allowed in the where clause",
+ "SELECT id AS user_id, name AS user_name FROM %s WHERE user_id = 0");
+
+ // test that select throws a meaningful exception for aliases in order by clause
+ assertInvalidMessage("Aliases are not allowed in order by clause",
+ "SELECT id AS user_id, name AS user_name FROM %s WHERE id IN (0) ORDER BY user_name");
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/01115f72/test/unit/org/apache/cassandra/cql3/validation/operations/UpdateTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/UpdateTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/UpdateTest.java
new file mode 100644
index 0000000..c5d153f
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/UpdateTest.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.cql3.validation.operations;
+
+import org.junit.Test;
+
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+public class UpdateTest extends CQLTester
+{
+ /**
+ * Test altering the type of a column, including the one in the primary key (#4041)
+ * migrated from cql_tests.py:TestCQL.update_type_test()
+ */
+ @Test
+ public void testUpdateColumnType() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k text, c text, s set <text>, v text, PRIMARY KEY(k, c))");
+
+ // using utf8 character so that we can see the transition to BytesType
+ execute("INSERT INTO %s (k, c, v, s) VALUES ('ɸ', 'ɸ', 'ɸ', {'ɸ'})");
+
+ assertRows(execute("SELECT * FROM %s"),
+ row("ɸ", "ɸ", set("ɸ"), "ɸ"));
+
+ execute("ALTER TABLE %s ALTER v TYPE blob");
+ assertRows(execute("SELECT * FROM %s"),
+ row("ɸ", "ɸ", set("ɸ"), ByteBufferUtil.bytes("ɸ")));
+
+ execute("ALTER TABLE %s ALTER k TYPE blob");
+ assertRows(execute("SELECT * FROM %s"),
+ row(ByteBufferUtil.bytes("ɸ"), "ɸ", set("ɸ"), ByteBufferUtil.bytes("ɸ")));
+
+ execute("ALTER TABLE %s ALTER c TYPE blob");
+ assertRows(execute("SELECT * FROM %s"),
+ row(ByteBufferUtil.bytes("ɸ"), ByteBufferUtil.bytes("ɸ"), set("ɸ"), ByteBufferUtil.bytes("ɸ")));
+
+ execute("ALTER TABLE %s ALTER s TYPE set<blob>");
+ assertRows(execute("SELECT * FROM %s"),
+ row(ByteBufferUtil.bytes("ɸ"), ByteBufferUtil.bytes("ɸ"), set(ByteBufferUtil.bytes("ɸ")), ByteBufferUtil.bytes("ɸ")));
+ }
+
+ @Test
+ public void testTypeCasts() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, t text, a ascii, d double, i int)");
+
+ // The followings is fine
+ execute("UPDATE %s SET t = 'foo' WHERE k = ?", 0);
+ execute("UPDATE %s SET t = (ascii)'foo' WHERE k = ?", 0);
+ execute("UPDATE %s SET t = (text)(ascii)'foo' WHERE k = ?", 0);
+ execute("UPDATE %s SET a = 'foo' WHERE k = ?", 0);
+ execute("UPDATE %s SET a = (ascii)'foo' WHERE k = ?", 0);
+
+ // But trying to put some explicitely type-casted text into an ascii
+ // column should be rejected (even though the text is actually ascci)
+ assertInvalid("UPDATE %s SET a = (text)'foo' WHERE k = ?", 0);
+
+ // This is also fine because integer constants works for both integer and float types
+ execute("UPDATE %s SET i = 3 WHERE k = ?", 0);
+ execute("UPDATE %s SET i = (int)3 WHERE k = ?", 0);
+ execute("UPDATE %s SET d = 3 WHERE k = ?", 0);
+ execute("UPDATE %s SET d = (double)3 WHERE k = ?", 0);
+
+ // But values for ints and doubles are not truly compatible (their binary representation differs)
+ assertInvalid("UPDATE %s SET d = (int)3 WHERE k = ?", 0);
+ assertInvalid("UPDATE %s SET i = (double)3 WHERE k = ?", 0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/01115f72/test/unit/org/apache/cassandra/cql3/validation/operations/UseTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/UseTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/UseTest.java
new file mode 100644
index 0000000..e1498b6
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/UseTest.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.cql3.validation.operations;
+
+import org.junit.Test;
+
+import org.apache.cassandra.cql3.CQLTester;
+
+public class UseTest extends CQLTester
+{
+ @Test
+ public void testUseStatementWithBindVariable() throws Throwable
+ {
+ assertInvalidSyntaxMessage("Bind variables cannot be used for keyspace names", "USE ?");
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/01115f72/test/unit/org/apache/cassandra/service/ClientWarningsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/service/ClientWarningsTest.java b/test/unit/org/apache/cassandra/service/ClientWarningsTest.java
index da7577e..363fc7d 100644
--- a/test/unit/org/apache/cassandra/service/ClientWarningsTest.java
+++ b/test/unit/org/apache/cassandra/service/ClientWarningsTest.java
@@ -22,8 +22,9 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.apache.cassandra.config.DatabaseDescriptor;
-import org.apache.cassandra.cql3.CQLTester;
import org.apache.cassandra.cql3.QueryOptions;
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.dht.ByteOrderedPartitioner;
import org.apache.cassandra.transport.Message;
import org.apache.cassandra.transport.Server;
import org.apache.cassandra.transport.SimpleClient;
@@ -37,6 +38,8 @@ public class ClientWarningsTest extends CQLTester
@BeforeClass
public static void setUp()
{
+ DatabaseDescriptor.setPartitioner(ByteOrderedPartitioner.instance);
+
requireNetwork();
DatabaseDescriptor.setBatchSizeWarnThresholdInKB(1);
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/01115f72/test/unit/org/apache/cassandra/transport/MessagePayloadTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/transport/MessagePayloadTest.java b/test/unit/org/apache/cassandra/transport/MessagePayloadTest.java
index 73daa48..1dd3c5d 100644
--- a/test/unit/org/apache/cassandra/transport/MessagePayloadTest.java
+++ b/test/unit/org/apache/cassandra/transport/MessagePayloadTest.java
@@ -29,14 +29,16 @@ import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.cql3.BatchQueryOptions;
import org.apache.cassandra.cql3.CQLStatement;
-import org.apache.cassandra.cql3.CQLTester;
import org.apache.cassandra.cql3.QueryHandler;
import org.apache.cassandra.cql3.QueryOptions;
import org.apache.cassandra.cql3.QueryProcessor;
import org.apache.cassandra.cql3.statements.BatchStatement;
import org.apache.cassandra.cql3.statements.ParsedStatement;
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.dht.ByteOrderedPartitioner;
import org.apache.cassandra.exceptions.RequestExecutionException;
import org.apache.cassandra.exceptions.RequestValidationException;
import org.apache.cassandra.service.ClientState;
@@ -63,6 +65,8 @@ public class MessagePayloadTest extends CQLTester
{
try
{
+ DatabaseDescriptor.setPartitioner(ByteOrderedPartitioner.instance);
+
cqlQueryHandlerField = ClientState.class.getDeclaredField("cqlQueryHandler");
cqlQueryHandlerField.setAccessible(true);
http://git-wip-us.apache.org/repos/asf/cassandra/blob/01115f72/tools/stress/src/org/apache/cassandra/stress/generate/values/TimeUUIDs.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/generate/values/TimeUUIDs.java b/tools/stress/src/org/apache/cassandra/stress/generate/values/TimeUUIDs.java
index 7bfabf5..537d54e 100644
--- a/tools/stress/src/org/apache/cassandra/stress/generate/values/TimeUUIDs.java
+++ b/tools/stress/src/org/apache/cassandra/stress/generate/values/TimeUUIDs.java
@@ -46,6 +46,6 @@ public class TimeUUIDs extends Generator<UUID>
@Override
public UUID generate()
{
- return UUIDGen.getTimeUUID(dateGen.generate().getTime(), clockSeqAndNode);
+ return UUIDGen.getTimeUUID(dateGen.generate().getTime(), 0L, clockSeqAndNode);
}
}