This is an automated email from the ASF dual-hosted git repository.

aweisberg pushed a commit to branch cas-accord-v2
in repository https://gitbox.apache.org/repos/asf/cassandra.git

commit bc96d9565c22f94751b7c0c2f93c53c5b816c9f4
Author: Caleb Rackliffe <calebrackli...@gmail.com>
AuthorDate: Tue Dec 6 12:20:09 2022 -0600

    fixes from David's feedback branch
---
 .../cql3/statements/TransactionStatement.java      |  2 ++
 .../cassandra/serializers/ListSerializer.java      | 12 ++++-----
 .../cql3/statements/TransactionStatementTest.java  | 22 ++++++++--------
 .../cassandra/service/accord/txn/TxnBuilder.java   | 30 ++++++++++++----------
 4 files changed, 36 insertions(+), 30 deletions(-)

diff --git 
a/src/java/org/apache/cassandra/cql3/statements/TransactionStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/TransactionStatement.java
index 19ead226ba..c78f116a53 100644
--- a/src/java/org/apache/cassandra/cql3/statements/TransactionStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/TransactionStatement.java
@@ -353,6 +353,8 @@ public class TransactionStatement implements CQLStatement
         public void setKeyspace(ClientState state)
         {
             assignments.forEach(select -> select.setKeyspace(state));
+            if (select != null)
+                select.setKeyspace(state);
             updates.forEach(update -> update.setKeyspace(state));
         }
 
