adelapena commented on code in PR #1739:
URL: https://github.com/apache/cassandra/pull/1739#discussion_r931206531


##########
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:
   That's the same behaviour that the regular selection of collection items 
has, independently of `writetime` and `ttl`. For example, with and without the 
proposed changes a query like `SELECT s[3..1] FROM t;` passes, and it always 
returns no data.
   
   I'd say that type of intervals is strictly correct given that `[3, 1]` in 
interval notation just means `3 <= x <= 1`, which is useless but correct. 
However, I agree that we should consider throwing an error in that case because 
the user is probably giving those intervals by mistake. 
   
   If we change the behaviour of collection ranges to reject that type of 
bounds, we should do it for all types of selections, not only `writetime` and 
`ttl`. And if we consider it as a bug we should backport the fix. So I think 
I'd keep the current behaviour on this ticket and would open a separate 
followup ticket. wdyt?



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