cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject git commit: Refuse conditions on deletes unless full PK is given
Date Fri, 17 Oct 2014 09:44:01 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.0 6cabd252b -> 29a8b882d


Refuse conditions on deletes unless full PK is given

patch by thobbs; reviewed by slebresne for CASSANDRA-6430


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

Branch: refs/heads/cassandra-2.0
Commit: 29a8b882d8f4192588b85b77c41c00942508b8ce
Parents: 6cabd25
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Fri Oct 17 11:43:31 2014 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Fri Oct 17 11:43:31 2014 +0200

----------------------------------------------------------------------
 CHANGES.txt                                      |  1 +
 .../cql3/statements/DeleteStatement.java         | 19 +++++++++++++++++++
 .../cql3/statements/ModificationStatement.java   | 14 +++++++++++++-
 3 files changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/29a8b882/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 8c4fc15..544cf9a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.0.11:
+ * Reject conditions on DELETE unless full PK is given (CASSANDRA-6430)
  * Properly reject the token function DELETE (CASSANDRA-7747)
  * Force batchlog replay before decommissioning a node (CASSANDRA-7446)
  * Fix hint replay with many accumulated expired hints (CASSANDRA-6998)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/29a8b882/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java b/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
index 902add4..6c1c6ed 100644
--- a/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
@@ -20,6 +20,8 @@ package org.apache.cassandra.cql3.statements;
 import java.nio.ByteBuffer;
 import java.util.*;
 
+import com.google.common.collect.Iterators;
+
 import org.apache.cassandra.cql3.*;
 import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.db.*;
@@ -92,6 +94,23 @@ public class DeleteStatement extends ModificationStatement
         }
     }
 
+    protected void validateWhereClauseForConditions() throws InvalidRequestException
+    {
+        Iterator<CFDefinition.Name> iterator = Iterators.concat(cfm.getCfDef().partitionKeys().iterator(),
cfm.getCfDef().clusteringColumns().iterator());
+        while (iterator.hasNext())
+        {
+            CFDefinition.Name name = iterator.next();
+            Restriction restriction = processedKeys.get(name.name);
+            if (restriction == null || !(restriction.isEQ() || restriction.isIN()))
+            {
+                throw new InvalidRequestException(
+                        String.format("DELETE statements must restrict all PRIMARY KEY columns
with equality relations in order " +
+                                      "to use IF conditions, but column '%s' is not restricted",
name.name));
+            }
+        }
+
+    }
+
     public static class Parsed extends ModificationStatement.Parsed
     {
         private final List<Operation.RawDeletion> deletions;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/29a8b882/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
index 006873d..adb0084 100644
--- a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
@@ -62,7 +62,7 @@ public abstract class ModificationStatement implements CQLStatement, MeasurableF
     public final CFMetaData cfm;
     public final Attributes attrs;
 
-    private final Map<ColumnIdentifier, Restriction> processedKeys = new HashMap<ColumnIdentifier,
Restriction>();
+    protected final Map<ColumnIdentifier, Restriction> processedKeys = new HashMap<>();
     private final List<Operation> columnOperations = new ArrayList<Operation>();
 
     private int boundTerms;
@@ -747,6 +747,16 @@ public abstract class ModificationStatement implements CQLStatement,
MeasurableF
         return new UpdateParameters(cfm, variables, getTimestamp(now, variables), getTimeToLive(variables),
rows);
     }
 
+    /**
+     * If there are conditions on the statement, this is called after the where clause and
conditions have been
+     * processed to check that they are compatible.
+     * @throws InvalidRequestException
+     */
+    protected void validateWhereClauseForConditions() throws InvalidRequestException
+    {
+        //  no-op by default
+    }
+
     public static abstract class Parsed extends CFStatement
     {
         protected final Attributes.Raw attrs;
@@ -827,6 +837,8 @@ public abstract class ModificationStatement implements CQLStatement, MeasurableF
                         }
                     }
                 }
+
+                stmt.validateWhereClauseForConditions();
             }
 
             stmt.boundTerms = boundNames.getCollectedCount() - collected;


Mime
View raw message