cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/3] git commit: Fix validation for IN where clauses with collection
Date Wed, 27 Mar 2013 10:42:34 GMT
Updated Branches:
  refs/heads/trunk f6106a18a -> 1527fabfc


Fix validation for IN where clauses with collection

patch by slebresne; reviewed by iamaleksey for CASSANDRA-5376


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

Branch: refs/heads/trunk
Commit: 193e56607bc26d8cbba404fd4197ec279bc073b8
Parents: b14fc6d
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Wed Mar 27 11:30:33 2013 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Wed Mar 27 11:30:33 2013 +0100

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../cassandra/cql3/statements/SelectStatement.java |   25 ++++++++++++--
 2 files changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/193e5660/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 3722f2d..7eaefaa 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -10,6 +10,7 @@
  * Make upgradeSSTable skip current version sstables by default (CASSANDRA-5366)
  * Optimize min/max timestamp collection (CASSANDRA-5373)
  * Invalid streamId in cql binary protocol when using invalid CL (CASSANDRA-5164)
+ * Fix validation for IN where clauses with collections (CASSANDRA-5376)
 Merged from 1.1:
  * cli: Quote ks and cf names in schema output when needed (CASSANDRA-5052)
  * Fix bad default for min/max timestamp in SSTableMetadata (CASSANDRA-5372)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/193e5660/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 d5a7425..b218975 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -406,7 +406,7 @@ public class SelectStatement implements CQLStatement
             return false;
 
         // However, collections always entails one
-        if (cfDef.hasCollections)
+        if (selectACollection())
             return true;
 
         // Otherwise, it is a range query if it has at least one the column alias
@@ -473,7 +473,7 @@ public class SelectStatement implements CQLStatement
         {
             // Collections require doing a slice query because a given collection is a
             // non-know set of columns, so we shouldn't get there
-            assert !cfDef.hasCollections;
+            assert !selectACollection();
 
             SortedSet<ByteBuffer> columns = new TreeSet<ByteBuffer>(cfDef.cfm.comparator);
 
@@ -505,6 +505,20 @@ public class SelectStatement implements CQLStatement
         }
     }
 
+    private boolean selectACollection()
+    {
+        if (!cfDef.hasCollections)
+            return false;
+
+        for (CFDefinition.Name name : selection.getColumnsList())
+        {
+            if (name.type instanceof CollectionType)
+                return true;
+        }
+
+        return false;
+    }
+
     private static ByteBuffer buildBound(Bound bound,
                                          Collection<CFDefinition.Name> names,
                                          Restriction[] restrictions,
@@ -986,9 +1000,12 @@ public class SelectStatement implements CQLStatement
                 }
                 // We only support IN for the last name so far
                 // TODO: #3885 allows us to extend to other parts (cf. #4762)
-                else if (restriction.eqValues.size() > 1 && i != stmt.columnRestrictions.length
- 1)
+                else if (restriction.eqValues.size() > 1)
                 {
-                    throw new InvalidRequestException(String.format("PRIMARY KEY part %s
cannot be restricted by IN relation", cname));
+                    if (i != stmt.columnRestrictions.length - 1)
+                        throw new InvalidRequestException(String.format("PRIMARY KEY part
%s cannot be restricted by IN relation", cname));
+                    else if (stmt.selectACollection())
+                        throw new InvalidRequestException(String.format("Cannot restrict
PRIMARY KEY part %s by IN relation as a collection is selected by the query", cname));
                 }
 
                 previous = cname;


Mime
View raw message