AmatyaAvadhanula commented on code in PR #16389:
URL: https://github.com/apache/druid/pull/16389#discussion_r1589853274


##########
processing/src/test/java/org/apache/druid/collections/spatial/ImmutableRTreeTest.java:
##########
@@ -702,4 +703,37 @@ public void testPreciseRadiusBoundFilter()
     ImmutableBitmap finalSet = bf.union(points);
     Assert.assertTrue(finalSet.size() == 100);
   }
+
+  @Test
+  public void testForImmutableRTreeImmutability()
+  {
+    BitmapFactory bf = new RoaringBitmapFactory();
+    RTree tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bf), bf);
+    float centerLat = 37.4133961f;
+    float centerLong = -122.1224665f;
+    float[][] insidePoints = 
SpatialUtils.generateGeoCoordinatesAroundCircle(centerLat, centerLong, 100, 
100, true);
+    for (int i = 0; i < insidePoints.length; i++) {
+      tree.insert(insidePoints[i], i);
+    }
+    float[][] outsidePoints = 
SpatialUtils.generateGeoCoordinatesAroundCircle(centerLat, centerLong, 100, 
100, false);
+    for (int i = 0; i < outsidePoints.length; i++) {
+      tree.insert(outsidePoints[i], i);
+    }
+    final ImmutableRTree searchTree = 
ImmutableRTree.newImmutableFromMutable(tree);
+    ByteBuffer buffer = ByteBuffer.wrap(searchTree.toBytes());
+    ImmutableRTreeObjectStrategy objectStrategy = new 
ImmutableRTreeObjectStrategy(bf);
+    ImmutableRTree builtTree = objectStrategy.fromByteBuffer(buffer, 
searchTree.toBytes().length);
+    buffer.position(10);

Review Comment:
   Should this be called before calling the `fromByteBuffer` method?



##########
processing/src/main/java/org/apache/druid/segment/data/ImmutableRTreeObjectStrategy.java:
##########
@@ -63,8 +63,9 @@ public Class<ImmutableRTree> getClazz()
   @Override
   public ImmutableRTree fromByteBuffer(ByteBuffer buffer, int numBytes)
   {
-    buffer.limit(buffer.position() + numBytes);
-    return new ImmutableRTree(buffer, bitmapFactory);
+    ByteBuffer duplicateBuf = buffer.duplicate();

Review Comment:
   Please add a comment explaining the need for a duplicate buffer for future 
reference.



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