Skip to content

Commit f0bea80

Browse files
fix: restore DISTINCT operator (#129)
* restore DISTINCT operator * address review comments
1 parent a729727 commit f0bea80

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

document-store/src/main/java/org/hypertrace/core/documentstore/expression/operators/AggregationOperator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
public enum AggregationOperator {
44
AVG,
55
COUNT,
6+
/** @deprecated Use {@link AggregationOperator#DISTINCT_ARRAY} instead. */
7+
@Deprecated(forRemoval = true)
8+
DISTINCT,
69
DISTINCT_ARRAY, // This operator generates an array of distinct values
710
DISTINCT_COUNT,
811
SUM,

document-store/src/main/java/org/hypertrace/core/documentstore/mongo/parser/MongoAggregateExpressionParser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static java.util.Collections.unmodifiableMap;
44
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.AVG;
55
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.COUNT;
6+
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.DISTINCT;
67
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.DISTINCT_ARRAY;
78
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.MAX;
89
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.MIN;
@@ -23,6 +24,7 @@ final class MongoAggregateExpressionParser extends MongoSelectTypeExpressionPars
2324
new EnumMap<>(AggregationOperator.class) {
2425
{
2526
put(AVG, "$avg");
27+
put(DISTINCT, "$addToSet");
2628
put(DISTINCT_ARRAY, "$addToSet");
2729
put(SUM, "$sum");
2830
put(MIN, "$min");

document-store/src/main/java/org/hypertrace/core/documentstore/postgres/query/v1/vistors/PostgresAggregateExpressionVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public String visit(final AggregateExpression expression) {
5959
private String convertToAggregationFunction(AggregationOperator operator, String value) {
6060
if (operator.equals(AggregationOperator.DISTINCT_COUNT)) {
6161
return String.format("COUNT(DISTINCT %s )", value);
62+
} else if (operator.equals(AggregationOperator.DISTINCT)) {
63+
return String.format("ARRAY_AGG(DISTINCT %s)", value);
6264
} else if (operator.equals(AggregationOperator.DISTINCT_ARRAY)) {
6365
return String.format("ARRAY_AGG(DISTINCT %s)", value);
6466
}

0 commit comments

Comments
 (0)