Merge branch 'cassandra-3.11' into trunk

Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/b871decb
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/b871decb
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/b871decb

Branch: refs/heads/trunk
Commit: b871decba274be126fc94ab3ab48f75a95be9d94
Parents: 33eada0 2edd6fd
Author: Aleksey Yeshchenko <alek...@apple.com>
Authored: Mon Dec 10 18:23:39 2018 +0000
Committer: Aleksey Yeshchenko <alek...@apple.com>
Committed: Mon Dec 10 18:23:39 2018 +0000

----------------------------------------------------------------------
 .../operations/SelectOrderByTest.java           | 78 ++++++++++++++++++++
 1 file changed, 78 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/b871decb/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderByTest.java
----------------------------------------------------------------------
diff --cc 
test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderByTest.java
index fd44c50,06aa2fd..8a3ae03
--- 
a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderByTest.java
+++ 
b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderByTest.java
@@@ -639,132 -702,84 +639,210 @@@ public class SelectOrderByTest extends 
          }
      }
  
 +    /**
 +     * Test that ORDER BY columns allow skipping equality-restricted 
clustering columns, see CASSANDRA-10271.
 +     */
 +    @Test
 +    public void 
testAllowSkippingEqualityAndSingleValueInRestrictedClusteringColumns() 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 (?, ?, ?, ?)", 0, 0, 0, 
0);
 +        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 
1);
 +        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 2, 
2);
 +        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 0, 
3);
 +        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 1, 
4);
 +        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 2, 
