XieJiann commented on code in PR #23499:
URL: https://github.com/apache/doris/pull/23499#discussion_r1307173214


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NormalizeAggregate.java:
##########
@@ -211,11 +194,41 @@ public Rule build() {
                 bottomPlan = aggregate.child();
             }
 
+            List<NamedExpression> upperProjects = 
normalizeOutput(aggregateOutput,
+                    groupByToSlotContext, normalizedAggFuncsToSlotContext);
+
             return new LogicalProject<>(upperProjects,
                     aggregate.withNormalized(normalizedGroupExprs, 
normalizedAggOutput, bottomPlan));
         }).toRule(RuleType.NORMALIZE_AGGREGATE);
     }
 
+    private List<NamedExpression> normalizeOutput(List<NamedExpression> 
aggregateOutput,
+            NormalizeToSlotContext groupByToSlotContext, 
NormalizeToSlotContext normalizedAggFuncsToSlotContext) {
+        // build upper project, use two context to do pop up, because agg 
output maybe contain two part:
+        //   group by keys and agg expressions
+        List<NamedExpression> upperProjects = groupByToSlotContext
+                .normalizeToUseSlotRefWithoutWindowFunction(aggregateOutput);
+        upperProjects = 
normalizedAggFuncsToSlotContext.normalizeToUseSlotRefWithoutWindowFunction(upperProjects);
+
+        Builder<NamedExpression> builder = new ImmutableList.Builder<>();
+        for (int i = 0; i < aggregateOutput.size(); i++) {
+            NamedExpression e = upperProjects.get(i);
+            // process Expression like Alias(SlotReference#0)#0
+            if (e instanceof Alias && e.child(0) instanceof SlotReference) {
+                SlotReference slotReference = (SlotReference) e.child(0);
+                if (slotReference.getExprId().equals(e.getExprId())) {
+                    e = slotReference;
+                }
+            }
+            // Make the output ExprId unchanged
+            if (e.getExprId() != aggregateOutput.get(i).getExprId()) {

Review Comment:
   done



-- 
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]

Reply via email to