This is an automated email from the ASF dual-hosted git repository.

Jackie-Jiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new f29b359b846 Fix SmartHLL ClassCastException in GROUP BY ORDER BY 
(#18841)
f29b359b846 is described below

commit f29b359b8464b8d8f54aefa92e9fec37544f94e7
Author: ilamhs <[email protected]>
AuthorDate: Wed Jul 8 17:00:36 2026 -0700

    Fix SmartHLL ClassCastException in GROUP BY ORDER BY (#18841)
---
 ...istinctCountSmartSketchAggregationFunction.java |  4 ++--
 ...stinctCountSmartHLLAggregationFunctionTest.java | 26 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/BaseDistinctCountSmartSketchAggregationFunction.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/BaseDistinctCountSmartSketchAggregationFunction.java
index 52a7351fd35..7147e074a24 100644
--- 
a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/BaseDistinctCountSmartSketchAggregationFunction.java
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/BaseDistinctCountSmartSketchAggregationFunction.java
@@ -508,7 +508,7 @@ abstract class 
BaseDistinctCountSmartSketchAggregationFunction
   }
 
   @Override
-  public final Set extractGroupByResult(GroupByResultHolder 
groupByResultHolder, int groupKey) {
+  public final Object extractGroupByResult(GroupByResultHolder 
groupByResultHolder, int groupKey) {
     Object result = groupByResultHolder.getResult(groupKey);
     if (result == null) {
       return EMPTY_PLACEHOLDER;
@@ -517,7 +517,7 @@ abstract class 
BaseDistinctCountSmartSketchAggregationFunction
     if (result instanceof DictIdsWrapper) {
       return convertToValueSet((DictIdsWrapper) result);
     } else {
-      return (Set) result;
+      return result;
     }
   }
 
diff --git 
a/pinot-core/src/test/java/org/apache/pinot/core/query/aggregation/function/DistinctCountSmartHLLAggregationFunctionTest.java
 
b/pinot-core/src/test/java/org/apache/pinot/core/query/aggregation/function/DistinctCountSmartHLLAggregationFunctionTest.java
index 1516b1f947b..083cfe6eb28 100644
--- 
a/pinot-core/src/test/java/org/apache/pinot/core/query/aggregation/function/DistinctCountSmartHLLAggregationFunctionTest.java
+++ 
b/pinot-core/src/test/java/org/apache/pinot/core/query/aggregation/function/DistinctCountSmartHLLAggregationFunctionTest.java
@@ -20,12 +20,15 @@ package org.apache.pinot.core.query.aggregation.function;
 
 import com.clearspring.analytics.stream.cardinality.HyperLogLog;
 import java.util.List;
+import java.util.Set;
 import org.apache.pinot.common.request.context.ExpressionContext;
 import org.apache.pinot.common.utils.DataSchema;
+import 
org.apache.pinot.core.query.aggregation.groupby.ObjectGroupByResultHolder;
 import org.apache.pinot.spi.data.FieldSpec;
 import org.testng.annotations.Test;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 
@@ -151,6 +154,29 @@ public class DistinctCountSmartHLLAggregationFunctionTest {
     assertTrue(mergedCardinality >= 700 && mergedCardinality <= 800, "Merged 
cardinality: " + mergedCardinality);
   }
 
+  @Test
+  public void itExtractsHLLFromGroupByResultHolderWhenSketchConverted() {
+    DistinctCountSmartHLLAggregationFunction function = new 
DistinctCountSmartHLLAggregationFunction(
+        List.of(ExpressionContext.forIdentifier("col"),
+            ExpressionContext.forLiteral(FieldSpec.DataType.STRING, 
"threshold=5;dictThreshold=5")));
+
+    ObjectGroupByResultHolder holder = new ObjectGroupByResultHolder(10, 10);
+
+    HyperLogLog hll = new HyperLogLog(12);
+    for (int i = 0; i < 100; i++) {
+      hll.offer(i);
+    }
+    holder.setValueForKey(0, hll);
+
+    Object extracted = function.extractGroupByResult(holder, 0);
+    assertTrue(extracted instanceof HyperLogLog,
+        "Expected HyperLogLog but got: " + (extracted == null ? "null" : 
extracted.getClass().getName()));
+    assertFalse(extracted instanceof Set, "HyperLogLog must not be cast to 
Set");
+
+    int cardinality = function.extractFinalResult(extracted);
+    assertTrue(cardinality >= 90 && cardinality <= 110, "Cardinality out of 
range: " + cardinality);
+  }
+
   @Test
   public void testAdaptiveConversion() {
     // Test adaptive conversion enabled by default (100K threshold)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to