You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/01/05 00:53:15 UTC

[GitHub] [druid] suneet-s commented on a change in pull request #10685: Subtotal queries give incorrect results if query has a limit spec

suneet-s commented on a change in pull request #10685:
URL: https://github.com/apache/druid/pull/10685#discussion_r551655397



##########
File path: processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/ByteBufferMinMaxOffsetHeap.java
##########
@@ -59,6 +60,35 @@ public ByteBufferMinMaxOffsetHeap(
     this.heapIndexUpdater = heapIndexUpdater;
   }
 
+  public ByteBufferMinMaxOffsetHeap copy()
+  {
+    LimitedBufferHashGrouper.BufferGrouperOffsetHeapIndexUpdater updater =
+        Optional
+            .ofNullable(heapIndexUpdater)
+            .map(LimitedBufferHashGrouper.BufferGrouperOffsetHeapIndexUpdater::copy)
+            .orElse(null);
+
+    // deep copy buf
+    ByteBuffer buffer = ByteBuffer.allocateDirect(buf.capacity());
+
+    int bufPosition = buf.position();
+    int bufLimit = buf.limit();
+    buf.rewind();
+
+    buffer.put(buf);
+    buffer.position(bufPosition);
+    buffer.limit(bufLimit);
+
+    buf.position(bufPosition);
+    buf.limit(bufLimit);

Review comment:
       nit: It seems like this should be moved in to a separate function since it's used in 2 places. I tried a little googling, and didn't find any libraries that implement deep copying of ByteBuffers which I thought was surprising.
   
   Looking at an implementation I found in http://www.java2s.com/example/java/java.nio/performs-a-deep-copy-on-a-byte-buffer.html, it looks like this implementation does not copy the order of the original ByteBuffer. I can't tell if this is important or not. What do you think?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org