diff --git a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountRawThetaSketchAggregationFunction.java b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountRawThetaSketchAggregationFunction.java index b809193b80d..e25b8e0ddbb 100644 --- a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountRawThetaSketchAggregationFunction.java +++ b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountRawThetaSketchAggregationFunction.java @@ -53,7 +53,8 @@ public String extractFinalResult(List accumulators) { int numAccumulators = accumulators.size(); List mergedSketches = new ArrayList<>(numAccumulators); - for (ThetaSketchAccumulator accumulator : accumulators) { + for (Object object : accumulators) { + ThetaSketchAccumulator accumulator = convertSketchAccumulator(object); accumulator.setThreshold(_accumulatorThreshold); accumulator.setSetOperationBuilder(_setOperationBuilder); mergedSketches.add(accumulator.getResult()); diff --git a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountThetaSketchAggregationFunction.java b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountThetaSketchAggregationFunction.java index 83709857f99..7c7234d4dad 100644 --- a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountThetaSketchAggregationFunction.java +++ b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountThetaSketchAggregationFunction.java @@ -947,12 +947,9 @@ public List extractAggregationResult(AggregationResultHo } if (result.get(0) instanceof Sketch) { - int numSketches = result.size(); - ArrayList thetaSketchAccumulators = new ArrayList<>(numSketches); + ArrayList thetaSketchAccumulators = new ArrayList<>(result.size()); for (Object o : result) { - ThetaSketchAccumulator thetaSketchAccumulator = - new ThetaSketchAccumulator(_setOperationBuilder, _accumulatorThreshold); - thetaSketchAccumulator.apply((Sketch) o); + ThetaSketchAccumulator thetaSketchAccumulator = convertSketchAccumulator(o); thetaSketchAccumulators.add(thetaSketchAccumulator); } return thetaSketchAccumulators; @@ -974,12 +971,9 @@ public List extractGroupByResult(GroupByResultHolder gro } if (result.get(0) instanceof Sketch) { - int numSketches = result.size(); - ArrayList thetaSketchAccumulators = new ArrayList<>(numSketches); + ArrayList thetaSketchAccumulators = new ArrayList<>(result.size()); for (Object o : result) { - ThetaSketchAccumulator thetaSketchAccumulator = - new ThetaSketchAccumulator(_setOperationBuilder, _accumulatorThreshold); - thetaSketchAccumulator.apply((Sketch) o); + ThetaSketchAccumulator thetaSketchAccumulator = convertSketchAccumulator(o); thetaSketchAccumulators.add(thetaSketchAccumulator); } return thetaSketchAccumulators; @@ -1024,7 +1018,8 @@ public Comparable extractFinalResult(List accumulators) int numAccumulators = accumulators.size(); List mergedSketches = new ArrayList<>(numAccumulators); - for (ThetaSketchAccumulator accumulator : accumulators) { + for (Object accumulatorObject : accumulators) { + ThetaSketchAccumulator accumulator = convertSketchAccumulator(accumulatorObject); accumulator.setThreshold(_accumulatorThreshold); accumulator.setSetOperationBuilder(_setOperationBuilder); mergedSketches.add(accumulator.getResult()); @@ -1037,14 +1032,14 @@ public Comparable extractFinalResult(List accumulators) // The AggregationDataTableReducer casts intermediate results to Objects and although the code compiles, // types might still be incompatible at runtime due to type erasure. // Due to performance overheads of redundant casts, this should be removed at some future point. - private ThetaSketchAccumulator convertSketchAccumulator(Object mergeResult) { - if (mergeResult instanceof Sketch) { - Sketch sketch = (Sketch) mergeResult; + protected ThetaSketchAccumulator convertSketchAccumulator(Object result) { + if (result instanceof Sketch) { + Sketch sketch = (Sketch) result; ThetaSketchAccumulator accumulator = new ThetaSketchAccumulator(_setOperationBuilder, _accumulatorThreshold); accumulator.apply(sketch); return accumulator; } - return (ThetaSketchAccumulator) mergeResult; + return (ThetaSketchAccumulator) result; } /**