cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ble...@apache.org
Subject [1/5] cassandra git commit: Fix SELECT on tuple relations for mixed ASC/DESC clustering order
Date Thu, 11 Feb 2016 09:43:26 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.0 62f94b74e -> 1aa97e30c


http://git-wip-us.apache.org/repos/asf/cassandra/blob/90fc8969/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
index b3232d5..b8a1d50 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
@@ -792,8 +792,10 @@ public class SelectMultiColumnRelationTest extends CQLTester
                     row(0, 0, 1, 0)
             );
 
-            // preserve pre-6875 behavior (even though the query result is technically incorrect)
-            assertEmpty(execute("SELECT * FROM %s WHERE a = ? AND (b, c) > (?, ?)", 0,
1, 0));
+            assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) > (?, ?)", 0,
1, 0),
+                    row(0,1, 1, 1),
+                    row(0, 1, 1, 0)
+                    );
         }
     }
 
@@ -990,6 +992,859 @@ public class SelectMultiColumnRelationTest extends CQLTester
                              "SELECT * from %s WHERE (i, j) IN ? ALLOW FILTERING", unset());
     }
 
+    @Test
+    public void testMixedOrderColumns1() throws Throwable
+    {
+        createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, PRIMARY KEY (a,
b, c, d, e)) " +
+                "WITH CLUSTERING ORDER BY (b DESC, c ASC, d DESC, e ASC)");
+
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 2, 0, -1, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 2, 0, -1, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 2, 0, 1, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, -1, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, -1, 1, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, -1, 1, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 1, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 1, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 0, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 0, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, -1, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, -1, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 0, 0, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, -1, 0, -1, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, -1, 0, 0, 0);
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e)<=(?,?,?,?) " +
+                                "AND (b)>(?)", 0, 2, 0, 1, 1, -1),
+
+                row( 0, 2, 0, 1, 1),
+                row( 0, 2, 0, -1, 0),
+                row( 0, 2, 0, -1, 1),
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 0, 0, 0, 0)
+        );
+
+
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e)<=(?,?,?,?) " +
+                                "AND (b)>=(?)", 0, 2, 0, 1, 1, -1),
+
+                row( 0, 2, 0, 1, 1),
+                row( 0, 2, 0, -1, 0),
+                row( 0, 2, 0, -1, 1),
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 0, 0, 0, 0),
+                row( 0, -1, 0, 0, 0),
+                row( 0, -1, 0, -1, 0)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d)>=(?,?,?)"+
+                                "AND (b,c,d,e)<(?,?,?,?) ", 0, 1, 1,0,1,  1, 0,1),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0)
+
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e)>(?,?,?,?)"+
+                                "AND (b,c,d)<=(?,?,?) ", 0, -1, 0,-1,-1,  2, 0,-1),
+
+                row( 0, 2, 0, -1, 0),
+                row( 0, 2, 0, -1, 1),
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 0, 0, 0, 0),
+                row( 0, -1, 0, 0, 0),
+                row( 0, -1, 0, -1, 0)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e) < (?,?,?,?) " +
+                                "AND (b,c,d,e)>(?,?,?,?)", 0, 1, 0, 0, 0, 1, 0,-1,-1),
+                row(0, 1, 0, 0, -1)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e) <= (?,?,?,?) " +
+                                "AND (b,c,d,e)>(?,?,?,?)", 0, 1, 0, 0, 0, 1, 0,-1,-1),
+                row(0, 1, 0, 0, -1),
+                row(0, 1, 0, 0, 0)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b)<(?) " +
+                                "AND (b,c,d,e)>(?,?,?,?)", 0, 2, -1, 0,-1,-1),
+
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 0, 0, 0, 0),
+                row( 0, -1, 0, 0, 0),
+                row( 0, -1, 0, -1, 0)
+
+        );
+
+
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b)<(?) " +
+                                "AND (b)>(?)", 0, 2, -1),
+
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 0, 0, 0, 0)
+
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b)<(?) " +
+                                "AND (b)>=(?)", 0, 2, -1),
+
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 0, 0, 0, 0),
+                row( 0, -1, 0, 0, 0),
+                row( 0, -1, 0, -1, 0)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e)<=(?,?,?,?) " +
+                                "AND (b,c,d,e)>(?,?,?,?)", 0, 2, 0, 1, 1, -1, 0,-1,-1),
+
+                row( 0, 2, 0, 1, 1),
+                row( 0, 2, 0, -1, 0),
+                row( 0, 2, 0, -1, 1),
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 0, 0, 0, 0),
+                row( 0, -1, 0, 0, 0),
+                row( 0, -1, 0, -1, 0)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c)<=(?,?) " +
+                                "AND (b,c,d,e)>(?,?,?,?)", 0, 2, 0, -1, 0,-1,-1),
+
+                row( 0, 2, 0, 1, 1),
+                row( 0, 2, 0, -1, 0),
+                row( 0, 2, 0, -1, 1),
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 0, 0, 0, 0),
+                row( 0, -1, 0, 0, 0),
+                row( 0, -1, 0, -1, 0)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d)<=(?,?,?) " +
+                                "AND (b,c,d,e)>(?,?,?,?)", 0, 2, 0,-1, -1, 0,-1,-1),
+
+                row( 0, 2, 0, -1, 0),
+                row( 0, 2, 0, -1, 1),
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 0, 0, 0, 0),
+                row( 0, -1, 0, 0, 0),
+                row( 0, -1, 0, -1, 0)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e)>(?,?,?,?)"+
+                                "AND (b,c,d)<=(?,?,?) ", 0, -1, 0,-1,-1,  2, 0,-1),
+
+                row( 0, 2, 0, -1, 0),
+                row( 0, 2, 0, -1, 1),
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 0, 0, 0, 0),
+                row( 0, -1, 0, 0, 0),
+                row( 0, -1, 0, -1, 0)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d)>=(?,?,?)"+
+                                "AND (b,c,d,e)<(?,?,?,?) ", 0, 1, 1,0,1,  1, 0,1),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0)
+        );
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e)<(?,?,?,?) "+
+                                "AND (b,c,d)>=(?,?,?)", 0, 1, 1,0,1,1,  1, 0),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0)
+
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c)<(?,?) " +
+                                "AND (b,c,d,e)>(?,?,?,?)", 0, 2, 0, -1, 0,-1,-1),
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 0, 0, 0, 0),
+                row( 0, -1, 0, 0, 0),
+                row( 0, -1, 0, -1, 0)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c)<(?,?) " +
+                                "AND (b,c,d,e)>(?,?,?,?)", 0, 2, 0, -1, 0,-1,-1),
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 0, 0, 0, 0),
+                row( 0, -1, 0, 0, 0),
+                row( 0, -1, 0, -1, 0)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c,d,e) <= (?,?,?,?)",
0, 1, 0, 0, 0),
+                row(0, 1, -1, 1, 0),
+                row(0, 1, -1, 1, 1),
+                row(0, 1, -1, 0, 0),
+                row(0, 1, 0, 0, -1),
+                row(0, 1, 0, 0, 0),
+                row(0, 1, 0, -1, -1),
+                row(0, 0, 0, 0, 0),
+                row(0, -1, 0, 0, 0),
+                row(0, -1, 0, -1, 0)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c,d,e) > (?,?,?,?)", 0,
1, 0, 0, 0),
+                row(0, 2, 0, 1, 1),
+                row(0, 2, 0, -1, 0),
+                row(0, 2, 0, -1, 1),
+                row(0, 1, 0,  1, -1),
+                row(0, 1, 0,  1, 1),
+                row(0, 1, 0,  0, 1),
+                row(0, 1, 1,  0, -1),
+                row(0, 1, 1,  0, 0),
+                row(0, 1, 1,  0, 1),
+                row(0, 1, 1, -1, 0)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c,d,e) >= (?,?,?,?)",
0, 1, 0, 0, 0),
+                row( 0, 2, 0, 1, 1),
+                row(0, 2, 0, -1, 0),
+                row(0, 2, 0, -1, 1),
+                row(0, 1, 0,  1, -1),
+                row(0, 1, 0,  1, 1),
+                row(0, 1, 0,  0, 0),
+                row(0, 1, 0,  0, 1),
+                row(0, 1, 1,  0, -1),
+                row(0, 1, 1,  0, 0),
+                row(0, 1, 1,  0, 1),
+                row(0, 1, 1, -1, 0)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c,d) >= (?,?,?)", 0, 1,
0, 0),
+                row( 0, 2, 0, 1, 1),
+                row(0, 2, 0, -1, 0),
+                row(0, 2, 0, -1, 1),
+                row(0, 1, 0,  1, -1),
+                row(0, 1, 0,  1, 1),
+                row(0, 1, 0,  0, -1),
+                row(0, 1, 0,  0, 0),
+                row(0, 1, 0,  0, 1),
+                row(0, 1, 1,  0, -1),
+                row(0, 1, 1,  0, 0),
+                row(0, 1, 1,  0, 1),
+                row(0, 1, 1, -1, 0)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c,d) > (?,?,?)", 0, 1,
0, 0),
+                row(0, 2, 0, 1, 1),
+                row(0, 2, 0, -1, 0),
+                row(0, 2, 0, -1, 1),
+                row(0, 1, 0,  1, -1),
+                row(0, 1, 0,  1, 1),
+                row(0, 1, 1,  0, -1),
+                row(0, 1, 1,  0, 0),
+                row(0, 1, 1,  0, 1),
+                row(0, 1, 1, -1, 0)
+        );
+
+    }
+
+    @Test
+    public void testMixedOrderColumns2() throws Throwable
+    {
+        createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, PRIMARY KEY (a,
b, c, d, e)) " +
+                "WITH CLUSTERING ORDER BY (b DESC, c ASC, d ASC, e ASC)");
+
+        // b and d are reversed in the clustering order
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 2, 0, -1, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 2, 0, -1, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, -1, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, -1, 1, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, -1, 1, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 1, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 1, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 0, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 0, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, -1, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, -1, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 0, 0, 0, 0);
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c,d,e) <= (?,?,?,?)",
0, 1, 0, 0, 0),
+                row(0, 1, -1, 0, 0),
+                row(0, 1, -1, 1, 0),
+                row(0, 1, -1, 1, 1),
+                row(0, 1, 0, -1, -1),
+                row(0, 1, 0, 0, -1),
+                row(0, 1, 0, 0, 0),
+                row(0, 0, 0, 0, 0)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c,d,e) > (?,?,?,?)", 0,
1, 0, 0, 0),
+                row(0, 2, 0, -1, 0),
+                row(0, 2, 0, -1, 1),
+                row(0, 1, 0,  0, 1),
+                row(0, 1, 0,  1, -1),
+                row(0, 1, 0,  1, 1),
+                row(0, 1, 1, -1, 0),
+                row(0, 1, 1,  0, -1),
+                row(0, 1, 1,  0, 0),
+                row(0, 1, 1,  0, 1)
+        );
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c,d,e) >= (?,?,?,?)",
0, 1, 0, 0, 0),
+                row(0, 2, 0, -1, 0),
+                row(0, 2, 0, -1, 1),
+                row(0, 1, 0,  0, 0),
+                row(0, 1, 0,  0, 1),
+                row(0, 1, 0,  1, -1),
+                row(0, 1, 0,  1, 1),
+                row(0, 1, 1, -1, 0),
+                row(0, 1, 1,  0, -1),
+                row(0, 1, 1,  0, 0),
+                row(0, 1, 1,  0, 1)
+        );
+    }
+
+    @Test
+    public void testMixedOrderColumns3() throws Throwable
+    {
+        createTable("create table %s (a int, b int, c int, PRIMARY KEY (a, b, c)) WITH CLUSTERING
ORDER BY (b DESC, c ASC)");
+
+        execute("INSERT INTO %s (a, b, c) VALUES (?,?,?);", 0, 2, 3);
+        execute("INSERT INTO %s (a, b, c) VALUES (?,?,?);", 0, 2, 4);
+        execute("INSERT INTO %s (a, b, c) VALUES (?,?,?);", 0, 4, 4);
+        execute("INSERT INTO %s (a, b, c) VALUES (?,?,?);", 0, 3, 4);
+        execute("INSERT INTO %s (a, b, c) VALUES (?,?,?);", 0, 4, 5);
+        execute("INSERT INTO %s (a, b, c) VALUES (?,?,?);", 0, 4, 6);
+
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c)>=(?,?) AND (b,c)<(?,?)
ALLOW FILTERING", 0, 2, 3, 4, 5),
+                row(0, 4, 4), row(0, 3, 4), row(0, 2, 3), row(0, 2, 4)
+        );
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c)>=(?,?) AND (b,c)<=(?,?)
ALLOW FILTERING", 0, 2, 3, 4, 5),
+                row(0, 4, 4), row(0, 4, 5), row(0, 3, 4), row(0, 2, 3), row(0, 2, 4)
+        );
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c)<(?,?) ALLOW FILTERING",
0, 4, 5),
+                row(0, 4, 4),row(0, 3, 4),row(0, 2, 3),row(0, 2, 4)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c)>(?,?) ALLOW FILTERING",
0, 4, 5),
+                row(0, 4, 6)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b)<(?) and (b)>(?) ALLOW
FILTERING", 0, 4, 2),
+                row(0, 3, 4)
+        );
+    }
+
+    @Test
+    public void testMixedOrderColumns4() throws Throwable
+    {
+        createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, PRIMARY KEY (a,
b, c, d, e)) " +
+                "WITH CLUSTERING ORDER BY (b ASC, c DESC, d DESC, e ASC)");
+
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 2, 0, -1, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 2, 0, -1, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 2, 0, 1, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 2, -1, 1, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 2, -3, 1, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, -1, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, -1, 1, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, -1, 1, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 1, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 1, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 0, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, 0, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 0, -1, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, -1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, 0, 1);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 1, 1, -1, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, 0, 0, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, -1, 0, -1, 0);
+        execute("INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)", 0, -1, 0, 0, 0);
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e)<(?,?,?,?) " +
+                                "AND (b,c,d,e)>(?,?,?,?)", 0, 2, 0, 1, 1, -1, 0, -1, -1),
+
+                row(0, -1, 0, 0, 0),
+                row(0, -1, 0, -1, 0),
+                row(0, 0, 0, 0, 0),
+                row(0, 1, 1, 0, -1),
+                row(0, 1, 1, 0, 0),
+                row(0, 1, 1, 0, 1),
+                row(0, 1, 1, -1, 0),
+                row(0, 1, 0, 1, -1),
+                row(0, 1, 0, 1, 1),
+                row(0, 1, 0, 0, -1),
+                row(0, 1, 0, 0, 0),
+                row(0, 1, 0, 0, 1),
+                row(0, 1, 0, -1, -1),
+                row(0, 1, -1, 1, 0),
+                row(0, 1, -1, 1, 1),
+                row(0, 1, -1, 0, 0),
+                row(0, 2, 0, -1, 0),
+                row(0, 2, 0, -1, 1),
+                row(0, 2, -1, 1, 1),
+                row(0, 2, -3, 1, 1)
+
+        );
+
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e) < (?,?,?,?) " +
+                                "AND (b,c,d,e)>(?,?,?,?)", 0, 1, 0, 0, 0, 1, 0, -1, -1),
+                row(0, 1, 0, 0, -1)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e) <= (?,?,?,?) " +
+                                "AND (b,c,d,e)>(?,?,?,?)", 0, 1, 0, 0, 0, 1, 0,-1,-1),
+                row(0, 1, 0, 0, -1),
+                row(0, 1, 0, 0, 0)
+        );
+
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e)<=(?,?,?,?) " +
+                                "AND (b,c,d,e)>(?,?,?,?)", 0, 2, 0, 1, 1, -1, 0,-1,-1),
+
+                row( 0, -1, 0, 0, 0),
+                row( 0, -1, 0, -1, 0),
+                row(0, 0, 0, 0, 0),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 2, 0, 1, 1),
+                row( 0, 2, 0, -1, 0),
+                row( 0, 2, 0, -1, 1),
+                row(  0, 2, -1, 1, 1),
+                row(  0, 2, -3, 1, 1)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c)<=(?,?) " +
+                                "AND (b,c,d,e)>(?,?,?,?)", 0, 2, 0, -1, 0,-1,-1),
+
+                row( 0, -1, 0, 0, 0),
+                row(0, -1, 0, -1, 0),
+                row( 0, 0, 0, 0, 0),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 2, 0, 1, 1),
+                row( 0, 2, 0, -1, 0),
+                row( 0, 2, 0, -1, 1),
+                row(  0, 2, -1, 1, 1),
+                row(  0, 2, -3, 1, 1)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c)<(?,?) " +
+                                "AND (b,c,d,e)>(?,?,?,?)", 0, 2, 0, -1, 0, -1, -1),
+                row( 0, -1, 0, 0, 0),
+                row( 0, -1, 0, -1, 0),
+                row( 0, 0, 0, 0, 0),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row(  0, 2, -1, 1, 1),
+                row(0, 2, -3, 1, 1)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e)<=(?,?,?,?) " +
+                                "AND (b)>=(?)", 0, 2, 0, 1, 1, -1),
+
+                row( 0, -1, 0, 0, 0),
+                row( 0, -1, 0, -1, 0),
+                row( 0, 0, 0, 0, 0),
+                row( 0, 1, 1, 0, -1),
+                row(0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 2, 0, 1, 1),
+                row( 0, 2, 0, -1, 0),
+                row( 0, 2, 0, -1, 1),
+                row(  0, 2, -1, 1, 1),
+                row(  0, 2, -3, 1, 1)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e)<=(?,?,?,?) " +
+                                "AND (b)>(?)", 0, 2, 0, 1, 1, -1),
+
+                row( 0, 0, 0, 0, 0),
+                row( 0, 1, 1, 0, -1),
+                row( 0, 1, 1, 0, 0),
+                row( 0, 1, 1, 0, 1),
+                row( 0, 1, 1, -1, 0),
+                row( 0, 1, 0, 1, -1),
+                row( 0, 1, 0, 1, 1),
+                row( 0, 1, 0, 0, -1),
+                row( 0, 1, 0, 0, 0),
+                row( 0, 1, 0, 0, 1),
+                row( 0, 1, 0, -1, -1),
+                row( 0, 1, -1, 1, 0),
+                row( 0, 1, -1, 1, 1),
+                row( 0, 1, -1, 0, 0),
+                row( 0, 2, 0, 1, 1),
+                row( 0, 2, 0, -1, 0),
+                row( 0, 2, 0, -1, 1),
+                row(  0, 2, -1, 1, 1),
+                row(  0, 2, -3, 1, 1)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c,d,e) <= (?,?,?,?)",
0, 1, 0, 0, 0),
+                row(0, -1, 0, 0, 0),
+                row(0, -1, 0, -1, 0),
+                row(0, 0, 0, 0, 0),
+                row(0, 1, 0, 0, -1),
+                row(0, 1, 0, 0, 0),
+                row(0, 1, 0, -1, -1),
+                row(0, 1, -1, 1, 0),
+                row(0, 1, -1, 1, 1),
+                row(0, 1, -1, 0, 0)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c,d,e) > (?,?,?,?)", 0,
1, 0, 0, 0),
+                row(0, 1, 1,  0, -1),
+                row(0, 1, 1,  0, 0),
+                row(0, 1, 1, 0, 1),
+                row(0, 1, 1, -1, 0),
+                row(0, 1, 0,  1, -1),
+                row(0, 1, 0,  1, 1),
+                row(0, 1, 0,  0, 1),
+                row(0, 2, 0, 1, 1),
+                row(0, 2, 0, -1, 0),
+                row(0, 2, 0, -1, 1),
+                row(  0, 2, -1, 1, 1),
+                row(  0, 2, -3, 1, 1)
+
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c,d,e) >= (?,?,?,?)",
0, 1, 0, 0, 0),
+                row(0, 1, 1,  0, -1),
+                row(0, 1, 1,  0, 0),
+                row(0, 1, 1, 0, 1),
+                row(0, 1, 1, -1, 0),
+                row(0, 1, 0,  1, -1),
+                row(0, 1, 0,  1, 1),
+                row(0, 1, 0,  0, 0),
+                row(0, 1, 0,  0, 1),
+                row(0, 2, 0, 1, 1),
+                row(0, 2, 0, -1, 0),
+                row(0, 2, 0, -1, 1),
+                row(  0, 2, -1, 1, 1),
+                row(  0, 2, -3, 1, 1)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c,d) >= (?,?,?)", 0, 1,
0, 0),
+                row(0, 1, 1,  0, -1),
+                row(0, 1, 1,  0, 0),
+                row(0, 1, 1, 0, 1),
+                row(0, 1, 1, -1, 0),
+                row(0, 1, 0,  1, -1),
+                row(0, 1, 0,  1, 1),
+                row(0, 1, 0,  0, -1),
+                row(0, 1, 0,  0, 0),
+                row(0, 1, 0,  0, 1),
+                row(0, 2, 0, 1, 1),
+                row(0, 2, 0, -1, 0),
+                row(0, 2, 0, -1, 1),
+                row(  0, 2, -1, 1, 1),
+                row(  0, 2, -3, 1, 1)
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b,c,d) > (?,?,?)", 0, 1,
0, 0),
+                row(0, 1, 1,  0, -1),
+                row(0, 1, 1,  0, 0),
+                row(0, 1, 1,  0, 1),
+                row(0, 1, 1, -1, 0),
+                row(0, 1, 0,  1, -1),
+                row(0, 1, 0,  1, 1),
+                row(0, 2, 0, 1, 1),
+                row(0, 2, 0, -1, 0),
+                row(0, 2, 0, -1, 1),
+                row(  0, 2, -1, 1, 1),
+                row(  0, 2, -3, 1, 1)
+        );
+
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b) < (?) ", 0, 0),
+                row(0, -1, 0, 0, 0), row(0, -1, 0, -1, 0)
+        );
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b) <= (?) ", 0,-1),
+                row(0, -1, 0, 0, 0), row(0, -1, 0, -1, 0)
+        );
+        assertRows(execute(
+                        "SELECT * FROM %s" +
+                                " WHERE a = ? " +
+                                "AND (b,c,d,e) < (?,?,?,?) and (b,c,d,e) > (?,?,?,?)
", 0, 2, 0, 0, 0, 2, -2, 0, 0),
+                row(0, 2, 0, -1, 0),
+                row(0, 2, 0, -1, 1),
+                row(0, 2, -1, 1, 1)
+        );
+    }
+
     /**
      * Check select on tuple relations, see CASSANDRA-8613
      * migrated from cql_tests.py:TestCQL.simple_tuple_query_test()


Mime
View raw message