morrySnow commented on code in PR #32414:
URL: https://github.com/apache/doris/pull/32414#discussion_r1533424551


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java:
##########
@@ -287,4 +303,11 @@ private List<NamedExpression> 
normalizeOutput(List<NamedExpression> aggregateOut
         }
         return builder.build();
     }
+
+    private List<Slot> collectAllUsedSlots(List<NamedExpression> expressions) {
+        return Stream.concat(
+                ExpressionUtils.collectAll(expressions, 
SubqueryExpr.class::isInstance).stream()

Review Comment:
   ditto



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java:
##########
@@ -244,6 +246,20 @@ private LogicalPlan normalizeAgg(LogicalAggregate<Plan> 
aggregate, Optional<Logi
 
         // create a parent project node
         LogicalProject<Plan> project = new LogicalProject<>(upperProjects, 
newAggregate);
+        // verify project used slots are all coming from agg's output
+        List<Slot> slots = collectAllUsedSlots(upperProjects);
+        if (!slots.isEmpty()) {
+            Set<ExprId> aggOutput = normalizedAggOutput.stream()
+                    .map(NamedExpression::getExprId)
+                    .collect(Collectors.toSet());
+            slots = slots.stream()
+                    .filter(s -> !aggOutput.contains(s.getExprId()))
+                    .collect(Collectors.toList());

Review Comment:
   use for loop for better perfermance



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to