dcapwell commented on code in PR #2427:
URL: https://github.com/apache/cassandra/pull/2427#discussion_r1238747589


##########
src/java/org/apache/cassandra/service/accord/txn/TxnMultiUpdate.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.service.accord.txn;
+
+import java.io.IOException;
+import javax.annotation.Nullable;
+
+import accord.api.Data;
+import accord.api.Update;
+import accord.api.Write;
+import accord.primitives.Keys;
+import accord.primitives.Ranges;
+import accord.primitives.Seekables;
+import accord.primitives.Timestamp;
+import org.apache.cassandra.cache.IMeasurableMemory;
+import org.apache.cassandra.db.TypeSizes;
+import org.apache.cassandra.io.IVersionedSerializer;
+import org.apache.cassandra.io.util.DataInputPlus;
+import org.apache.cassandra.io.util.DataOutputPlus;
+
+public class TxnMultiUpdate implements Update, IMeasurableMemory
+{
+    private final Keys keys;
+    public final TxnUpdate[] updates;
+
+    public TxnMultiUpdate(TxnUpdate[] updates)
+    {
+        this.updates = updates;
+        Keys keys = Keys.EMPTY;
+        for (int i = 0; i < updates.length; i++) // TODO perf
+            keys = keys.with(updates[i].keys());
+
+        this.keys = keys;
+    }
+
+    @Override
+    public Seekables<?, ?> keys()
+    {
+        return keys;
+    }
+
+    @Override
+    public Write apply(Timestamp executeAt, @Nullable Data data)
+    {
+        for (int i = 0; i < updates.length; i++)
+        {
+            TxnUpdate update = updates[i];
+            if (update.checkCondition(data))
+            {
+                TxnData txnData = data != null ? ((TxnData) data) : new 
TxnData();
+                txnData.setSelectedBranch(i);

Review Comment:
   this shouldn't be around outside of this local processing, so doesn't look 
to help?



##########
src/java/org/apache/cassandra/service/accord/txn/TxnUpdate.java:
##########
@@ -57,7 +56,7 @@
 import static 
org.apache.cassandra.utils.ByteBufferUtil.serializedSizeWithVIntLength;
 import static org.apache.cassandra.utils.ByteBufferUtil.writeWithVIntLength;
 
-public class TxnUpdate implements Update

Review Comment:
   why?  when we don't have multiple conditions, we can safely just use this 
class



##########
test/unit/org/apache/cassandra/cql3/statements/TransactionStatementTest.java:
##########
@@ -359,12 +374,218 @@ public void 
shouldRejectLetSelectWithIncompletePartitionKey()
                   
.hasMessageContaining(String.format(ILLEGAL_RANGE_QUERY_MESSAGE, "LET 
assignment row1", "at [2:15]"));
     }
 
+    @Test
+    public void shouldRejectSelectDefinedOnTopLevelAndInBranches()
+    {
+        String query = "BEGIN TRANSACTION\n" +
+                       "  LET a = (SELECT * FROM ks.tbl1 WHERE k = 0 AND c = 
0);\n" +
+                       "  LET b = (SELECT * FROM ks.tbl1 WHERE k = 1 AND c = 
0);\n" +
+                       "  SELECT a.v;\n" +
+                       "  IF a.v = 1 THEN\n" +
+                       "    SELECT b.v;\n" +
+                       "    UPDATE ks.tbl1 SET v = a.v WHERE k=1 AND c=2;\n" +
+                       "  ELSE IF a.v = 2 THEN\n" +
+                       "    SELECT a.v;\n" +
+                       "    UPDATE ks.tbl1 SET v = b.v WHERE k=1 AND c=2;\n" +
+                       "  ELSE\n" +
+                       "    SELECT b.v;\n" +
+                       "  END IF\n" +
+                       "COMMIT TRANSACTION";
+
+        Assertions.assertThatThrownBy(() -> prepare(query))
+                    .isInstanceOf(InvalidRequestException.class)
+                    
.hasMessageContaining(String.format(SELECT_ALREADY_DEFINED_MESSAGE, "at 
[5:3]"));
+    }
+
+    @Test
+    public void shouldRejectSelectDefinedAfterUpdate()
+    {
+        String query = "BEGIN TRANSACTION\n" +
+                       "  LET a = (SELECT * FROM ks.tbl1 WHERE k = 0 AND c = 
0);\n" +
+                       "  LET b = (SELECT * FROM ks.tbl1 WHERE k = 1 AND c = 
0);\n" +
+                       "  IF a.v = 1 THEN\n" +
+                       "    UPDATE ks.tbl1 SET v = a.v WHERE k=1 AND c=2;\n" +
+                       "    SELECT b.value, a.value;\n" +   // <-- SELECT 
defined after UPDATE
+                       "  ELSE IF a.v = 2 THEN\n" +
+                       "    SELECT a.value, b.value;\n" +
+                       "    UPDATE ks.tbl1 SET v = b.v WHERE k=1 AND c=2;\n" +
+                       "  ELSE\n" +
+                       "    SELECT a.value, b.value;\n" +
+                       "  END IF\n" +
+                       "COMMIT TRANSACTION";
+
+        Assertions.assertThatThrownBy(() -> prepare(query))
+                  .isInstanceOf(SyntaxException.class)
+                  .hasMessageContaining("mismatched input 'SELECT' expecting 
K_END");
+    }
+
+    @Test
+    public void shouldRejectMissingSelectInBranch()

Review Comment:
   why is this an error? feels weird for me, would expect empty result set in 
this case rather than an error



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to