atris commented on a change in pull request #7916:
URL: https://github.com/apache/pinot/pull/7916#discussion_r795404103
##########
File path:
pinot-core/src/main/java/org/apache/pinot/core/query/request/context/QueryContext.java
##########
@@ -441,76 +460,105 @@ public QueryContext build() {
*/
private void generateAggregationFunctions(QueryContext queryContext) {
List<AggregationFunction> aggregationFunctions = new ArrayList<>();
- List<Pair<AggregationFunction, FilterContext>>
filteredAggregationFunctions = new ArrayList<>();
+ List<Pair<AggregationFunction, FilterContext>> filteredAggregations =
new ArrayList<>();
Map<FunctionContext, Integer> aggregationFunctionIndexMap = new
HashMap<>();
+ Map<Pair<FunctionContext, FilterContext>, Integer>
filterExpressionIndexMap = new HashMap<>();
// Add aggregation functions in the SELECT clause
// NOTE: DO NOT deduplicate the aggregation functions in the SELECT
clause because that involves protocol change.
- List<FunctionContext> aggregationsInSelect = new ArrayList<>();
- List<Pair<FunctionContext, FilterContext>> filteredAggregations = new
ArrayList<>();
+ List<Pair<FilterContext, FunctionContext>> aggregationsInSelect = new
ArrayList<>();
for (ExpressionContext selectExpression :
queryContext._selectExpressions) {
- getAggregations(selectExpression, aggregationsInSelect,
filteredAggregations);
+ getAggregations(selectExpression, aggregationsInSelect);
}
- for (FunctionContext function : aggregationsInSelect) {
- int functionIndex = aggregationFunctions.size();
+ for (Pair<FilterContext, FunctionContext> pair : aggregationsInSelect) {
+ FunctionContext function = pair.getRight();
+ int functionIndex = filteredAggregations.size();
AggregationFunction aggregationFunction =
AggregationFunctionFactory.getAggregationFunction(function,
queryContext);
- aggregationFunctions.add(aggregationFunction);
+
+ FilterContext filterContext = null;
+ // If the left pair is not null, implies a filtered aggregation
+ if (pair.getLeft() != null) {
+ if (_groupByExpressions != null) {
+ throw new IllegalStateException("GROUP BY with FILTER clauses is
not supported");
+ }
+
+ queryContext._hasFilteredAggregations = true;
+
+ filterContext = pair.getLeft();
+
+ Pair<FunctionContext, FilterContext> filterContextPair =
+ Pair.of(function, filterContext);
+
+ if (!filterExpressionIndexMap.containsKey(filterContextPair)) {
+ int filterMapIndex = filterExpressionIndexMap.size();
+
+ filterExpressionIndexMap.put(filterContextPair, filterMapIndex);
+ }
+ }
+ filteredAggregations.add(Pair.of(aggregationFunction, filterContext));
+
Review comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]