yifan-c commented on code in PR #1739:
URL: https://github.com/apache/cassandra/pull/1739#discussion_r931262491


##########
src/java/org/apache/cassandra/serializers/MapSerializer.java:
##########
@@ -243,6 +247,96 @@ public ByteBuffer getSliceFromSerialized(ByteBuffer 
collection,
         }
     }
 
+    @Override
+    public int getIndexFromSerialized(ByteBuffer collection, ByteBuffer key, 
AbstractType<?> comparator)
+    {
+        try
+        {
+            ByteBuffer input = collection.duplicate();
+            int n = readCollectionSize(input, ByteBufferAccessor.instance, 
ProtocolVersion.V3);
+            int offset = sizeOfCollectionSize(n, ProtocolVersion.V3);
+            for (int i = 0; i < n; i++)
+            {
+                ByteBuffer kbb = readValue(input, ByteBufferAccessor.instance, 
offset, ProtocolVersion.V3);
+                offset += sizeOfValue(kbb, ByteBufferAccessor.instance, 
ProtocolVersion.V3);
+                int comparison = comparator.compareForCQL(kbb, key);
+
+                if (comparison == 0)
+                    return i;
+
+                if (comparison > 0)
+                    // since the map is in sorted order, we know we've gone 
too far and the element doesn't exist
+                    return -1;
+
+                // comparison < 0
+                offset += skipValue(input, ByteBufferAccessor.instance, 
offset, ProtocolVersion.V3);
+            }
+            return -1;
+        }
+        catch (BufferUnderflowException e)
+        {
+            throw new MarshalException("Not enough bytes to read a map");
+        }
+    }
+
+    @Override
+    public Range<Integer> getIndexesRangeFromSerialized(ByteBuffer collection,
+                                                        ByteBuffer from,
+                                                        ByteBuffer to,
+                                                        AbstractType<?> 
comparator)
+    {

Review Comment:
   Make sense! I did not try the slice syntax with `SELECT`. It feels to me 
that a separate ticket is a better fit since it is on the syntax. It can help 
clear out some potential confusions. 



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