You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by al...@apache.org on 2014/09/24 03:59:24 UTC

[1/3] git commit: Fix CASSANDRA-6075

Repository: cassandra
Updated Branches:
  refs/heads/trunk 6618bd89d -> dffdae0c9


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/trunk
Commit: b1166c09983b1678cbc4b241f1da860930c571a5
Parents: 62db20a
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Tue Sep 23 18:51:58 2014 -0700
Committer: Aleksey Yeschenko <al...@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')");
+    }
 }


[2/3] git commit: Merge branch 'cassandra-2.0' into cassandra-2.1

Posted by al...@apache.org.
Merge branch 'cassandra-2.0' into cassandra-2.1

Conflicts:
	src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
	test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java


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

Branch: refs/heads/trunk
Commit: c65ef9af6529086ef1793d24b3f387012bf59091
Parents: c2c9835 b1166c0
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Tue Sep 23 18:59:00 2014 -0700
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Tue Sep 23 18:59:00 2014 -0700

----------------------------------------------------------------------
 .../cassandra/cql3/statements/SelectStatement.java       |  4 ++--
 .../cassandra/cql3/SelectWithTokenFunctionTest.java      | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/c65ef9af/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index 22c8468,aadd0bd..ccda356
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@@ -1821,22 -1813,22 +1821,22 @@@ public class SelectStatement implement
                      // index with filtering, we'll need to handle it though.
                      throw new InvalidRequestException("Only EQ and IN relation are supported on the partition key (unless you use the token() function)");
                  }
 -                previous = cname;
 +                previous = cdef;
              }
  
