You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2022/03/01 12:08:29 UTC

[GitHub] [cassandra] blerer commented on a change in pull request #1458: CASSANDRA-15266 - 3.0

blerer commented on a change in pull request #1458:
URL: https://github.com/apache/cassandra/pull/1458#discussion_r816711654



##########
File path: src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java
##########
@@ -150,9 +150,14 @@ public StatementRestrictions(StatementType type,
          *     allow two IN for the same entity but that doesn't seem very useful)
          *   - The value_alias cannot be restricted in any way (we don't support wide rows with indexed value
          *     in CQL so far)
+         *   - CONTAINS and CONTAINS_KEY cannot be used with UPDATE or DELETE
          */
         for (Relation relation : whereClause.relations)
         {
+            if ((relation.isContains() || relation.isContainsKey()) && (type.isUpdate() || type.isDelete()))
+            {
+                throw invalidRequest("Cannot use %s with %s", type, relation.operator());

Review comment:
       I agree. This message makes more sense.

##########
File path: test/unit/org/apache/cassandra/cql3/validation/operations/UpdateTest.java
##########
@@ -189,6 +191,34 @@ private void testUpdate(boolean forceFlush) throws Throwable
         }
     }
 
+    @Test
+    public void testUpdateWithContains() throws Throwable
+    {
+        createTable("CREATE TABLE %s (a int, b frozen<map<int, int>>, c int, primary key (a, b))");
+        Map<Integer, Integer> testMap = new HashMap<>();
+        testMap.put(1, 1);
+        testMap.put(2, 2);
+        execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 1, testMap, 3);
+        assertRows(execute("SELECT * FROM %s"),
+                   row(1, testMap, 3));
+        assertInvalidMessage("Cannot use UPDATE with CONTAINS",
+                             "UPDATE %s SET c=3 WHERE a=1 AND b CONTAINS 1");
+    }
+
+    @Test
+    public void testUpdateWithContainsKey() throws Throwable
+    {
+        createTable("CREATE TABLE %s (a int, b frozen<map<int, int>>, c int, primary key (a, b))");
+        Map<Integer, Integer> testMap = new HashMap<>();
+        testMap.put(1, 1);
+        testMap.put(2, 2);
+        execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 1, testMap, 3);
+        assertRows(execute("SELECT * FROM %s"),
+                   row(1, testMap, 3));
+        assertInvalidMessage("Cannot use UPDATE with CONTAINS KEY",
+                             "UPDATE %s SET c=3 WHERE a=1 AND b CONTAINS KEY 1");
+    }
+

Review comment:
       I think that we could merge the 2 tests into one. 
   As each test requires cleaning up the tables and other slow operations having both tests together will minimize the amount of time spend to run the tests. 
   Same thing for the DELETE tests.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org