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


##########
src/java/org/apache/cassandra/index/sai/utils/IndexTermType.java:
##########
@@ -453,10 +459,80 @@ public Iterator<ByteBuffer> valuesOf(Row row, long 
nowInSecs)
         }
     }
 
+    public Iterator<ByteBuffer> valuesOfFrozenCollection(Row row, long 
nowInSecs)
+    {
+        if (row == null)
+            return null;
+
+        ByteBuffer buffer;
+
+        if (columnMetadata.kind == ColumnMetadata.Kind.CLUSTERING)
+             buffer = row.clustering().bufferAt(columnMetadata.position());
+        else
+        {
+            Cell<?> cell = row.getCell(columnMetadata);
+            if (cell == null || !cell.isLive(nowInSecs))
+                return null;
+            buffer = cell.buffer();
+        }
+
+        if (buffer == null || buffer.remaining() == 0)
+            return null;
+
+        CollectionType<?> collectionType = (CollectionType<?>) 
columnMetadata.type.unwrap();
+        CollectionSerializer<?> serializer = collectionType.getSerializer();
+        List<ByteBuffer> elements = serializer.unpack(buffer);
+
+        switch (collectionType.kind)
+        {
+            case LIST:
+            case SET:
+                break;
+            case MAP:
+                elements = extractMapElements(elements);
+                break;
+            default:
+                throw new IllegalArgumentException("Unsupported type of 
collection - " + collectionType.kind);
+        }
+
+        if (isInetAddress())
+            elements.sort((c1, c2) -> compareInet(encodeInetAddress(c1), 
encodeInetAddress(c2)));
+
+        return elements.iterator();
+    }
+
+    private List<ByteBuffer> extractMapElements(List<ByteBuffer> elements)
+    {
+        List<ByteBuffer> result = new ArrayList<>();

Review Comment:
   ```suggestion
           List<ByteBuffer> result = new ArrayList<>(elements.size());
   ```



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