cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [4/5] git commit: Fix validation of IN with 2ndary indexes
Date Thu, 19 Sep 2013 10:37:28 GMT
Fix validation of IN with 2ndary indexes

patch by slebresne; reviewed by iamaleskey for CASSANDRA-6050


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

Branch: refs/heads/trunk
Commit: a0abadfdb5721f6f595b6f9e33ed2bf44603d2fe
Parents: 2c316af
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Thu Sep 19 12:35:43 2013 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Thu Sep 19 12:35:43 2013 +0200

----------------------------------------------------------------------
 CHANGES.txt                                         |  1 +
 .../cassandra/cql3/statements/Restriction.java      | 16 ++++++++++++++++
 .../cassandra/cql3/statements/SelectStatement.java  |  7 ++++++-
 3 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/a0abadfd/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 6003ed2..d101c74 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -25,6 +25,7 @@
  * Paging filter empty rows too agressively (CASSANDRA-6040)
  * Support variadic parameters for IN clauses (CASSANDRA-4210)
  * cqlsh: return the result of CAS writes (CASSANDRA-5796)
+ * Fix validation of IN clauses with 2ndary indexes (CASSANDRA-6050)
 Merged from 1.2:
  * Avoid second-guessing out-of-space state (CASSANDRA-5605)
  * Tuning knobs for dealing with large blobs and many CFs (CASSANDRA-5982)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a0abadfd/src/java/org/apache/cassandra/cql3/statements/Restriction.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/Restriction.java b/src/java/org/apache/cassandra/cql3/statements/Restriction.java
index 45cc607..3a3aa05 100644
--- a/src/java/org/apache/cassandra/cql3/statements/Restriction.java
+++ b/src/java/org/apache/cassandra/cql3/statements/Restriction.java
@@ -112,6 +112,12 @@ public interface Restriction
             return true;
         }
 
+        // Used when we need to know if it's a IN with just one value before we have
+        // the bind variables. This is ugly and only there for backward compatiblity
+        // because we used to treate IN with 1 value like an EQ and need to preserve
+        // this behavior.
+        public abstract boolean canHaveOnlyOneValue();
+
         public boolean isOnToken()
         {
             return false;
@@ -134,6 +140,11 @@ public interface Restriction
                 return buffers;
             }
 
+            public boolean canHaveOnlyOneValue()
+            {
+                return values.size() == 1;
+            }
+
             @Override
             public String toString()
             {
@@ -158,6 +169,11 @@ public interface Restriction
                 return lval.elements;
             }
 
+            public boolean canHaveOnlyOneValue()
+            {
+                return false;
+            }
+
             @Override
             public String toString()
             {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a0abadfd/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 c85864f..86dad85 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -1124,7 +1124,12 @@ public class SelectStatement implements CQLStatement
                     case VALUE_ALIAS:
                         throw new InvalidRequestException(String.format("Predicates on the
non-primary-key column (%s) of a COMPACT table are not yet supported", name.name));
                     case COLUMN_METADATA:
-                        stmt.metadataRestrictions.put(name, updateRestriction(name, stmt.metadataRestrictions.get(name),
rel, names));
+                        // We only all IN on the row key and last clustering key so far,
never on non-PK columns, and this even if there's an index
+                        Restriction r = updateRestriction(name, stmt.metadataRestrictions.get(name),
rel, names);
+                        if (r.isIN() && !((Restriction.IN)r).canHaveOnlyOneValue())
+                            // Note: for backward compatibility reason, we conside a IN of
1 value the same as a EQ, so we let that slide.
+                            throw new InvalidRequestException(String.format("IN predicates
on non-primary-key columns (%s) is not yet supported", name));
+                        stmt.metadataRestrictions.put(name, r);
                         break;
                 }
             }


Mime
View raw message