cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alek...@apache.org
Subject [1/2] git commit: Fix CASSANDRA-6075
Date Wed, 24 Sep 2014 01:59:07 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 c2c9835f7 -> c65ef9af6


Fix CASSANDRA-6075

patch by Aleksey Yeschenko and Benjamin Lerer


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

Branch: refs/heads/cassandra-2.1
Commit: b1166c09983b1678cbc4b241f1da860930c571a5
Parents: 62db20a
Author: Aleksey Yeschenko <aleksey@apache.org>
Authored: Tue Sep 23 18:51:58 2014 -0700
Committer: Aleksey Yeschenko <aleksey@apache.org>
Committed: Tue Sep 23 18:53:27 2014 -0700

----------------------------------------------------------------------
 .../cql3/statements/SelectStatement.java        |  5 ++--
 .../cql3/SelectWithTokenFunctionTest.java       | 30 ++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/b1166c09/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index 363e3d3..aadd0bd 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -24,6 +24,7 @@ import com.google.common.base.Joiner;
 import com.google.common.base.Objects;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
 
 import org.github.jamm.MemoryMeter;
 
@@ -1815,7 +1816,7 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
                 previous = cname;
             }
 
-            if (stmt.onToken && cfDef.partitionKeyCount() > 0)
+            if (stmt.onToken)
                 checkTokenFunctionArgumentsOrder(cfDef);
         }
 
@@ -1827,7 +1828,7 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
          */
         private void checkTokenFunctionArgumentsOrder(CFDefinition cfDef) throws InvalidRequestException
         {
-            Iterator<Name> iter = cfDef.partitionKeys().iterator();
+            Iterator<Name> iter = Iterators.cycle(cfDef.partitionKeys());
             for (Relation relation : whereClause)
             {
                 SingleColumnRelation singleColumnRelation = (SingleColumnRelation) relation;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b1166c09/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java b/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java
index f089a5b..9199862 100644
--- a/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java
+++ b/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java
@@ -20,6 +20,7 @@ package org.apache.cassandra.cql3;
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.db.ConsistencyLevel;
 import org.apache.cassandra.exceptions.InvalidRequestException;
+import org.apache.cassandra.exceptions.SyntaxException;
 import org.apache.cassandra.gms.Gossiper;
 import org.apache.cassandra.service.ClientState;
 import org.junit.AfterClass;
@@ -90,6 +91,8 @@ public class SelectWithTokenFunctionTest
         {
             UntypedResultSet results = execute("SELECT * FROM %s.single_partition WHERE token(a)
>= token(0)");
             assertEquals(1, results.size());
+            results = execute("SELECT * FROM %s.single_partition WHERE token(a) >= token(0)
and token(a) < token(1)");
+            assertEquals(1, results.size());
         }
         finally
         {
@@ -104,6 +107,24 @@ public class SelectWithTokenFunctionTest
     }
 
     @Test(expected = InvalidRequestException.class)
+    public void testTokenFunctionWithTwoGreaterThan() throws Throwable
+    {
+        execute("SELECT * FROM %s.single_clustering WHERE token(a) >= token(0) and token(a)
>= token(1)");
+    }
+
+    @Test(expected = InvalidRequestException.class)
+    public void testTokenFunctionWithGreaterThanAndEquals() throws Throwable
+    {
+        execute("SELECT * FROM %s.single_clustering WHERE token(a) >= token(0) and token(a)
= token(1)");
+    }
+
+    @Test(expected = SyntaxException.class)
+    public void testTokenFunctionWithGreaterThanAndIn() throws Throwable
+    {
+        execute("SELECT * FROM %s.single_clustering WHERE token(a) >= token(0) and token(a)
in (token(1))");
+    }
+
+    @Test(expected = InvalidRequestException.class)
     public void testTokenFunctionWithPartitionKeyAndClusteringKeyArguments() throws Throwable
     {
         execute("SELECT * FROM %s.single_clustering WHERE token(a, b) > token(0, 'c')");
@@ -126,6 +147,9 @@ public class SelectWithTokenFunctionTest
         {
             UntypedResultSet results = execute("SELECT * FROM %s.compound_partition WHERE
token(a, b) > token(0, 'a')");
             assertEquals(2, results.size());
+            results = execute("SELECT * FROM %s.compound_partition WHERE token(a, b) >
token(0, 'a') "
+                    + "and token(a, b) < token(0, 'd')");
+            assertEquals(2, results.size());
         }
         finally
         {
@@ -138,4 +162,10 @@ public class SelectWithTokenFunctionTest
     {
         execute("SELECT * FROM %s.compound_partition WHERE token(b, a) > token(0, 'c')");
     }
+
+    @Test(expected = InvalidRequestException.class)
+    public void testTokenFunctionOnEachPartitionKeyColumns() throws Throwable
+    {
+        execute("SELECT * FROM %s.compound_partition WHERE token(a) > token(0) and token(b)
> token('c')");
+    }
 }


Mime
View raw message