diff --git a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountHLLPlusAggregationFunction.java b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountHLLPlusAggregationFunction.java index 52f3b18db20..2ca7d4eec3e 100644 --- a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountHLLPlusAggregationFunction.java +++ b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountHLLPlusAggregationFunction.java @@ -96,16 +96,14 @@ public void aggregate(int length, AggregationResultHolder aggregationResultHolde byte[][] bytesValues = blockValSet.getBytesValuesSV(); try { HyperLogLogPlus hyperLogLogPlus = aggregationResultHolder.getResult(); - if (hyperLogLogPlus != null) { - for (int i = 0; i < length; i++) { - hyperLogLogPlus.addAll(ObjectSerDeUtils.HYPER_LOG_LOG_PLUS_SER_DE.deserialize(bytesValues[i])); - } - } else { + if (hyperLogLogPlus == null) { hyperLogLogPlus = ObjectSerDeUtils.HYPER_LOG_LOG_PLUS_SER_DE.deserialize(bytesValues[0]); aggregationResultHolder.setValue(hyperLogLogPlus); - for (int i = 1; i < length; i++) { - hyperLogLogPlus.addAll(ObjectSerDeUtils.HYPER_LOG_LOG_PLUS_SER_DE.deserialize(bytesValues[i])); - } + } else { + hyperLogLogPlus.addAll(ObjectSerDeUtils.HYPER_LOG_LOG_PLUS_SER_DE.deserialize(bytesValues[0])); + } + for (int i = 1; i < length; i++) { + hyperLogLogPlus.addAll(ObjectSerDeUtils.HYPER_LOG_LOG_PLUS_SER_DE.deserialize(bytesValues[i])); } } catch (Exception e) { throw new RuntimeException("Caught exception while merging HyperLogLogPlus", e);