maedhroz commented on code in PR #2088:
URL: https://github.com/apache/cassandra/pull/2088#discussion_r1068643364


##########
src/java/org/apache/cassandra/cql3/statements/TransactionStatement.java:
##########
@@ -177,9 +178,16 @@ TxnNamedRead createNamedRead(NamedSelect namedSelect, 
QueryOptions options)
         SinglePartitionReadQuery.Group<SinglePartitionReadCommand> selectQuery 
= (SinglePartitionReadQuery.Group<SinglePartitionReadCommand>) readQuery;
 
         if (selectQuery.queries.size() != 1)
-            throw new IllegalArgumentException("Within a transaction, SELECT 
statements must select a single partition; found " + selectQuery.queries.size() 
+ " partitions");
+        {
+            if (!TxnDataName.returning().equals(namedSelect.name))
+                throw new IllegalArgumentException("Within a transaction, 
SELECT statements must select a single partition; found " + 
selectQuery.queries.size() + " partitions");
+            // multi partitions on the same table are only allowed for the 
returning clause
+            return IntStream.range(0, selectQuery.queries.size())
+                            .mapToObj(i -> new 
TxnNamedRead(TxnDataName.returning(i), selectQuery.queries.get(i)))
+                            .collect(Collectors.toList());

Review Comment:
   This should be a pretty hot path, so I'd have two potential concerns.
   
   1.) I think we'll create less overall garbage w/ something like...
   
   ```
   List<TxnNamedRead> list = new ArrayList<>(selectQuery.queries.size());
   for (int i = 0; i < selectQuery.queries.size(); i++)
       list.add(new TxnNamedRead(TxnDataName.returning(i), 
selectQuery.queries.get(i)));
   ```
   
   2.) Given how many times we'll only have one query, I'd leave 
`createNamedRead()` alone and create a new `createNamedReads()` to house the 
new logic here. No point in creating even a singleton list if we don't have to.



-- 
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