Merge branch cassandra-3.0 into trunk
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/94ca7695 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/94ca7695 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/94ca7695 Branch: refs/heads/trunk Commit: 94ca7695ffbec46d97b23598184a5fb1dfe61499 Parents: 2bb1bfc 7927ace Author: Benjamin Lerer <b.le...@gmail.com> Authored: Thu Apr 28 11:24:27 2016 +0200 Committer: Benjamin Lerer <b.le...@gmail.com> Committed: Thu Apr 28 11:24:27 2016 +0200 ---------------------------------------------------------------------- .../SelectMultiColumnRelationTest.java | 1678 +++++++++--------- .../cql3/validation/operations/SelectTest.java | 75 +- 2 files changed, 920 insertions(+), 833 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/94ca7695/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java ---------------------------------------------------------------------- diff --cc test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java index 49e6c4b,b49bd87..6e3b6eb --- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java +++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java @@@ -2437,378 -2426,76 +2437,451 @@@ public class SelectTest extends CQLTest unset()); } + @Test + public void filteringOnClusteringColumns() throws Throwable + { + createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))"); + + execute("INSERT INTO %s (a,b,c,d) VALUES (11, 12, 13, 14)"); + execute("INSERT INTO %s (a,b,c,d) VALUES (11, 15, 16, 17)"); + execute("INSERT INTO %s (a,b,c,d) VALUES (21, 22, 23, 24)"); + execute("INSERT INTO %s (a,b,c,d) VALUES (31, 32, 33, 34)"); + + beforeAndAfterFlush(() -> { + + assertRows(execute("SELECT * FROM %s WHERE a = 11 AND b = 15"), + row(11, 15, 16, 17)); + + assertInvalidMessage("Clustering column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)", + "SELECT * FROM %s WHERE a = 11 AND b > 12 AND c = 15"); + + assertRows(execute("SELECT * FROM %s WHERE a = 11 AND b = 15 AND c > 15"), + row(11, 15, 16, 17)); + + assertRows(execute("SELECT * FROM %s WHERE a = 11 AND b > 12 AND c > 13 AND d = 17 ALLOW FILTERING"), + row(11, 15, 16, 17)); + assertInvalidMessage("Clustering column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)", + "SELECT * FROM %s WHERE a = 11 AND b > 12 AND c > 13 and d = 17"); + + assertRows(execute("SELECT * FROM %s WHERE b > 20 AND c > 30 ALLOW FILTERING"), + row(31, 32, 33, 34)); + assertInvalidMessage("Clustering column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)", + "SELECT * FROM %s WHERE b > 20 AND c > 30"); + + assertRows(execute("SELECT * FROM %s WHERE b > 20 AND c < 30 ALLOW FILTERING"), + row(21, 22, 23, 24)); + assertInvalidMessage("Clustering column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)", + "SELECT * FROM %s WHERE b > 20 AND c < 30"); + + assertRows(execute("SELECT * FROM %s WHERE b > 20 AND c = 33 ALLOW FILTERING"), + row(31, 32, 33, 34)); + assertInvalidMessage("Clustering column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)", + "SELECT * FROM %s WHERE b > 20 AND c = 33"); + + assertRows(execute("SELECT * FROM %s WHERE c = 33 ALLOW FILTERING"), + row(31, 32, 33, 34)); + assertInvalidMessage("PRIMARY KEY column \"c\" cannot be restricted as preceding column \"b\" is not restricted", + "SELECT * FROM %s WHERE c = 33"); + }); + + // -------------------------------------------------- + // Clustering column within and across partition keys + // -------------------------------------------------- + createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))"); + + execute("INSERT INTO %s (a,b,c,d) VALUES (11, 12, 13, 14)"); + execute("INSERT INTO %s (a,b,c,d) VALUES (11, 15, 16, 17)"); + execute("INSERT INTO %s (a,b,c,d) VALUES (11, 18, 19, 20)"); + + execute("INSERT INTO %s (a,b,c,d) VALUES (21, 22, 23, 24)"); + execute("INSERT INTO %s (a,b,c,d) VALUES (21, 25, 26, 27)"); + execute("INSERT INTO %s (a,b,c,d) VALUES (21, 28, 29, 30)"); + + execute("INSERT INTO %s (a,b,c,d) VALUES (31, 32, 33, 34)"); + execute("INSERT INTO %s (a,b,c,d) VALUES (31, 35, 36, 37)"); + execute("INSERT INTO %s (a,b,c,d) VALUES (31, 38, 39, 40)"); + + beforeAndAfterFlush(() -> { + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE a = 21 AND c > 23"), + row(21, 25, 26, 27), + row(21, 28, 29, 30)); + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE a = 21 AND c > 23 ORDER BY b DESC"), + row(21, 28, 29, 30), + row(21, 25, 26, 27)); + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c > 16 and c < 36"), + row(11, 18, 19, 20), + row(21, 22, 23, 24), + row(21, 25, 26, 27), + row(21, 28, 29, 30), + row(31, 32, 33, 34)); + }); + } + + @Test + public void filteringWithMultiColumnSlices() throws Throwable + { + //---------------------------------------- + // Multi-column slices for clustering keys + //---------------------------------------- + createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, PRIMARY KEY (a, b, c, d))"); + + execute("INSERT INTO %s (a,b,c,d,e) VALUES (11, 12, 13, 14, 15)"); + execute("INSERT INTO %s (a,b,c,d,e) VALUES (21, 22, 23, 24, 25)"); + execute("INSERT INTO %s (a,b,c,d,e) VALUES (31, 32, 33, 34, 35)"); + + beforeAndAfterFlush(() -> { + + assertRows(execute("SELECT * FROM %s WHERE b = 22 AND d = 24 ALLOW FILTERING"), + row(21, 22, 23, 24, 25)); + assertInvalidMessage("PRIMARY KEY column \"d\" cannot be restricted as preceding column \"c\" is not restricted", + "SELECT * FROM %s WHERE b = 22 AND d = 24"); + + assertRows(execute("SELECT * FROM %s WHERE (b, c) > (20, 30) AND d = 34 ALLOW FILTERING"), + row(31, 32, 33, 34, 35)); + assertInvalidMessage("Clustering column \"d\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)", + "SELECT * FROM %s WHERE (b, c) > (20, 30) AND d = 34"); + }); + } + + @Test + public void containsFilteringForClusteringKeys() throws Throwable + { + //------------------------------------------------- + // Frozen collections filtering for clustering keys + //------------------------------------------------- + + // first clustering column + createTable("CREATE TABLE %s (a int, b frozen<list<int>>, c int, PRIMARY KEY (a, b, c))"); + execute("INSERT INTO %s (a,b,c) VALUES (?, ?, ?)", 11, list(1, 3), 14); + execute("INSERT INTO %s (a,b,c) VALUES (?, ?, ?)", 21, list(2, 3), 24); + execute("INSERT INTO %s (a,b,c) VALUES (?, ?, ?)", 21, list(3, 3), 34); + + beforeAndAfterFlush(() -> { + + assertRows(execute("SELECT * FROM %s WHERE a = 21 AND b CONTAINS 2 ALLOW FILTERING"), + row(21, list(2, 3), 24)); + assertInvalidMessage("Clustering columns can only be restricted with CONTAINS with a secondary index or filtering", + "SELECT * FROM %s WHERE a = 21 AND b CONTAINS 2"); + + assertRows(execute("SELECT * FROM %s WHERE b CONTAINS 2 ALLOW FILTERING"), + row(21, list(2, 3), 24)); + assertInvalidMessage("Clustering columns can only be restricted with CONTAINS with a secondary index or filtering", + "SELECT * FROM %s WHERE b CONTAINS 2"); + + assertRows(execute("SELECT * FROM %s WHERE b CONTAINS 3 ALLOW FILTERING"), + row(11, list(1, 3), 14), + row(21, list(2, 3), 24), + row(21, list(3, 3), 34)); + }); + + // non-first clustering column + createTable("CREATE TABLE %s (a int, b int, c frozen<list<int>>, d int, PRIMARY KEY (a, b, c))"); + + execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", 11, 12, list(1, 3), 14); + execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", 21, 22, list(2, 3), 24); + execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", 21, 22, list(3, 3), 34); + + beforeAndAfterFlush(() -> { + + assertRows(execute("SELECT * FROM %s WHERE a = 21 AND c CONTAINS 2 ALLOW FILTERING"), + row(21, 22, list(2, 3), 24)); + assertInvalidMessage("Clustering columns can only be restricted with CONTAINS with a secondary index or filtering", + "SELECT * FROM %s WHERE a = 21 AND c CONTAINS 2"); + + assertRows(execute("SELECT * FROM %s WHERE b > 20 AND c CONTAINS 2 ALLOW FILTERING"), + row(21, 22, list(2, 3), 24)); + assertInvalidMessage("Clustering column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)", + "SELECT * FROM %s WHERE b > 20 AND c CONTAINS 2"); + + assertRows(execute("SELECT * FROM %s WHERE c CONTAINS 3 ALLOW FILTERING"), + row(11, 12, list(1, 3), 14), + row(21, 22, list(2, 3), 24), + row(21, 22, list(3, 3), 34)); + }); + + createTable("CREATE TABLE %s (a int, b int, c frozen<map<text, text>>, d int, PRIMARY KEY (a, b, c))"); + + execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", 11, 12, map("1", "3"), 14); + execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", 21, 22, map("2", "3"), 24); + execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", 21, 22, map("3", "3"), 34); + + beforeAndAfterFlush(() -> { + assertRows(execute("SELECT * FROM %s WHERE b > 20 AND c CONTAINS KEY '2' ALLOW FILTERING"), + row(21, 22, map("2", "3"), 24)); + assertInvalidMessage("Clustering column \"c\" cannot be restricted (preceding column \"b\" is restricted by a non-EQ relation)", + "SELECT * FROM %s WHERE b > 20 AND c CONTAINS KEY '2'"); + }); + } + + @Test + public void filteringWithOrderClause() throws Throwable + { + createTable("CREATE TABLE %s (a int, b int, c int, d list<int>, PRIMARY KEY (a, b, c))"); + + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 11, 12, 13, list(1,4)); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 22, 23, list(2,4)); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 25, 26, list(2,7)); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 31, 32, 33, list(3,4)); + + beforeAndAfterFlush(() -> { + + assertRows(executeFilteringOnly("SELECT a, b, c, d FROM %s WHERE a = 21 AND c > 20 ORDER BY b DESC"), + row(21, 25, 26, list(2, 7)), + row(21, 22, 23, list(2, 4))); + + assertRows(executeFilteringOnly("SELECT a, b, c, d FROM %s WHERE a IN(21, 31) AND c > 20 ORDER BY b DESC"), + row(31, 32, 33, list(3, 4)), + row(21, 25, 26, list(2, 7)), + row(21, 22, 23, list(2, 4))); + }); + } + + + @Test + public void filteringOnStaticColumnTest() throws Throwable + { + createTable("CREATE TABLE %s (a int, b int, c int, d int, s int static, PRIMARY KEY (a, b))"); + + execute("INSERT INTO %s (a, b, c, d, s) VALUES (11, 12, 13, 14, 15)"); + execute("INSERT INTO %s (a, b, c, d, s) VALUES (21, 22, 23, 24, 25)"); + execute("INSERT INTO %s (a, b, c, d, s) VALUES (21, 26, 27, 28, 29)"); + execute("INSERT INTO %s (a, b, c, d, s) VALUES (31, 32, 33, 34, 35)"); + execute("INSERT INTO %s (a, b, c, d, s) VALUES (11, 42, 43, 44, 45)"); + + beforeAndAfterFlush(() -> { + + assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE s = 29"), + row(21, 22, 23, 24, 29), + row(21, 26, 27, 28, 29)); + assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE b > 22 AND s = 29"), + row(21, 26, 27, 28, 29)); + assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE b > 10 and b < 26 AND s = 29"), + row(21, 22, 23, 24, 29)); + assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE c > 10 and c < 27 AND s = 29"), + row(21, 22, 23, 24, 29)); + assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE c > 10 and c < 43 AND s = 29"), + row(21, 22, 23, 24, 29), + row(21, 26, 27, 28, 29)); + assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE c > 10 AND s > 15 AND s < 45"), + row(21, 22, 23, 24, 29), + row(21, 26, 27, 28, 29), + row(31, 32, 33, 34, 35)); + assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE a = 21 AND s > 15 AND s < 45 ORDER BY b DESC"), + row(21, 26, 27, 28, 29), + row(21, 22, 23, 24, 29)); + assertRows(executeFilteringOnly("SELECT a, b, c, d, s FROM %s WHERE c > 13 and d < 44"), + row(21, 22, 23, 24, 29), + row(21, 26, 27, 28, 29), + row(31, 32, 33, 34, 35)); + }); + } + + @Test + public void containsFilteringOnNonClusteringColumn() throws Throwable { + createTable("CREATE TABLE %s (a int, b int, c int, d list<int>, PRIMARY KEY (a, b, c))"); + + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 11, 12, 13, list(1,4)); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 22, 23, list(2,4)); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 25, 26, list(2,7)); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 31, 32, 33, list(3,4)); + + beforeAndAfterFlush(() -> { + + assertRows(executeFilteringOnly("SELECT a, b, c, d FROM %s WHERE b > 20 AND d CONTAINS 2"), + row(21, 22, 23, list(2, 4)), + row(21, 25, 26, list(2, 7))); + + assertRows(executeFilteringOnly("SELECT a, b, c, d FROM %s WHERE b > 20 AND d CONTAINS 2 AND d contains 4"), + row(21, 22, 23, list(2, 4))); + }); + } + + @Test + public void filteringOnCompactTable() throws Throwable + { + createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c)) WITH COMPACT STORAGE"); + + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 11, 12, 13, 14); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 22, 23, 24); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 25, 26, 27); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 31, 32, 33, 34); + + beforeAndAfterFlush(() -> { + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c > 13"), + row(21, 22, 23, 24), + row(21, 25, 26, 27), + row(31, 32, 33, 34)); + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c > 13 AND c < 33"), + row(21, 22, 23, 24), + row(21, 25, 26, 27)); + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c > 13 AND b < 32"), + row(21, 22, 23, 24), + row(21, 25, 26, 27)); + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE a = 21 AND c > 13 AND b < 32 ORDER BY b DESC"), + row(21, 25, 26, 27), + row(21, 22, 23, 24)); + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE a IN (21, 31) AND c > 13 ORDER BY b DESC"), + row(31, 32, 33, 34), + row(21, 25, 26, 27), + row(21, 22, 23, 24)); + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c > 13 AND d < 34"), + row(21, 22, 23, 24), + row(21, 25, 26, 27)); + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c > 13"), + row(21, 22, 23, 24), + row(21, 25, 26, 27), + row(31, 32, 33, 34)); + }); + + // with frozen in clustering key + createTable("CREATE TABLE %s (a int, b int, c frozen<list<int>>, d int, PRIMARY KEY (a, b, c)) WITH COMPACT STORAGE"); + + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 11, 12, list(1, 3), 14); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 22, list(2, 3), 24); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 25, list(2, 6), 27); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 31, 32, list(3, 3), 34); + + beforeAndAfterFlush(() -> { + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c CONTAINS 2"), + row(21, 22, list(2, 3), 24), + row(21, 25, list(2, 6), 27)); + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c CONTAINS 2 AND b < 25"), + row(21, 22, list(2, 3), 24)); + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE c CONTAINS 2 AND c CONTAINS 3"), + row(21, 22, list(2, 3), 24)); + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE b > 12 AND c CONTAINS 2 AND d < 27"), + row(21, 22, list(2, 3), 24)); + }); + + // with frozen in value + createTable("CREATE TABLE %s (a int, b int, c int, d frozen<list<int>>, PRIMARY KEY (a, b, c)) WITH COMPACT STORAGE"); + + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 11, 12, 13, list(1, 4)); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 22, 23, list(2, 4)); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 21, 25, 25, list(2, 6)); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 31, 32, 34, list(3, 4)); + + beforeAndAfterFlush(() -> { + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE d CONTAINS 2"), + row(21, 22, 23, list(2, 4)), + row(21, 25, 25, list(2, 6))); + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE d CONTAINS 2 AND b < 25"), + row(21, 22, 23, list(2, 4))); + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE d CONTAINS 2 AND d CONTAINS 4"), + row(21, 22, 23, list(2, 4))); + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE b > 12 AND c < 25 AND d CONTAINS 2"), + row(21, 22, 23, list(2, 4))); + }); + } + + @Test + public void testCustomIndexWithFiltering() throws Throwable { + // Test for CASSANDRA-11310 compatibility with 2i + createTable("CREATE TABLE %s (a text, b int, c text, d int, PRIMARY KEY (a, b, c));"); + createIndex("CREATE INDEX ON %s(c)"); + + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", "a", 0, "b", 1); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", "a", 1, "b", 2); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", "a", 2, "b", 3); + execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", "c", 3, "b", 4); + + assertRows(executeFilteringOnly("SELECT * FROM %s WHERE a='a' AND b > 0 AND c = 'b'"), + row("a", 1, "b", 2), + row("a", 2, "b", 3)); + } + + private UntypedResultSet executeFilteringOnly(String statement) throws Throwable + { + assertInvalid(statement); + return execute(statement + " ALLOW FILTERING"); + } - } ++ + /** + * Check select with and without compact storage, with different column + * order. See CASSANDRA-10988 + */ + @Test + public void testClusteringOrderWithSlice() throws Throwable + { + for (String compactOption : new String[] { "", " COMPACT STORAGE AND" }) + { + // non-compound, ASC order + createTable("CREATE TABLE %s (a text, b int, PRIMARY KEY (a, b)) WITH" + + compactOption + + " CLUSTERING ORDER BY (b ASC)"); + + execute("INSERT INTO %s (a, b) VALUES ('a', 2)"); + execute("INSERT INTO %s (a, b) VALUES ('a', 3)"); + assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0"), + row("a", 2), + row("a", 3)); + + assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0 ORDER BY b DESC"), + row("a", 3), + row("a", 2)); + + // non-compound, DESC order + createTable("CREATE TABLE %s (a text, b int, PRIMARY KEY (a, b)) WITH" + + compactOption + + " CLUSTERING ORDER BY (b DESC)"); + + execute("INSERT INTO %s (a, b) VALUES ('a', 2)"); + execute("INSERT INTO %s (a, b) VALUES ('a', 3)"); + assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0"), + row("a", 3), + row("a", 2)); + + assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0 ORDER BY b ASC"), + row("a", 2), + row("a", 3)); + + // compound, first column DESC order + createTable("CREATE TABLE %s (a text, b int, c int, PRIMARY KEY (a, b, c)) WITH" + + compactOption + + " CLUSTERING ORDER BY (b DESC)" + ); + + execute("INSERT INTO %s (a, b, c) VALUES ('a', 2, 4)"); + execute("INSERT INTO %s (a, b, c) VALUES ('a', 3, 5)"); + assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0"), + row("a", 3, 5), + row("a", 2, 4)); + + assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0 ORDER BY b ASC"), + row("a", 2, 4), + row("a", 3, 5)); + + // compound, mixed order + createTable("CREATE TABLE %s (a text, b int, c int, PRIMARY KEY (a, b, c)) WITH" + + compactOption + + " CLUSTERING ORDER BY (b ASC, c DESC)" + ); + + execute("INSERT INTO %s (a, b, c) VALUES ('a', 2, 4)"); + execute("INSERT INTO %s (a, b, c) VALUES ('a', 3, 5)"); + assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0"), + row("a", 2, 4), + row("a", 3, 5)); + + assertRows(execute("SELECT * FROM %s WHERE a = 'a' AND b > 0 ORDER BY b ASC"), + row("a", 2, 4), + row("a", 3, 5)); + } + } + }