diff --git a/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperLogLogCollector.java b/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperLogLogCollector.java index 2ffca7cbcd7..586dc86d3c7 100644 --- a/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperLogLogCollector.java +++ b/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperLogLogCollector.java @@ -575,18 +575,19 @@ public abstract class HyperLogLogCollector implements Comparable> 1); + + final int position = getPayloadBytePosition() + (short) (bucket >> 1); final boolean isUpperNibble = ((bucket & 0x1) == 0); - byte shiftedPositionOf1 = (isUpperNibble) ? (byte) (positionOf1 << bitsPerBucket) : positionOf1; + final byte shiftedPositionOf1 = (isUpperNibble) ? (byte) (positionOf1 << bitsPerBucket) : positionOf1; if (storageBuffer.remaining() != getNumBytesForDenseStorage()) { convertToDenseStorage(); } - byte origVal = storageBuffer.get(getPayloadBytePosition() + position); - byte newValueMask = (isUpperNibble) ? (byte) 0xf0 : (byte) 0x0f; - byte originalValueMask = (byte) (newValueMask ^ 0xff); + final byte origVal = storageBuffer.get(position); + final byte newValueMask = (isUpperNibble) ? (byte) 0xf0 : (byte) 0x0f; + final byte originalValueMask = (byte) (newValueMask ^ 0xff); // if something was at zero, we have to increase the numNonZeroRegisters if ((origVal & newValueMask) == 0 && shiftedPositionOf1 != 0) { @@ -594,7 +595,7 @@ public abstract class HyperLogLogCollector implements Comparable