diff --git a/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperUniquesBufferAggregator.java b/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperUniquesBufferAggregator.java index 143e68dece2..3229e813d6d 100644 --- a/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperUniquesBufferAggregator.java +++ b/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperUniquesBufferAggregator.java @@ -66,9 +66,11 @@ public class HyperUniquesBufferAggregator implements BufferAggregator @Override public Object get(ByteBuffer buf, int position) { - ByteBuffer dataCopyBuffer = ByteBuffer.allocateDirect(HyperLogLogCollector.getLatestNumBytesForDenseStorage()); + final int size = HyperLogLogCollector.getLatestNumBytesForDenseStorage(); + ByteBuffer dataCopyBuffer = ByteBuffer.allocateDirect(size); ByteBuffer mutationBuffer = buf.duplicate(); mutationBuffer.position(position); + mutationBuffer.limit(position + size); dataCopyBuffer.put(mutationBuffer); dataCopyBuffer.rewind(); return HyperLogLogCollector.makeCollector(dataCopyBuffer);