Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into issue/opensearch…
Browse files Browse the repository at this point in the history
…-project#100

Signed-off-by: chloe-zh <[email protected]>

# Conflicts:
#	opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilder.java
  • Loading branch information
chloe-zh committed Jun 9, 2021
1 parent 43dad8d commit 866d71d
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ public Pair<AggregationBuilder, MetricParser> visitNamedAggregator(
if (distinct) {
switch (node.getFunctionName().getFunctionName()) {
case "count":
return make(AggregationBuilders.cardinality(name), expression);
return make(
AggregationBuilders.cardinality(name),
expression,
new SingleValueParser(name));
default:
throw new ExpressionEvaluationException(String.format(
"unsupported distinct aggregator %s", node.getFunctionName().getFunctionName()));
Expand Down Expand Up @@ -171,6 +174,12 @@ private AggregationBuilder make(CardinalityAggregationBuilder builder, Expressio
return cardinalityHelper.build(expression, builder::field, builder::script);
}

private Pair<AggregationBuilder, MetricParser> make(CardinalityAggregationBuilder builder,
Expression expression,
MetricParser parser) {
return Pair.of(cardinalityHelper.build(expression, builder::field, builder::script), parser);
}

/**
* Replace star or literal with OpenSearch metadata field "_index". Because: 1) Analyzer already
* converts * to string literal, literal check here can handle both COUNT(*) and COUNT(1). 2)
Expand Down

0 comments on commit 866d71d

Please sign in to comment.