-             if (stmt.onToken && cfm.partitionKeyColumns().size() > 0)
+             if (stmt.onToken)
 -                checkTokenFunctionArgumentsOrder(cfDef);
 +                checkTokenFunctionArgumentsOrder(cfm);
          }
  
          /**
           * Checks that the column identifiers used as argument for the token function have been specified in the
           * partition key order.
 -         * @param cfDef the Column Family Definition
 +         * @param cfm the Column Family MetaData
           * @throws InvalidRequestException if the arguments have not been provided in the proper order.
           */
 -        private void checkTokenFunctionArgumentsOrder(CFDefinition cfDef) throws InvalidRequestException
 +        private void checkTokenFunctionArgumentsOrder(CFMetaData cfm) throws InvalidRequestException
          {
-             Iterator<ColumnDefinition> iter = cfm.partitionKeyColumns().iterator();
 -            Iterator<Name> iter = Iterators.cycle(cfDef.partitionKeys());
++            Iterator<ColumnDefinition> iter = Iterators.cycle(cfm.partitionKeyColumns());
              for (Relation relation : whereClause)
              {
                  SingleColumnRelation singleColumnRelation = (SingleColumnRelation) relation;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c65ef9af/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java
index 73a7209,9199862..6f9f5e2
--- a/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java
+++ b/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java
@@@ -17,39 -17,155 +17,50 @@@
   */
  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;
 -import org.junit.BeforeClass;
  import org.junit.Test;
 -import org.slf4j.Logger;
 -import org.slf4j.LoggerFactory;
  
 -import static org.apache.cassandra.cql3.QueryProcessor.process;
 -import static org.apache.cassandra.cql3.QueryProcessor.processInternal;
 -import static org.junit.Assert.assertEquals;
 -
 -public class SelectWithTokenFunctionTest
 +public class SelectWithTokenFunctionTest extends CQLTester
  {
 -    private static final Logger logger = LoggerFactory.getLogger(SelectWithTokenFunctionTest.class);
 -    static ClientState clientState;
 -    static String keyspace = "token_function_test";
 -
 -    @BeforeClass
 -    public static void setUpClass() throws Throwable
 -    {
 -        SchemaLoader.loadSchema();
 -        executeSchemaChange("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}");
 -        executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.single_partition (a int PRIMARY KEY, b text)");
 -        executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.compound_partition (a int, b text, PRIMARY KEY ((a, b)))");
 -        executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.single_clustering (a int, b text, PRIMARY KEY (a, b))");
 -        clientState = ClientState.forInternalCalls();
 -    }
 -
 -    @AfterClass
 -    public static void stopGossiper()
 -    {
 -        Gossiper.instance.stop();
 -    }
 -
 -    private static void executeSchemaChange(String query) throws Throwable
 -    {
 -        try
 -        {
 -            process(String.format(query, keyspace), ConsistencyLevel.ONE);
 -        }
 -        catch (RuntimeException exc)
 -        {
 -            throw exc.getCause();
 -        }
 -    }
 -
 -    private static UntypedResultSet execute(String query) throws Throwable
 -    {
 -        try
 -        {
 -            return processInternal(String.format(query, keyspace));
 -        }
 -        catch (RuntimeException exc)
 -        {
 -            if (exc.getCause() != null)
 -                throw exc.getCause();
 -            throw exc;
 -        }
 -    }
 -
      @Test
 -    public void testTokenFunctionWithSinglePartitionArgument() throws Throwable
 -    {
 -        execute("INSERT INTO %s.single_partition (a, b) VALUES (0, 'a')");
 -
 -        try
 -        {
 -            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
 -        {
 -            execute("DELETE FROM %s.single_partition WHERE a = 0");
 -        }
 -    }
 -
 -    @Test(expected = InvalidRequestException.class)
 -    public void testTokenFunctionWithWrongLiteralArgument() throws Throwable
 -    {
 -        execute("SELECT * FROM %s.single_partition WHERE token(a) > token('a')");
 -    }
 -
 -    @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
 +    public void testTokenFunctionWithSingleColumnPartitionKey() throws Throwable
      {
 -        execute("SELECT * FROM %s.single_clustering WHERE token(a) >= token(0) and token(a) = token(1)");
 +        createTable("CREATE TABLE IF NOT EXISTS %s (a int PRIMARY KEY, b text)");
 +        execute("INSERT INTO %s (a, b) VALUES (0, 'a')");
 +
 +        assertRows(execute("SELECT * FROM %s WHERE token(a) >= token(?)", 0), row(0, "a"));
++        assertRows(execute("SELECT * FROM %s WHERE token(a) >= token(?) and token(a) < token(?)", 0, 1), row(0, "a"));
 +        assertInvalid("SELECT * FROM %s WHERE token(a) > token(?)", "a");
 +        assertInvalid("SELECT * FROM %s WHERE token(a, b) >= token(?, ?)", "b", 0);
++        assertInvalid("SELECT * FROM %s WHERE token(a) >= token(?) and token(a) >= token(?)", 0, 1);
++        assertInvalid("SELECT * FROM %s WHERE token(a) >= token(?) and token(a) = token(?)", 0, 1);
++        assertInvalidSyntax("SELECT * FROM %s WHERE token(a) = token(?) and token(a) IN (token(?))", 0, 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)
 +    @Test
      public void testTokenFunctionWithPartitionKeyAndClusteringKeyArguments() throws Throwable
      {
 -        execute("SELECT * FROM %s.single_clustering WHERE token(a, b) > token(0, 'c')");
 -    }
 -
 -    @Test(expected = InvalidRequestException.class)
 -    public void testTokenFunctionWithCompoundPartitionKeyAndWrongLiteralArgument() throws Throwable
 -    {
 -        execute("SELECT * FROM %s.single_partition WHERE token(a, b) >= token('c', 0)");
 +        createTable("CREATE TABLE IF NOT EXISTS %s (a int, b text, PRIMARY KEY (a, b))");
 +        assertInvalid("SELECT * FROM %s WHERE token(a, b) > token(0, 'c')");
      }
  
      @Test
 -    public void testTokenFunctionWithCompoundPartition() throws Throwable
 -    {
 -        execute("INSERT INTO %s.compound_partition (a, b) VALUES (0, 'a')");
 -        execute("INSERT INTO %s.compound_partition (a, b) VALUES (0, 'b')");
 -        execute("INSERT INTO %s.compound_partition (a, b) VALUES (0, 'c')");
 -
 -        try
 -        {
 -            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
 -        {
 -            execute("DELETE FROM %s.compound_partition WHERE a = 0 and b in ('a', 'b', 'c')");
 -        }
 -    }
 -
 -    @Test(expected = InvalidRequestException.class)
 -    public void testTokenFunctionWithCompoundPartitionKeyAndColumnIdentifierInWrongOrder() throws Throwable
 -    {
 -        execute("SELECT * FROM %s.compound_partition WHERE token(b, a) > token(0, 'c')");
 -    }
 -
 -    @Test(expected = InvalidRequestException.class)
 -    public void testTokenFunctionOnEachPartitionKeyColumns() throws Throwable
 +    public void testTokenFunctionWithMultiColumnPartitionKey() throws Throwable
      {
 -        execute("SELECT * FROM %s.compound_partition WHERE token(a) > token(0) and token(b) > token('c')");
 +        createTable("CREATE TABLE IF NOT EXISTS %s (a int, b text, PRIMARY KEY ((a, b)))");
 +        execute("INSERT INTO %s (a, b) VALUES (0, 'a')");
 +        execute("INSERT INTO %s (a, b) VALUES (0, 'b')");
 +        execute("INSERT INTO %s (a, b) VALUES (0, 'c')");
 +
 +        assertRows(execute("SELECT * FROM %s WHERE token(a, b) > token(?, ?)", 0, "a"),
 +                   row(0, "b"),
 +                   row(0, "c"));
++        assertRows(execute("SELECT * FROM %s WHERE token(a, b) > token(?, ?) and token(a, b) < token(?, ?)",
++                           0, "a",
++                           0, "d"),
++                   row(0, "b"),
++                   row(0, "c"));
++        assertInvalid("SELECT * FROM %s WHERE token(a) > token(?) and token(b) > token(?)", 0, "a");
++        assertInvalid("SELECT * FROM %s WHERE token(a) > token(?, ?) and token(a) < token(?, ?) and token(b) > token(?, ?) ", 0, "a", 0, "d", 0, "a");
 +        assertInvalid("SELECT * FROM %s WHERE token(b, a) > token(0, 'c')");
      }
  }


[3/3] git commit: Merge branch 'cassandra-2.1' into trunk

Posted by al...@apache.org.
Merge branch 'cassandra-2.1' into trunk


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

Branch: refs/heads/trunk
Commit: dffdae0c94352d99ebc147dae6282670315e8fd2
Parents: 6618bd8 c65ef9a
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Tue Sep 23 18:59:18 2014 -0700
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Tue Sep 23 18:59:18 2014 -0700

----------------------------------------------------------------------
 .../cassandra/cql3/statements/SelectStatement.java       |  4 ++--
 .../cassandra/cql3/SelectWithTokenFunctionTest.java      | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/dffdae0c/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------