You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by bl...@apache.org on 2015/08/17 11:12:43 UTC
[1/2] cassandra git commit: Fix ordering with IN restriction on
partition key
Repository: cassandra
Updated Branches:
refs/heads/cassandra-3.0 d2da7606a -> 47b66d7c1
Fix ordering with IN restriction on partition key
patch by Benjamin Lerer; reviewed by Stefania Alborghetti for CASSANDRA-9970
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/ee186b6b
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/ee186b6b
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/ee186b6b
Branch: refs/heads/cassandra-3.0
Commit: ee186b6b05569537eb979027176ccee57354c4da
Parents: 31db093
Author: blerer <be...@datastax.com>
Authored: Mon Aug 17 10:58:37 2015 +0200
Committer: blerer <be...@datastax.com>
Committed: Mon Aug 17 10:58:37 2015 +0200
----------------------------------------------------------------------
.../restrictions/PrimaryKeyRestrictionSet.java | 2 +-
.../operations/SelectOrderByTest.java | 43 ++++++++++++++++++++
2 files changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ee186b6b/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java b/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java
index b49d774..3a20f6a 100644
--- a/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java
+++ b/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java
@@ -98,7 +98,7 @@ final class PrimaryKeyRestrictionSet extends AbstractPrimaryKeyRestrictions
this.slice = true;
else if (restriction.isContains() || primaryKeyRestrictions.isContains())
this.contains = true;
- else if (restriction.isIN())
+ else if (restriction.isIN() || primaryKeyRestrictions.isIN())
this.in = true;
else
this.eq = true;
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ee186b6b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderByTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderByTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderByTest.java
index e788095..699ade8 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderByTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderByTest.java
@@ -22,6 +22,7 @@ import org.junit.Test;
import org.apache.cassandra.cql3.CQLTester;
import static org.junit.Assert.assertTrue;
+import static java.util.Arrays.asList;
public class SelectOrderByTest extends CQLTester
{
@@ -488,6 +489,48 @@ public class SelectOrderByTest extends CQLTester
assertTrue(isFirstIntSorted(results));
}
+ @Test
+ public void testInOrderByWithTwoPartitionKeyColumns() throws Throwable
+ {
+ for (String option : asList("", "WITH CLUSTERING ORDER BY (col_3 DESC)"))
+ {
+ createTable("CREATE TABLE %s (col_1 int, col_2 int, col_3 int, PRIMARY KEY ((col_1, col_2), col_3)) " + option);
+ execute("INSERT INTO %s (col_1, col_2, col_3) VALUES(?, ?, ?)", 1, 1, 1);
+ execute("INSERT INTO %s (col_1, col_2, col_3) VALUES(?, ?, ?)", 1, 1, 2);
+ execute("INSERT INTO %s (col_1, col_2, col_3) VALUES(?, ?, ?)", 1, 1, 13);
+ execute("INSERT INTO %s (col_1, col_2, col_3) VALUES(?, ?, ?)", 1, 2, 10);
+ execute("INSERT INTO %s (col_1, col_2, col_3) VALUES(?, ?, ?)", 1, 2, 11);
+
+ assertRows(execute("select * from %s where col_1=? and col_2 IN (?, ?) order by col_3;", 1, 1, 2),
+ row(1, 1, 1),
+ row(1, 1, 2),
+ row(1, 2, 10),
+ row(1, 2, 11),
+ row(1, 1, 13));
+
+ assertRows(execute("select * from %s where col_1=? and col_2 IN (?, ?) order by col_3 desc;", 1, 1, 2),
+ row(1, 1, 13),
+ row(1, 2, 11),
+ row(1, 2, 10),
+ row(1, 1, 2),
+ row(1, 1, 1));
+
+ assertRows(execute("select * from %s where col_2 IN (?, ?) and col_1=? order by col_3;", 1, 2, 1),
+ row(1, 1, 1),
+ row(1, 1, 2),
+ row(1, 2, 10),
+ row(1, 2, 11),
+ row(1, 1, 13));
+
+ assertRows(execute("select * from %s where col_2 IN (?, ?) and col_1=? order by col_3 desc;", 1, 2, 1),
+ row(1, 1, 13),
+ row(1, 2, 11),
+ row(1, 2, 10),
+ row(1, 1, 2),
+ row(1, 1, 1));
+ }
+ }
+
private boolean isFirstIntSorted(Object[][] rows)
{
for (int i = 1; i < rows.length; i++)
[2/2] cassandra git commit: Merge cassandra-2.2 into cassandra-3.0
Posted by bl...@apache.org.
Merge cassandra-2.2 into cassandra-3.0
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/47b66d7c
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/47b66d7c
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/47b66d7c
Branch: refs/heads/cassandra-3.0
Commit: 47b66d7c1e22dfd063d39b6aa3874c611ef8f0b7
Parents: d2da760 ee186b6
Author: blerer <be...@datastax.com>
Authored: Mon Aug 17 11:09:51 2015 +0200
Committer: blerer <be...@datastax.com>
Committed: Mon Aug 17 11:10:55 2015 +0200
----------------------------------------------------------------------
.../restrictions/PrimaryKeyRestrictionSet.java | 2 +-
.../cql3/statements/SelectStatement.java | 2 +
.../operations/SelectOrderByTest.java | 43 ++++++++++++++++++++
3 files changed, 46 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/47b66d7c/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/47b66d7c/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index 32177a4,3edb7d0..9acbb35
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@@ -747,8 -811,11 +747,10 @@@ public class SelectStatement implement
verifyOrderingIsAllowed(restrictions);
orderingComparator = getOrderingComparator(cfm, selection, restrictions);
isReversed = isReversed(cfm);
++ if (isReversed)
++ orderingComparator = Collections.reverseOrder(orderingComparator);
}
- if (isReversed)
- restrictions.reverse();
-
checkNeedsFiltering(restrictions);
SelectStatement stmt = new SelectStatement(cfm,
http://git-wip-us.apache.org/repos/asf/cassandra/blob/47b66d7c/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderByTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderByTest.java
index e788095,699ade8..341eed9
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderByTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderByTest.java
@@@ -21,7 -21,8 +21,8 @@@ import org.junit.Test
import org.apache.cassandra.cql3.CQLTester;
-import static org.junit.Assert.assertTrue;
+ import static java.util.Arrays.asList;
+import static org.junit.Assert.assertTrue;
public class SelectOrderByTest extends CQLTester
{