You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ty...@apache.org on 2015/02/19 20:21:13 UTC

[1/2] cassandra git commit: Fix token() + multi-column relation on clustering cols

Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 6065f2c8a -> e4980b3b8


Fix token() + multi-column relation on clustering cols

Patch by Tyler Hobbs; reviewed by Benjamin Lerer for CASSANDRA-8797


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

Branch: refs/heads/cassandra-2.1
Commit: ee160a971a52134a7d2715cb1123472f539c0ace
Parents: 6214e35
Author: Tyler Hobbs <ty...@datastax.com>
Authored: Thu Feb 19 13:16:56 2015 -0600
Committer: Tyler Hobbs <ty...@datastax.com>
Committed: Thu Feb 19 13:16:56 2015 -0600

----------------------------------------------------------------------
 CHANGES.txt                                              |  2 ++
 src/java/org/apache/cassandra/cql3/Relation.java         |  5 +++++
 .../org/apache/cassandra/cql3/SingleColumnRelation.java  |  5 +++++
 .../cassandra/cql3/statements/SelectStatement.java       |  6 +++++-
 .../cassandra/cql3/SelectWithTokenFunctionTest.java      | 11 +++++++++++
 5 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/ee160a97/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 09d6d2f..f2b4469 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
 2.0.13:
+ * Fix combining token() function with multi-column relations on
+   clustering columns (CASSANDRA-8797)
  * Make CFS.markReferenced() resistant to bad refcounting (CASSANDRA-8829)
  * Fix StreamTransferTask abort/complete bad refcounting (CASSANDRA-8815)
  * Fix AssertionError when querying a DESC clustering ordered

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ee160a97/src/java/org/apache/cassandra/cql3/Relation.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/Relation.java b/src/java/org/apache/cassandra/cql3/Relation.java
index 0f1366d..e7c5f2d 100644
--- a/src/java/org/apache/cassandra/cql3/Relation.java
+++ b/src/java/org/apache/cassandra/cql3/Relation.java
@@ -54,4 +54,9 @@ public abstract class Relation {
     }
 
     public abstract boolean isMultiColumn();
+
+    public boolean isOnToken()
+    {
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ee160a97/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java b/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java
index d63493e..388d938 100644
--- a/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java
+++ b/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java
@@ -84,6 +84,11 @@ public class SingleColumnRelation extends Relation
         return false;
     }
 
+    public boolean isOnToken()
+    {
+        return onToken;
+    }
+
     public SingleColumnRelation withNonStrictOperator()
     {
         switch (relationType)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ee160a97/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 2fa57b9..59ed6e1 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -1906,8 +1906,12 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
             Iterator<Name> iter = Iterators.cycle(cfDef.partitionKeys());
             for (Relation relation : whereClause)
             {
+                if (!relation.isOnToken())
+                    continue;
+
+                assert !relation.isMultiColumn() : "Unexpectedly got multi-column token relation";
                 SingleColumnRelation singleColumnRelation = (SingleColumnRelation) relation;
-                if (singleColumnRelation.onToken && !cfDef.get(singleColumnRelation.getEntity().prepare(cfDef.cfm)).equals(iter.next()))
+                if (!cfDef.get(singleColumnRelation.getEntity().prepare(cfDef.cfm)).equals(iter.next()))
                     throw new InvalidRequestException(String.format("The token function arguments must be in the partition key order: %s",
                                                                     Joiner.on(',').join(cfDef.partitionKeys())));
             }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ee160a97/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 9199862..c222f35 100644
--- a/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java
+++ b/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java
@@ -47,6 +47,7 @@ public class SelectWithTokenFunctionTest
         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))");
+        executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.compound_with_clustering (a int, b int, c int, d int, PRIMARY KEY ((a, b), c, d))");
         clientState = ClientState.forInternalCalls();
     }
 
@@ -168,4 +169,14 @@ public class SelectWithTokenFunctionTest
     {
         execute("SELECT * FROM %s.compound_partition WHERE token(a) > token(0) and token(b) > token('c')");
     }
+
+    @Test
+    public void testTokenFunctionWithCompoundPartitionAndClusteringCols() throws Throwable
+    {
+        // just test that the queries don't error
+        execute("SELECT * FROM %s.compound_with_clustering WHERE token(a, b) > token(0, 0) AND c > 10 ALLOW FILTERING;");
+        execute("SELECT * FROM %s.compound_with_clustering WHERE c > 10 AND token(a, b) > token(0, 0) ALLOW FILTERING;");
+        execute("SELECT * FROM %s.compound_with_clustering WHERE token(a, b) > token(0, 0) AND (c, d) > (0, 0) ALLOW FILTERING;");
+        execute("SELECT * FROM %s.compound_with_clustering WHERE (c, d) > (0, 0) AND token(a, b) > token(0, 0) ALLOW FILTERING;");
+    }
 }


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

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

Conflicts:
	CHANGES.txt
	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/e4980b3b
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/e4980b3b
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/e4980b3b

Branch: refs/heads/cassandra-2.1
Commit: e4980b3b8df0d15aef0f9f24159064c7be86d111
Parents: 6065f2c ee160a9
Author: Tyler Hobbs <ty...@datastax.com>
Authored: Thu Feb 19 13:21:02 2015 -0600
Committer: Tyler Hobbs <ty...@datastax.com>
Committed: Thu Feb 19 13:21:02 2015 -0600

