cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ble...@apache.org
Subject [1/2] cassandra git commit: Fix conditions on static columns
Date Tue, 20 Oct 2015 12:07:42 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 728f94e79 -> a33790730


Fix conditions on static columns

patch by Benjamin Lerer; reviewed by Sylvain Lebresne for CASSANDRA-10264


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

Branch: refs/heads/cassandra-2.2
Commit: 9b3b1cb03c6536d40adfcfa8f93577079b9a9d1d
Parents: b84ed11
Author: blerer <benjamin.lerer@datastax.com>
Authored: Tue Oct 20 13:54:46 2015 +0200
Committer: blerer <benjamin.lerer@datastax.com>
Committed: Tue Oct 20 13:54:46 2015 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 pylib/cqlshlib/cql3handling.py                  |  2 +-
 .../cql3/statements/ModificationStatement.java  | 24 ++++++++++++++++++--
 .../operations/InsertUpdateIfConditionTest.java | 12 +++++++++-
 4 files changed, 35 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/9b3b1cb0/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 7358689..b17929c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.12
+ * Fix conditions on static columns (CASSANDRA-10264)
  * AssertionError: attempted to delete non-existing file CommitLog (CASSANDRA-10377)
  * Merge range tombstones during compaction (CASSANDRA-7953)
  * (cqlsh) Distinguish negative and positive infinity in output (CASSANDRA-10523)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/9b3b1cb0/pylib/cqlshlib/cql3handling.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py
index 5f93003..49970e4 100644
--- a/pylib/cqlshlib/cql3handling.py
+++ b/pylib/cqlshlib/cql3handling.py
@@ -143,7 +143,7 @@ JUNK ::= /([ \t\r\f\v]+|(--|[/][/])[^\n\r]*([\n\r]|$)|[/][*].*?[*][/])/
;
 <star> ::=          "*" ;
 <endtoken> ::=      ";" ;
 <op> ::=            /[-+=,().]/ ;
-<cmp> ::=           /[<>]=?/ ;
+<cmp> ::=           /[<>!]=?/ ;
 <brackets> ::=      /[][{}]/ ;
 
 <integer> ::= "-"? <wholenumber> ;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/9b3b1cb0/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 37b46ae..75a3b40 100644
--- a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
@@ -29,7 +29,6 @@ import org.apache.cassandra.config.ColumnDefinition;
 import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.cql3.*;
 import org.apache.cassandra.db.*;
-import org.apache.cassandra.db.composites.AbstractCellNameType;
 import org.apache.cassandra.db.composites.CBuilder;
 import org.apache.cassandra.db.composites.Composite;
 import org.apache.cassandra.db.filter.ColumnSlice;
@@ -339,7 +338,7 @@ public abstract class ModificationStatement implements CQLStatement
         //   UPDATE t SET s = 3 WHERE k = 0 AND v = 1
         //   DELETE v FROM t WHERE k = 0 AND v = 1
         // sounds like you don't really understand what your are doing.
-        if (setsStaticColumns && !setsRegularColumns)
+        if (appliesOnlyToStaticColumns())
         {
             // If we set no non-static columns, then it's fine not to have clustering columns
             if (hasNoClusteringColumns)
@@ -361,6 +360,27 @@ public abstract class ModificationStatement implements CQLStatement
         return createClusteringPrefixBuilderInternal(options);
     }
 
+    /**
+     * Checks that the modification only apply to static columns.
+     * @return <code>true</code> if the modification only apply to static columns,
<code>false</code> otherwise.
+     */
+    private boolean appliesOnlyToStaticColumns()
+    {
+        return setsStaticColumns && !appliesToRegularColumns();
+    }
+
+    /**
+     * Checks that the modification apply to regular columns.
+     * @return <code>true</code> if the modification apply to regular columns,
<code>false</code> otherwise.
+     */
+    private boolean appliesToRegularColumns()
+    {
+        // If we have regular operations, this applies to regular columns.
+        // Otherwise, if the statement is a DELETE and columnOperations is empty, this means
we have no operations,
+        // which for a DELETE means a full row deletion. Which means the operation applies
to all columns and regular ones in particular.
+        return setsRegularColumns || (type == StatementType.DELETE && columnOperations.isEmpty());
+    }
+
     private Composite createClusteringPrefixBuilderInternal(QueryOptions options)
     throws InvalidRequestException
     {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/9b3b1cb0/test/unit/org/apache/cassandra/cql3/validation/operations/InsertUpdateIfConditionTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/InsertUpdateIfConditionTest.java
b/test/unit/org/apache/cassandra/cql3/validation/operations/InsertUpdateIfConditionTest.java
index 0438f13..e94011b 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/InsertUpdateIfConditionTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/InsertUpdateIfConditionTest.java
@@ -26,7 +26,6 @@ import org.apache.cassandra.exceptions.SyntaxException;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 public class InsertUpdateIfConditionTest extends CQLTester
 {
@@ -181,6 +180,17 @@ public class InsertUpdateIfConditionTest extends CQLTester
         assertInvalid("DELETE FROM %s WHERE i = 0 IF EXISTS");
         assertInvalid("DELETE FROM %s WHERE k = 0 AND i > 0 IF EXISTS");
         assertInvalid("DELETE FROM %s WHERE k = 0 AND i > 0 IF v = 'foo'");
+
+        createTable("CREATE TABLE %s(k int, s int static, i int, v text, PRIMARY KEY(k, i))");
+        execute("INSERT INTO %s (k, s, i, v) VALUES ( 1, 1, 2, '1')");
+        assertRows(execute("DELETE v FROM %s WHERE k = 1 AND i = 2 IF s != 1"), row(false,
1));
+        assertRows(execute("DELETE v FROM %s WHERE k = 1 AND i = 2 IF s = 1"), row(true));
+        assertRows(execute("SELECT * FROM %s WHERE k = 1 AND i = 2"), row(1, 2, 1, null));
+
+        assertRows(execute("DELETE FROM %s WHERE  k = 1 AND i = 2 IF s != 1"), row(false,
1));
+        assertRows(execute("DELETE FROM %s WHERE k = 1 AND i = 2 IF s = 1"), row(true));
+        assertEmpty(execute("SELECT * FROM %s WHERE k = 1 AND i = 2"));
+        assertRows(execute("SELECT * FROM %s WHERE k = 1"), row(1, null, 1, null));
     }
 
     /**


Mime
View raw message