Source:
public static List<AggregationColumnNode> computeAggregationNodes(AggregationNode aggregationNode) { int groupByKeyIndex = 0; ImmutableList.Builder<AggregationColumnNode> nodeBuilder = ImmutableList.builder(); for (VariableReferenceExpression outputColumn : aggregationNode.getOutputVariables()) { AggregationNode.Aggregation agg = aggregationNode.getAggregations().get(outputColumn); if (agg != null) { if (agg.getFilter().isPresent() || agg.isDistinct() || agg.getOrderBy().isPresent()) { throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "Unsupported aggregation node " + aggregationNode); } if (agg.getMask().isPresent()) { if (agg.getCall().getDisplayName().equalsIgnoreCase(COUNT_FUNCTION_NAME) && agg.getMask().get().getName().equalsIgnoreCase(agg.getArguments().get(0) + DISTINCT_MASK)) { nodeBuilder.add(new AggregationFunctionColumnNode(outputColumn, new CallExpression(DISTINCT_COUNT_FUNCTION_NAME, agg.getCall().getFunctionHandle(), agg.getCall().getType(), agg.getCall().getArguments()))); continue; } throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "Unsupported aggregation node " + aggregationNode); } if (handlePushDownSingleDistinctCount(nodeBuilder, aggregationNode, outputColumn, agg)) { continue; } nodeBuilder.add(new AggregationFunctionColumnNode(outputColumn, agg.getCall())); } else { VariableReferenceExpression inputColumn = aggregationNode.getGroupingKeys().get(groupByKeyIndex); nodeBuilder.add(new GroupByColumnNode(inputColumn, outputColumn)); groupByKeyIndex++; } } return nodeBuilder.build(); }

Target:
public static List<AggregationColumnNode> computeAggregationNodes(AggregationNode aggregationNode) { int groupByKeyIndex = 0; ImmutableList.Builder<AggregationColumnNode> nodeBuilder = ImmutableList.builder(); for (VariableReferenceExpression outputColumn : aggregationNode.getOutputVariables()) { AggregationNode.Aggregation aggregation = aggregationNode.getAggregations().get(outputColumn); if (aggregation != null) { if (aggregation.getFilter().isPresent() || aggregation.isDistinct() || aggregation.getOrderBy().isPresent()) { throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "Unsupported aggregation node " + aggregationNode); } if (aggregation.getMask().isPresent()) { if (aggregation.getCall().getDisplayName().equalsIgnoreCase(COUNT_FUNCTION_NAME) && aggregation.getMask().get().getName().equalsIgnoreCase(aggregation.getArguments().get(0) + DISTINCT_MASK)) { nodeBuilder.add(new AggregationFunctionColumnNode(outputColumn, new CallExpression(PINOT_DISTINCT_COUNT_FUNCTION_NAME, aggregation.getCall().getFunctionHandle(), aggregation.getCall().getType(), aggregation.getCall().getArguments()))); continue; } throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "Unsupported aggregation node with mask " + aggregationNode); } if (handlePushDownSingleDistinctCount(nodeBuilder, aggregationNode, outputColumn, aggregation)) { continue; } nodeBuilder.add(new AggregationFunctionColumnNode(outputColumn, aggregation.getCall())); } else { VariableReferenceExpression inputColumn = aggregationNode.getGroupingKeys().get(groupByKeyIndex); nodeBuilder.add(new GroupByColumnNode(inputColumn, outputColumn)); groupByKeyIndex++; } } return nodeBuilder.build(); }