----------------------------------------------------------------------
 CHANGES.txt                                              |  2 ++
 src/java/org/apache/cassandra/cql3/Relation.java         |  5 +++++
 .../org/apache/cassandra/cql3/SingleColumnRelation.java  |  5 +++++
 .../cassandra/cql3/statements/SelectStatement.java       |  6 +++++-
 .../cassandra/cql3/SelectWithTokenFunctionTest.java      | 11 +++++++++++
 5 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4980b3b/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index 9458627,f2b4469..3b6ce5d
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -1,19 -1,6 +1,21 @@@
 -2.0.13:
 +2.1.4
 + * Fix CommitLog.forceRecycleAllSegments() memory access error (CASSANDRA-8812)
 + * Improve assertions in Memory (CASSANDRA-8792)
 + * Fix SSTableRewriter cleanup (CASSANDRA-8802)
 + * Introduce SafeMemory for CompressionMetadata.Writer (CASSANDRA-8758)
 + * 'nodetool info' prints exception against older node (CASSANDRA-8796)
 + * Ensure SSTableReader.last corresponds exactly with the file end (CASSANDRA-8750)
 + * Make SSTableWriter.openEarly more robust and obvious (CASSANDRA-8747)
 + * Enforce SSTableReader.first/last (CASSANDRA-8744)
 + * Cleanup SegmentedFile API (CASSANDRA-8749)
 + * Avoid overlap with early compaction replacement (CASSANDRA-8683)
 + * Safer Resource Management++ (CASSANDRA-8707)
 + * Write partition size estimates into a system table (CASSANDRA-7688)
 + * cqlsh: Fix keys() and full() collection indexes in DESCRIBE output
 +   (CASSANDRA-8154)
 +Merged from 2.0:
+  * Fix combining token() function with multi-column relations on
+    clustering columns (CASSANDRA-8797)
   * Make CFS.markReferenced() resistant to bad refcounting (CASSANDRA-8829)
   * Fix StreamTransferTask abort/complete bad refcounting (CASSANDRA-8815)
   * Fix AssertionError when querying a DESC clustering ordered

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4980b3b/src/java/org/apache/cassandra/cql3/Relation.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4980b3b/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4980b3b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index 08777c7,59ed6e1..9099ba7
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@@ -1933,18 -1898,22 +1933,22 @@@ public class SelectStatement implement
          /**
           * 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<Name> iter = Iterators.cycle(cfDef.partitionKeys());
 +            Iterator<ColumnDefinition> iter = Iterators.cycle(cfm.partitionKeyColumns());
              for (Relation relation : whereClause)
              {
+                 if (!relation.isOnToken())
+                     continue;
+ 
+                 assert !relation.isMultiColumn() : "Unexpectedly got multi-column token relation";
                  SingleColumnRelation singleColumnRelation = (SingleColumnRelation) relation;
-                 if (singleColumnRelation.onToken && !cfm.getColumnDefinition(singleColumnRelation.getEntity().prepare(cfm)).equals(iter.next()))
 -                if (!cfDef.get(singleColumnRelation.getEntity().prepare(cfDef.cfm)).equals(iter.next()))
++                if (!cfm.getColumnDefinition(singleColumnRelation.getEntity().prepare(cfm)).equals(iter.next()))
                      throw new InvalidRequestException(String.format("The token function arguments must be in the partition key order: %s",
 -                                                                    Joiner.on(',').join(cfDef.partitionKeys())));
 +                                                                    Joiner.on(',').join(cfm.partitionKeyColumns())));
              }
          }
  

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4980b3b/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java
index 6f9f5e2,c222f35..b2a972b
--- a/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java
+++ b/test/unit/org/apache/cassandra/cql3/SelectWithTokenFunctionTest.java
@@@ -44,23 -138,45 +44,34 @@@ public class SelectWithTokenFunctionTes
      }
  
      @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')");
      }
+ 
+     @Test
+     public void testTokenFunctionWithCompoundPartitionAndClusteringCols() throws Throwable
+     {
++        createTable("CREATE TABLE IF NOT EXISTS %s (a int, b int, c int, d int, PRIMARY KEY ((a, b), c, d))");
+         // just test that the queries don't error
 -        execute("SELECT * FROM %s.compound_with_clustering WHERE token(a, b) > token(0, 0) AND c > 10 ALLOW FILTERING;");
 -        execute("SELECT * FROM %s.compound_with_clustering WHERE c > 10 AND token(a, b) > token(0, 0) ALLOW FILTERING;");
 -        execute("SELECT * FROM %s.compound_with_clustering WHERE token(a, b) > token(0, 0) AND (c, d) > (0, 0) ALLOW FILTERING;");
 -        execute("SELECT * FROM %s.compound_with_clustering WHERE (c, d) > (0, 0) AND token(a, b) > token(0, 0) ALLOW FILTERING;");
++        execute("SELECT * FROM %s WHERE token(a, b) > token(0, 0) AND c > 10 ALLOW FILTERING;");
++        execute("SELECT * FROM %s WHERE c > 10 AND token(a, b) > token(0, 0) ALLOW FILTERING;");
++        execute("SELECT * FROM %s WHERE token(a, b) > token(0, 0) AND (c, d) > (0, 0) ALLOW FILTERING;");
++        execute("SELECT * FROM %s WHERE (c, d) > (0, 0) AND token(a, b) > token(0, 0) ALLOW FILTERING;");
+     }
  }