netudima commented on code in PR #4506:
URL: https://github.com/apache/cassandra/pull/4506#discussion_r2617318050


##########
src/java/org/apache/cassandra/cql3/BatchQueryOptions.java:
##########
@@ -91,6 +93,50 @@ public long getNowInSeconds(QueryState state)
         return wrapped.getNowInSeconds(state);
     }
 
+    private static class BatchQueryOptionsWrapper extends 
QueryOptions.QueryOptionsWrapper {
+        private final byte[][] valuesAsByteArray;
+        private List<ByteBuffer> values; // initialized on demand
+
+        BatchQueryOptionsWrapper(QueryOptions wrapped, byte[][] vars)
+        {
+            super(wrapped);
+            this.valuesAsByteArray = vars;
+        }
+        public List<ByteBuffer> getValues()
+        {
+            if (values == null)
+            {
+                values = new ArrayList<>(valuesAsByteArray.length);
+                for (byte[] byteArrayValue : valuesAsByteArray)
+                    values.add(convertToByteBufferValue(byteArrayValue));
+            }
+            return values;
+        }
+
+        public int getValuesSize()
+        {
+            return valuesAsByteArray.length;
+        }
+
+        public ByteBuffer getValue(int index)
+        {
+            if (values == null) // we convert values to ByteBuffer in a lazy 
way, on demand
+                return convertToByteBufferValue(valuesAsByteArray[index]);

Review Comment:
   From correctness point of view it is not a problem. It may introduce an 
extra allocation but in reality do we not do multiple lookups for this logic. 
To implement the lazy store logic for individual elements we will have to 
introduce one more array (we cannot use values for this purpose because we have 
getValues API to support as well), so we have to pay for this logic with an 
extra allocation. Actually, I had something like this in one of my early 
versions of the code but decided that it is an over-complication.



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