diff --git a/src/java/org/apache/cassandra/serializers/ListSerializer.java 
b/src/java/org/apache/cassandra/serializers/ListSerializer.java
index c024cb6f35..c8b859e655 100644
--- a/src/java/org/apache/cassandra/serializers/ListSerializer.java
+++ b/src/java/org/apache/cassandra/serializers/ListSerializer.java
@@ -230,20 +230,20 @@ public class ListSerializer<T> extends 
CollectionSerializer<List<T>>
     {
         try
         {
-            int n = readCollectionSize(collection, 
ByteBufferAccessor.instance, ProtocolVersion.V3);
-            int offset = sizeOfCollectionSize(n, ProtocolVersion.V3);
+            ProtocolVersion version = ProtocolVersion.V3;
+            int n = readCollectionSize(collection, 
ByteBufferAccessor.instance, version);
+            int offset = sizeOfCollectionSize(n, version);
             int idx = ByteBufferUtil.toInt(index);
 
             Preconditions.checkElementIndex(idx, n);
 
             for (int i = 0; i <= idx; i++)
             {
-                ByteBuffer value = readValue(collection, 
ByteBufferAccessor.instance, offset, ProtocolVersion.V3);
-                offset += sizeOfValue(value, ByteBufferAccessor.instance, 
ProtocolVersion.V3);
                 if (i == idx)
-                    return value;
+                    return readValue(collection, ByteBufferAccessor.instance, 
offset, version);
+                offset += skipValue(collection, ByteBufferAccessor.instance, 
offset, version);
             }
-            return null;
+            throw new AssertionError("Asked to read index " + idx + " but 
never read the index");
         }
         catch (BufferUnderflowException | IndexOutOfBoundsException e)
         {
diff --git 
a/test/unit/org/apache/cassandra/cql3/statements/TransactionStatementTest.java 
b/test/unit/org/apache/cassandra/cql3/statements/TransactionStatementTest.java
index 45e11a8fcf..492e3e67a2 100644
--- 
a/test/unit/org/apache/cassandra/cql3/statements/TransactionStatementTest.java
+++ 
b/test/unit/org/apache/cassandra/cql3/statements/TransactionStatementTest.java
@@ -378,8 +378,8 @@ public class TransactionStatementTest
                                  .withRead(TxnDataName.returning(), "SELECT v 
FROM ks.tbl1 WHERE k=2 AND c=2")
                                  .withWrite("UPDATE ks.tbl1 SET v=1 WHERE k=1 
AND c=2")
                                  .withIsNotNullCondition(user("row1"), null)
-                                 .withEqualsCondition("row1", "ks.tbl1.v", 
bytes(3))
-                                 .withEqualsCondition("row2", "ks.tbl2.v", 
bytes(4))
+                                 .withEqualsCondition("row1", "v", bytes(3))
+                                 .withEqualsCondition("row2", "v", bytes(4))
                                  .build();
 
         TransactionStatement.Parsed parsed = (TransactionStatement.Parsed) 
QueryProcessor.parseStatement(query);
@@ -407,8 +407,8 @@ public class TransactionStatementTest
                                  .withRead("row2", "SELECT * FROM ks.tbl2 
WHERE k=2 AND c=2")
                                  .withWrite("UPDATE ks.tbl1 SET v=1 WHERE k=1 
AND c=2")
                                  .withIsNotNullCondition(user("row1"), null)
-                                 .withEqualsCondition("row1", "ks.tbl1.v", 
bytes(3))
-                                 .withEqualsCondition("row2", "ks.tbl2.v", 
bytes(4))
+                                 .withEqualsCondition("row1", "v", bytes(3))
+                                 .withEqualsCondition("row2", "v", bytes(4))
                                  .build();
 
         TransactionStatement.Parsed parsed = (TransactionStatement.Parsed) 
QueryProcessor.parseStatement(query);
@@ -433,7 +433,7 @@ public class TransactionStatementTest
         Txn expected = TxnBuilder.builder()
                                  .withRead("row1", "SELECT * FROM ks.tbl3 
WHERE k=1")
                                  .withWrite("INSERT INTO ks.tbl3 (k, \"with 
spaces\") VALUES (1, 2)")
-                                 .withIsNullCondition(user("row1"), 
"ks.tbl3.with spaces")
+                                 .withIsNullCondition(user("row1"), "with 
spaces")
                                  .build();
 
         TransactionStatement.Parsed parsed = (TransactionStatement.Parsed) 
QueryProcessor.parseStatement(query);
@@ -467,8 +467,8 @@ public class TransactionStatementTest
                                  .withRead("row2", "SELECT * FROM ks.tbl2 
WHERE k=2 AND c=2")
                                  .withRead(TxnDataName.returning(), "SELECT v 
FROM ks.tbl1 WHERE k=1 AND c=2")
                                  .withWrite(emptyUpdate(TABLE1, 1, 2, false), 
referenceOps)
-                                 .withEqualsCondition("row1", "ks.tbl1.v", 
bytes(3))
-                                 .withEqualsCondition("row2", "ks.tbl2.v", 
bytes(4))
+                                 .withEqualsCondition("row1", "v", bytes(3))
+                                 .withEqualsCondition("row2", "v", bytes(4))
                                  .build();
 
         TransactionStatement.Parsed parsed = (TransactionStatement.Parsed) 
QueryProcessor.parseStatement(query);
@@ -497,8 +497,8 @@ public class TransactionStatementTest
                                  .withRead("row2", "SELECT * FROM ks.tbl2 
WHERE k=2 AND c=2")
                                  .withRead(TxnDataName.returning(), "SELECT v 
FROM ks.tbl1 WHERE k=1 AND c=2")
                                  .withWrite(emptyUpdate(TABLE1, 1, 2, true), 
referenceOps)
-                                 .withEqualsCondition("row1", "ks.tbl1.v", 
bytes(3))
-                                 .withEqualsCondition("row2", "ks.tbl2.v", 
bytes(4))
+                                 .withEqualsCondition("row1", "v", bytes(3))
+                                 .withEqualsCondition("row2", "v", bytes(4))
                                  .build();
 
         TransactionStatement.Parsed parsed = (TransactionStatement.Parsed) 
QueryProcessor.parseStatement(query);
@@ -531,7 +531,7 @@ public class TransactionStatementTest
                                             TxnReferenceOperations.empty(),
                                             new 
VariableSpecifications(Collections.singletonList(null)),
                                             updatedListBytes)
-                                 .withEqualsCondition("row1", 
"ks.tbl4.int_list", initialListBytes)
+                                 .withEqualsCondition("row1", "int_list", 
initialListBytes)
                                  .build();
 
         TransactionStatement.Parsed parsed = (TransactionStatement.Parsed) 
QueryProcessor.parseStatement(update);
@@ -569,7 +569,7 @@ public class TransactionStatementTest
         Txn expected = TxnBuilder.builder()
                                  .withRead("row1", "SELECT * FROM ks.tbl4 
WHERE k = 0")
                                  .withWrite(emptyUpdate(TABLE4, 1, 
Clustering.EMPTY, false), referenceOps)
-                                 .withEqualsCondition("row1", 
"ks.tbl4.int_list", initialListBytes)
+                                 .withEqualsCondition("row1", "int_list", 
initialListBytes)
                                  .build();
 
         TransactionStatement.Parsed parsed = (TransactionStatement.Parsed) 
QueryProcessor.parseStatement(update);
diff --git a/test/unit/org/apache/cassandra/service/accord/txn/TxnBuilder.java 
b/test/unit/org/apache/cassandra/service/accord/txn/TxnBuilder.java
index 055e649dcf..fe335a03cf 100644
--- a/test/unit/org/apache/cassandra/service/accord/txn/TxnBuilder.java
+++ b/test/unit/org/apache/cassandra/service/accord/txn/TxnBuilder.java
@@ -21,14 +21,15 @@ package org.apache.cassandra.service.accord.txn;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
-import accord.primitives.Keys;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Iterables;
 
 import accord.api.Key;
+import accord.primitives.Keys;
 import accord.primitives.Txn;
 import org.apache.cassandra.cql3.ColumnIdentifier;
 import org.apache.cassandra.cql3.QueryOptions;
@@ -42,6 +43,7 @@ import org.apache.cassandra.db.SinglePartitionReadQuery;
 import org.apache.cassandra.db.partitions.PartitionUpdate;
 import org.apache.cassandra.schema.ColumnMetadata;
 import org.apache.cassandra.schema.Schema;
+import org.apache.cassandra.schema.TableId;
 import org.apache.cassandra.schema.TableMetadata;
 import org.apache.cassandra.service.ClientState;
 import org.apache.cassandra.service.accord.api.PartitionKey;
@@ -102,18 +104,20 @@ public class TxnBuilder
         return withWrite(query, TxnReferenceOperations.empty(), 
VariableSpecifications.empty());
     }
 
-    static TxnReference reference(TxnDataName name, String column)
-    {
-        ColumnMetadata metadata = null;
-        if (column != null)
-        {
-            String[] parts = column.split("\\.");
-            Preconditions.checkArgument(parts.length == 3);
-            TableMetadata table = Schema.instance.getTableMetadata(parts[0], 
parts[1]);
-            Preconditions.checkArgument(table != null);
-            metadata = table.getColumn(new ColumnIdentifier(parts[2], true));
-            Preconditions.checkArgument(metadata != null);
-        }
+    private TxnReference reference(TxnDataName name, String column)
+    {
+        // do any reads match the name?
+        Optional<TxnNamedRead> match = reads.stream().filter(n -> 
n.name().equals(name)).findFirst();
+        if (!match.isPresent())
+            throw new IllegalArgumentException("Attempted to create a 
reference for " + name + " but no read exists with that name");
+        TxnNamedRead read = match.get();
+        TableId tableID = read.key().tableId();
+        TableMetadata table = Schema.instance.getTableMetadata(tableID);
+        if (table == null)
+                throw new IllegalStateException("No table exists w/ ID " + 
tableID);
+        ColumnMetadata metadata = column == null
+                                  ? null
+                                  : table.getColumn(new 
ColumnIdentifier(column, true)); //TODO support a.b.c for UDT
         return new TxnReference(name, metadata);
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to