You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2015/01/30 19:06:41 UTC
cassandra git commit: Generalize IN to compound partition keys
Repository: cassandra
Updated Branches:
refs/heads/trunk 24a189ca6 -> 2e4ad069d
Generalize IN to compound partition keys
patch by blerer; reviewed by beobal for CASSANDRA-7855
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/2e4ad069
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/2e4ad069
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/2e4ad069
Branch: refs/heads/trunk
Commit: 2e4ad069d552167d0fc06d39bc8d622573f14792
Parents: 24a189c
Author: Benjamin Lerer <be...@datastax.com>
Authored: Fri Jan 30 19:05:35 2015 +0100
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Fri Jan 30 19:05:35 2015 +0100
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../cassandra/cql3/SingleColumnRelation.java | 20 +------------
.../cql3/SingleColumnRelationTest.java | 31 ++++++++++++++++++--
3 files changed, 30 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/2e4ad069/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index fd3510c..c7c9434 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -33,6 +33,7 @@
* Remove cassandra-cli (CASSANDRA-7920)
* Accept dollar quoted strings in CQL (CASSANDRA-7769)
* Make assassinate a first class command (CASSANDRA-7935)
+ * Support IN clause on any partition key column (CASSANDRA-7855)
* Support IN clause on any clustering column (CASSANDRA-4762)
* Improve compaction logging (CASSANDRA-7818)
* Remove YamlFileNetworkTopologySnitch (CASSANDRA-7917)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/2e4ad069/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 3db1195..78b4d5d 100644
--- a/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java
+++ b/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java
@@ -203,11 +203,6 @@ public final class SingleColumnRelation extends Relation
if (isIN())
{
- // For partition keys we only support IN for the last name so far
- checkFalse(columnDef.isPartitionKey() && !isLastPartitionKey(cfm, columnDef),
- "Partition KEY part %s cannot be restricted by IN relation (only the last part of the partition key can)",
- columnDef.name);
-
// We only allow IN on the row key and the clustering key so far, never on non-PK columns, and this even if
// there's an index
// Note: for backward compatibility reason, we conside a IN of 1 value the same as a EQ, so we let that
@@ -262,7 +257,7 @@ public final class SingleColumnRelation extends Relation
return Collections.singletonList(receiver);
}
- private ColumnSpecification makeCollectionReceiver(ColumnSpecification receiver, boolean forKey)
+ private static ColumnSpecification makeCollectionReceiver(ColumnSpecification receiver, boolean forKey)
{
return ((CollectionType<?>) receiver.type).makeCollectionReceiver(receiver, forKey);
}
@@ -277,19 +272,6 @@ public final class SingleColumnRelation extends Relation
return mapKey != null && isEQ();
}
- /**
- * Checks if the specified column is the last column of the partition key.
- *
- * @param cfm the column family meta data
- * @param columnDef the column to check
- * @return <code>true</code> if the specified column is the last column of the partition key, <code>false</code>
- * otherwise.
- */
- private static boolean isLastPartitionKey(CFMetaData cfm, ColumnDefinition columnDef)
- {
- return columnDef.position() == cfm.partitionKeyColumns().size() - 1;
- }
-
private boolean canHaveOnlyOneValue()
{
return isEQ() || (isIN() && inValues != null && inValues.size() == 1);
http://git-wip-us.apache.org/repos/asf/cassandra/blob/2e4ad069/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java b/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java
index f505a04..4e4cc50 100644
--- a/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java
@@ -175,18 +175,43 @@ public class SingleColumnRelationTest extends CQLTester
execute("insert into %s (a, b, c, d) values (?, ?, ?, ?)", "first", 1, 1, 1);
execute("insert into %s (a, b, c, d) values (?, ?, ?, ?)", "first", 2, 2, 2);
execute("insert into %s (a, b, c, d) values (?, ?, ?, ?)", "first", 3, 3, 3);
+ execute("insert into %s (a, b, c, d) values (?, ?, ?, ?)", "first", 4, 4, 4);
+ execute("insert into %s (a, b, c, d) values (?, ?, ?, ?)", "second", 1, 1, 1);
execute("insert into %s (a, b, c, d) values (?, ?, ?, ?)", "second", 4, 4, 4);
- assertInvalidMessage("Partition KEY part a cannot be restricted by IN relation (only the last part of the partition key can)",
+ assertRows(execute("select * from %s where a = ? and b = ?", "first", 2),
+ row("first", 2, 2, 2));
+
+ assertRows(execute("select * from %s where a in (?, ?) and b in (?, ?)", "first", "second", 2, 3),
+ row("first", 2, 2, 2),
+ row("first", 3, 3, 3));
+
+ assertRows(execute("select * from %s where a in (?, ?) and b = ?", "first", "second", 4),
+ row("first", 4, 4, 4),
+ row("second", 4, 4, 4));
+
+ assertRows(execute("select * from %s where a = ? and b in (?, ?)", "first", 3, 4),
+ row("first", 3, 3, 3),
+ row("first", 4, 4, 4));
+
+ assertRows(execute("select * from %s where a in (?, ?) and b in (?, ?)", "first", "second", 1, 4),
+ row("first", 1, 1, 1),
+ row("first", 4, 4, 4),
+ row("second", 1, 1, 1),
+ row("second", 4, 4, 4));
+
+ assertInvalidMessage("Partition key parts: b must be restricted as other parts are",
"select * from %s where a in (?, ?)", "first", "second");
- assertInvalidMessage("Partition KEY part a cannot be restricted by IN relation (only the last part of the partition key can)",
- "select * from %s where a in (?, ?) and b in (?, ?)", "first", "second", 2, 3);
assertInvalidMessage("Partition key parts: b must be restricted as other parts are",
"select * from %s where a = ?", "first");
assertInvalidMessage("b cannot be restricted by more than one relation if it includes a IN",
"select * from %s where a = ? AND b IN (?, ?) AND b = ?", "first", 2, 2, 3);
assertInvalidMessage("b cannot be restricted by more than one relation if it includes an Equal",
"select * from %s where a = ? AND b = ? AND b IN (?, ?)", "first", 2, 2, 3);
+ assertInvalidMessage("a cannot be restricted by more than one relation if it includes a IN",
+ "select * from %s where a IN (?, ?) AND a = ? AND b = ?", "first", "second", "first", 3);
+ assertInvalidMessage("a cannot be restricted by more than one relation if it includes an Equal",
+ "select * from %s where a = ? AND a IN (?, ?) AND b IN (?, ?)", "first", "second", "first", 2, 3);
}
@Test