Skip to content

Commit 1382da6

Browse files
committed
enable pushdown distinct count approx
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent c30d5d0 commit 1382da6

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

opensearch/src/main/java/org/opensearch/sql/opensearch/executor/OpenSearchExecutionEngine.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
import org.opensearch.sql.planner.physical.PhysicalPlan;
5656
import org.opensearch.sql.storage.TableScanOperator;
5757

58+
import static org.opensearch.sql.expression.function.BuiltinFunctionName.DISTINCT_COUNT_APPROX;
59+
5860
/** OpenSearch execution engine implementation. */
5961
public class OpenSearchExecutionEngine implements ExecutionEngine {
6062
private static final Logger logger = LogManager.getLogger(OpenSearchExecutionEngine.class);
@@ -282,10 +284,10 @@ private void registerOpenSearchFunctions() {
282284
SqlUserDefinedAggFunction approxDistinctCountFunction =
283285
UserDefinedFunctionUtils.createUserDefinedAggFunction(
284286
DistinctCountApproxAggFunction.class,
285-
"APPROX_DISTINCT_COUNT",
287+
DISTINCT_COUNT_APPROX.toString(),
286288
ReturnTypes.BIGINT_FORCE_NULLABLE,
287289
null);
288290
PPLFuncImpTable.INSTANCE.registerExternalAggOperator(
289-
BuiltinFunctionName.DISTINCT_COUNT_APPROX, approxDistinctCountFunction);
291+
DISTINCT_COUNT_APPROX, approxDistinctCountFunction);
290292
}
291293
}

opensearch/src/main/java/org/opensearch/sql/opensearch/request/AggregateAnalyzer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,11 @@ yield switch (functionName) {
495495
}
496496
yield Pair.of(aggBuilder, new SinglePercentileParser(aggFieldName));
497497
}
498+
case DISTINCT_COUNT_APPROX -> Pair.of(
499+
helper.build(
500+
!args.isEmpty() ? args.getFirst() : null,
501+
AggregationBuilders.cardinality(aggFieldName)),
502+
new SingleValueParser(aggFieldName));
498503
default -> throw new AggregateAnalyzer.AggregateAnalyzerException(
499504
String.format("Unsupported push-down aggregator %s", aggCall.getAggregation()));
500505
};

0 commit comments

Comments
 (0)