5);
 +
 +        assertInvalidMessage("Order by is currently only supported on the 
clustered columns of the PRIMARY KEY, got d",
 +                             "SELECT * FROM %s WHERE a=? ORDER BY d DESC", 0);
 +
 +        assertInvalidMessage("Order by is currently only supported on the 
clustered columns of the PRIMARY KEY, got d",
 +                             "SELECT * FROM %s WHERE a=? ORDER BY b ASC, c 
ASC, d ASC", 0);
 +
 +        String errorMsg = "Order by currently only supports the ordering of 
columns following their declared order in the PRIMARY KEY";
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND b=? ORDER BY c", 
0, 0),
 +                   row(0, 0, 0, 0),
 +                   row(0, 0, 1, 1),
 +                   row(0, 0, 2, 2)
 +        );
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND b=? ORDER BY c 
ASC", 0, 0),
 +                   row(0, 0, 0, 0),
 +                   row(0, 0, 1, 1),
 +                   row(0, 0, 2, 2)
 +        );
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND b=? ORDER BY c 
DESC", 0, 0),
 +                   row(0, 0, 2, 2),
 +                   row(0, 0, 1, 1),
 +                   row(0, 0, 0, 0)
 +        );
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND b=? AND c>=? ORDER 
BY c ASC", 0, 0, 1),
 +                   row(0, 0, 1, 1),
 +                   row(0, 0, 2, 2));
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND b=? AND c>=? ORDER 
BY c DESC", 0, 0, 1),
 +                   row(0, 0, 2, 2),
 +                   row(0, 0, 1, 1));
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND b=? AND c IN (?, 
?) ORDER BY c ASC", 0, 0, 1, 2),
 +                   row(0, 0, 1, 1),
 +                   row(0, 0, 2, 2));
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND b=? AND c IN (?, 
?) ORDER BY c DESC", 0, 0, 1, 2),
 +                   row(0, 0, 2, 2),
 +                   row(0, 0, 1, 1));
 +
 +        assertInvalidMessage(errorMsg, "SELECT * FROM %s WHERE a=? AND b<? 
ORDER BY c DESC", 0, 1);
 +
 +        assertInvalidMessage(errorMsg, "SELECT * FROM %s WHERE a=? AND (b, c) 
> (?, ?) ORDER BY c", 0, 0, 0);
 +        assertInvalidMessage(errorMsg, "SELECT * FROM %s WHERE a=? AND (b, c) 
>= (?, ?) ORDER BY c", 0, 0, 0);
 +        assertInvalidMessage(errorMsg, "SELECT * FROM %s WHERE a=? AND (b, c) 
< (?, ?) ORDER BY c", 0, 0, 0);
 +        assertInvalidMessage(errorMsg, "SELECT * FROM %s WHERE a=? AND (b, c) 
<= (?, ?) ORDER BY c", 0, 0, 0);
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND (b, c) = (?, ?) 
ORDER BY c ASC", 0, 0, 0),
 +                   row(0, 0, 0, 0));
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND (b, c) = (?, ?) 
ORDER BY c DESC", 0, 0, 0),
 +                   row(0, 0, 0, 0));
 +
 +        assertInvalidMessage(errorMsg, "SELECT * FROM %s WHERE a=? AND (b, c) 
> ? ORDER BY c", 0, tuple(0, 0));
 +        assertInvalidMessage(errorMsg, "SELECT * FROM %s WHERE a=? AND (b, c) 
>= ? ORDER BY c", 0, tuple(0, 0));
 +        assertInvalidMessage(errorMsg, "SELECT * FROM %s WHERE a=? AND (b, c) 
< ? ORDER BY c", 0, tuple(0, 0));
 +        assertInvalidMessage(errorMsg, "SELECT * FROM %s WHERE a=? AND (b, c) 
<= ? ORDER BY c", 0, tuple(0, 0));
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND (b, c) = ? ORDER 
BY c ASC", 0, tuple(0, 0)),
 +                   row(0, 0, 0, 0));
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND (b, c) = ? ORDER 
BY c DESC", 0, tuple(0, 0)),
 +                   row(0, 0, 0, 0));
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a IN (?, ?) AND b=? AND 
c>=? ORDER BY c ASC", 0, 1, 0, 0),
 +                   row(0, 0, 0, 0),
 +                   row(0, 0, 1, 1),
 +                   row(0, 0, 2, 2));
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a IN (?, ?) AND b=? AND 
c>=? ORDER BY c DESC", 0, 1, 0, 0),
 +                   row(0, 0, 2, 2),
 +                   row(0, 0, 1, 1),
 +                   row(0, 0, 0, 0));
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a IN (?, ?) AND b=? ORDER 
BY c ASC", 0, 1, 0),
 +                   row(0, 0, 0, 0),
 +                   row(0, 0, 1, 1),
 +                   row(0, 0, 2, 2));
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a IN (?, ?) AND b=? ORDER 
BY c DESC", 0, 1, 0),
 +                   row(0, 0, 2, 2),
 +                   row(0, 0, 1, 1),
 +                   row(0, 0, 0, 0));
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND b IN (?) ORDER BY 
c ASC", 0, 1),
 +                   row(0, 1, 0, 3),
 +                   row(0, 1, 1, 4),
 +                   row(0, 1, 2, 5));
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND b IN (?) ORDER BY 
c DESC", 0, 1),
 +                   row(0, 1, 2, 5),
 +                   row(0, 1, 1, 4),
 +                   row(0, 1, 0, 3));
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND (b, c) IN ((?, ?)) 
ORDER BY c ASC", 0, 1, 1),
 +                   row(0, 1, 1, 4));
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND (b, c) IN ((?, ?)) 
ORDER BY c DESC", 0, 1, 1),
 +                   row(0, 1, 1, 4));
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND b IN (?, ?) AND 
c=? ORDER BY b ASC", 0, 0, 1, 2),
 +                   row(0, 0, 2, 2),
 +                   row(0, 1, 2, 5));
 +
 +        assertRows(execute("SELECT * FROM %s WHERE a=? AND b IN (?, ?) AND 
c=? ORDER BY b DESC", 0, 0, 1, 2),
 +                   row(0, 1, 2, 5),
 +                   row(0, 0, 2, 2));
 +
 +        assertInvalidMessage(errorMsg, "SELECT * FROM %s WHERE a=? AND b IN ? 
ORDER BY c", 0, list(0));
 +        assertInvalidMessage(errorMsg, "SELECT * FROM %s WHERE a=? AND b IN 
(?,?) ORDER BY c", 0, 1, 3);
 +        assertInvalidMessage(errorMsg, "SELECT * FROM %s WHERE a=? AND (b,c) 
IN ? ORDER BY c", 0, list(tuple(0, 0)));
 +        assertInvalidMessage(errorMsg, "SELECT * FROM %s WHERE a=? AND (b,c) 
IN ((?,?), (?,?)) ORDER BY c", 0, 0, 0, 0, 1);
 +    }
 +
+     @Test
+     public void 
testSelectWithReversedTypeInReverseOrderWithStaticColumnsWithoutStaticRow() 
throws Throwable
+     {
+         createTable("CREATE TABLE %s (a int, b int, c int, d int static, 
PRIMARY KEY (a, b)) WITH CLUSTERING ORDER BY (b DESC);");
+ 
+         execute("INSERT INTO %s (a, b, c) VALUES (1, 1, 1);");
+         execute("INSERT INTO %s (a, b, c) VALUES (1, 2, 2);");
+         execute("INSERT INTO %s (a, b, c) VALUES (1, 3, 3);");
+ 
+         // read in comparator order
+         assertRows(execute("SELECT b, c FROM %s WHERE a = 1 ORDER BY b 
DESC;"),
+                    row(3, 3),
+                    row(2, 2),
+                    row(1, 1));
+ 
+         // read in reverse comparator order
+         assertRows(execute("SELECT b, c FROM %s WHERE a = 1 ORDER BY b ASC;"),
+                    row(1, 1),
+                    row(2, 2),
+                    row(3, 3));
+ 
+         /*
+          * Flush the sstable. We *should* see the same results when reading 
in both directions, but prior to CASSANDRA-14910
+          * fix this would now have returned an empty result set when reading 
in reverse comparator order.
+          */
+         flush();
+ 
+         // read in comparator order
+         assertRows(execute("SELECT b, c FROM %s WHERE a = 1 ORDER BY b 
DESC;"),
+                    row(3, 3),
+                    row(2, 2),
+                    row(1, 1));
+ 
+         // read in reverse comparator order
+         assertRows(execute("SELECT b, c FROM %s WHERE a = 1 ORDER BY b ASC;"),
+                    row(1, 1),
+                    row(2, 2),
+                    row(3, 3));
+     }
+ 
+     @Test
+     public void 
testSelectWithReversedTypeInReverseOrderWithStaticColumnsWithStaticRow() throws 
Throwable
+     {
+         createTable("CREATE TABLE %s (a int, b int, c int, d int static, 
PRIMARY KEY (a, b)) WITH CLUSTERING ORDER BY (b DESC)");
+ 
+         execute("INSERT INTO %s (a, d) VALUES (1, 0);");
+ 
+         execute("INSERT INTO %s (a, b, c) VALUES (1, 1, 1);");
+         execute("INSERT INTO %s (a, b, c) VALUES (1, 2, 2);");
+         execute("INSERT INTO %s (a, b, c) VALUES (1, 3, 3);");
+ 
+         // read in comparator order
+         assertRows(execute("SELECT b, c, d FROM %s WHERE a = 1 ORDER BY b 
DESC;"),
+                    row(3, 3, 0),
+                    row(2, 2, 0),
+                    row(1, 1, 0));
+ 
+         // read in reverse comparator order
+         assertRows(execute("SELECT b, c, d FROM %s WHERE a = 1 ORDER BY b 
ASC;"),
+                    row(1, 1, 0),
+                    row(2, 2, 0),
+                    row(3, 3, 0));
+ 
+         flush();
+ 
+         // read in comparator order
+         assertRows(execute("SELECT b, c, d FROM %s WHERE a = 1 ORDER BY b 
DESC;"),
+                    row(3, 3, 0),
+                    row(2, 2, 0),
+                    row(1, 1, 0));
+ 
+         // read in reverse comparator order
+         assertRows(execute("SELECT b, c, d FROM %s WHERE a = 1 ORDER BY b 
ASC;"),
+                    row(1, 1, 0),
+                    row(2, 2, 0),
+                    row(3, 3, 0));
+     }
+ 
      private boolean isFirstIntSorted(Object[][] rows)
      {
          for (int i = 1; i < rows.length; i++)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to