Merge branch 'cassandra-2.1' into trunk
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/aef76dda Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/aef76dda Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/aef76dda Branch: refs/heads/trunk Commit: aef76ddac3fb2989e299f044a46ab55c679ec288 Parents: 149a152 e4980b3 Author: Tyler Hobbs <[email protected]> Authored: Thu Feb 19 13:23:57 2015 -0600 Committer: Tyler Hobbs <[email protected]> Committed: Thu Feb 19 13:23:57 2015 -0600 ---------------------------------------------------------------------- CHANGES.txt | 2 ++ .../cassandra/cql3/SelectWithTokenFunctionTest.java | 12 ++++++++++++ 2 files changed, 14 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/aef76dda/CHANGES.txt ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/aef76dda/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java ---------------------------------------------------------------------- diff --cc test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java index a365c09,b2a972b..b674ba2 --- a/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java +++ b/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java @@@ -74,149 -59,19 +74,161 @@@ public class SelectWithTokenFunctionTes 0, "d"), row(0, "b"), row(0, "c")); - assertInvalid("SELECT * FROM %s WHERE token(a) > token(?) and token(b) > token(?)", 0, "a"); - assertInvalid("SELECT * FROM %s WHERE token(a) > token(?, ?) and token(a) < token(?, ?) and token(b) > token(?, ?) ", 0, "a", 0, "d", 0, "a"); - assertInvalid("SELECT * FROM %s WHERE token(b, a) > token(0, 'c')"); + assertInvalidMessage("The token() function must be applied to all partition key components or none of them", + "SELECT * FROM %s WHERE token(a) > token(?) and token(b) > token(?)", 0, "a"); + assertInvalidMessage("The token() function must be applied to all partition key components or none of them", + "SELECT * FROM %s WHERE token(a) > token(?, ?) and token(a) < token(?, ?) and token(b) > token(?, ?) ", + 0, "a", 0, "d", 0, "a"); + assertInvalidMessage("The token function arguments must be in the partition key order: a, b", + "SELECT * FROM %s WHERE token(b, a) > token(0, 'c')"); + assertInvalidMessage("The token() function must be applied to all partition key components or none of them", + "SELECT * FROM %s WHERE token(a, b) > token(?, ?) and token(b) < token(?, ?)", 0, "a", 0, "a"); + assertInvalidMessage("The token() function must be applied to all partition key components or none of them", + "SELECT * FROM %s WHERE token(a) > token(?, ?) and token(b) > token(?, ?)", 0, "a", 0, "a"); + } + + @Test + public void testSingleColumnPartitionKeyWithTokenNonTokenRestrictionsMix() throws Throwable + { + createTable("CREATE TABLE %s (a int primary key, b int)"); + + execute("INSERT INTO %s (a, b) VALUES (0, 0);"); + execute("INSERT INTO %s (a, b) VALUES (1, 1);"); + execute("INSERT INTO %s (a, b) VALUES (2, 2);"); + execute("INSERT INTO %s (a, b) VALUES (3, 3);"); + execute("INSERT INTO %s (a, b) VALUES (4, 4);"); + assertRows(execute("SELECT * FROM %s WHERE a IN (?, ?);", 1, 3), + row(1, 1), + row(3, 3)); + assertRows(execute("SELECT * FROM %s WHERE token(a)> token(?) and token(a) <= token(?);", 1, 3), + row(2, 2), + row(3, 3)); + assertRows(execute("SELECT * FROM %s WHERE token(a)= token(2);"), + row(2, 2)); + assertRows(execute("SELECT * FROM %s WHERE token(a) > token(?) AND token(a) <= token(?) AND a IN (?, ?);", + 1, 3, 1, 3), + row(3, 3)); + assertRows(execute("SELECT * FROM %s WHERE token(a) < token(?) AND token(a) >= token(?) AND a IN (?, ?);", + 1, 3, 1, 3), + row(3, 3)); + assertInvalidMessage("Only EQ and IN relation are supported on the partition key (unless you use the token() function)", + "SELECT * FROM %s WHERE token(a) > token(?) AND token(a) <= token(?) AND a > ?;", 1, 3, 1); + + assertRows(execute("SELECT * FROM %s WHERE token(a) > token(?) AND token(a) <= token(?) AND a IN ?;", + 1, 3, Arrays.asList(1, 3)), + row(3, 3)); + assertRows(execute("SELECT * FROM %s WHERE token(a) > token(?) AND a = ?;", 1, 3), + row(3, 3)); + assertRows(execute("SELECT * FROM %s WHERE a = ? AND token(a) > token(?);", 3, 1), + row(3, 3)); + assertEmpty(execute("SELECT * FROM %s WHERE token(a) > token(?) AND a = ?;", 3, 1)); + assertEmpty(execute("SELECT * FROM %s WHERE a = ? AND token(a) > token(?);", 1, 3)); + assertRows(execute("SELECT * FROM %s WHERE token(a) > token(?) AND a IN (?, ?);", 2, 1, 3), + row(3, 3)); + assertRows(execute("SELECT * FROM %s WHERE token(a) > token(?) AND token(a) < token(?) AND a IN (?, ?) ;", 2, 5, 1, 3), + row(3, 3)); + assertRows(execute("SELECT * FROM %s WHERE a IN (?, ?) AND token(a) > token(?) AND token(a) < token(?);", 1, 3, 2, 5), + row(3, 3)); + assertRows(execute("SELECT * FROM %s WHERE token(a) > token(?) AND a IN (?, ?) AND token(a) < token(?);", 2, 1, 3, 5), + row(3, 3)); + assertEmpty(execute("SELECT * FROM %s WHERE a IN (?, ?) AND token(a) > token(?);", 1, 3, 3)); + assertRows(execute("SELECT * FROM %s WHERE token(a) <= token(?) AND a = ?;", 2, 2), + row(2, 2)); + assertEmpty(execute("SELECT * FROM %s WHERE token(a) <= token(?) AND a = ?;", 2, 3)); + assertEmpty(execute("SELECT * FROM %s WHERE token(a) = token(?) AND a = ?;", 2, 3)); + assertRows(execute("SELECT * FROM %s WHERE token(a) >= token(?) AND token(a) <= token(?) AND a = ?;", 2, 2, 2), + row(2, 2)); + assertEmpty(execute("SELECT * FROM %s WHERE token(a) >= token(?) AND token(a) < token(?) AND a = ?;", 2, 2, 2)); + assertEmpty(execute("SELECT * FROM %s WHERE token(a) > token(?) AND token(a) <= token(?) AND a = ?;", 2, 2, 2)); + assertEmpty(execute("SELECT * FROM %s WHERE token(a) > token(?) AND token(a) < token(?) AND a = ?;", 2, 2, 2)); + } + + @Test + public void testMultiColumnPartitionKeyWithTokenNonTokenRestrictionsMix() throws Throwable + { + createTable("CREATE TABLE %s (a int, b int, c int, primary key((a, b)))"); + + execute("INSERT INTO %s (a, b, c) VALUES (0, 0, 0);"); + execute("INSERT INTO %s (a, b, c) VALUES (0, 1, 1);"); + execute("INSERT INTO %s (a, b, c) VALUES (0, 2, 2);"); + execute("INSERT INTO %s (a, b, c) VALUES (1, 0, 3);"); + execute("INSERT INTO %s (a, b, c) VALUES (1, 1, 4);"); + + assertRows(execute("SELECT * FROM %s WHERE token(a, b) > token(?, ?);", 0, 0), + row(0, 1, 1), + row(0, 2, 2), + row(1, 0, 3), + row(1, 1, 4)); + + assertRows(execute("SELECT * FROM %s WHERE token(a, b) > token(?, ?) AND a = ? AND b IN (?, ?);", + 0, 0, 1, 0, 1), + row(1, 0, 3), + row(1, 1, 4)); + + assertRows(execute("SELECT * FROM %s WHERE a = ? AND token(a, b) > token(?, ?) AND b IN (?, ?);", + 1, 0, 0, 0, 1), + row(1, 0, 3), + row(1, 1, 4)); + + assertRows(execute("SELECT * FROM %s WHERE b IN (?, ?) AND token(a, b) > token(?, ?) AND a = ?;", + 0, 1, 0, 0, 1), + row(1, 0, 3), + row(1, 1, 4)); + + assertEmpty(execute("SELECT * FROM %s WHERE b IN (?, ?) AND token(a, b) > token(?, ?) AND token(a, b) < token(?, ?) AND a = ?;", + 0, 1, 0, 0, 0, 0, 1)); + + assertEmpty(execute("SELECT * FROM %s WHERE b IN (?, ?) AND token(a, b) > token(?, ?) AND token(a, b) <= token(?, ?) AND a = ?;", + 0, 1, 0, 0, 0, 0, 1)); + + assertEmpty(execute("SELECT * FROM %s WHERE b IN (?, ?) AND token(a, b) >= token(?, ?) AND token(a, b) < token(?, ?) AND a = ?;", + 0, 1, 0, 0, 0, 0, 1)); + + assertEmpty(execute("SELECT * FROM %s WHERE b IN (?, ?) AND token(a, b) = token(?, ?) AND a = ?;", + 0, 1, 0, 0, 1)); + + assertInvalidMessage("Partition key parts: b must be restricted as other parts are", + "SELECT * FROM %s WHERE token(a, b) > token(?, ?) AND a = ?;", 0, 0, 1); + } + + @Test + public void testMultiColumnPartitionKeyWithIndexAndTokenNonTokenRestrictionsMix() throws Throwable + { + createTable("CREATE TABLE %s (a int, b int, c int, primary key((a, b)))"); + createIndex("CREATE INDEX ON %s(b)"); + createIndex("CREATE INDEX ON %s(c)"); + + execute("INSERT INTO %s (a, b, c) VALUES (0, 0, 0);"); + execute("INSERT INTO %s (a, b, c) VALUES (0, 1, 1);"); + execute("INSERT INTO %s (a, b, c) VALUES (0, 2, 2);"); + execute("INSERT INTO %s (a, b, c) VALUES (1, 0, 3);"); + execute("INSERT INTO %s (a, b, c) VALUES (1, 1, 4);"); + + assertRows(execute("SELECT * FROM %s WHERE b = ?;", 1), + row(0, 1, 1), + row(1, 1, 4)); + + assertRows(execute("SELECT * FROM %s WHERE token(a, b) > token(?, ?) AND b = ?;", 0, 0, 1), + row(0, 1, 1), + row(1, 1, 4)); + + assertRows(execute("SELECT * FROM %s WHERE b = ? AND token(a, b) > token(?, ?);", 1, 0, 0), + row(0, 1, 1), + row(1, 1, 4)); + + assertRows(execute("SELECT * FROM %s WHERE b = ? AND token(a, b) > token(?, ?) and c = ? ALLOW FILTERING;", 1, 0, 0, 4), + row(1, 1, 4)); } + + @Test + public void testTokenFunctionWithCompoundPartitionAndClusteringCols() throws Throwable + { + createTable("CREATE TABLE IF NOT EXISTS %s (a int, b int, c int, d int, PRIMARY KEY ((a, b), c, d))"); + // just test that the queries don't error ++ // note: these shouldn't require ALLOW FILTERING + execute("SELECT * FROM %s WHERE token(a, b) > token(0, 0) AND c > 10 ALLOW FILTERING;"); + execute("SELECT * FROM %s WHERE c > 10 AND token(a, b) > token(0, 0) ALLOW FILTERING;"); + execute("SELECT * FROM %s WHERE token(a, b) > token(0, 0) AND (c, d) > (0, 0) ALLOW FILTERING;"); + execute("SELECT * FROM %s WHERE (c, d) > (0, 0) AND token(a, b) > token(0, 0) ALLOW FILTERING;"); + } }
