Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -508,16 +508,16 @@ public final Object extractAggregationResult(AggregationResultHolder aggregation
}

@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;
}

if (result instanceof DictIdsWrapper) {
return convertToValueSet((DictIdsWrapper) result);
if (result instanceof DictIdsWrapper dictIdsWrapper) {
return convertToValueSet(dictIdsWrapper);
} else {
return (Set) result;
return result;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@

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;

Expand Down Expand Up @@ -151,6 +154,29 @@ public void testHLLOperations() {
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)
Expand Down
Loading