924060929 commented on code in PR #10415:
URL: https://github.com/apache/doris/pull/10415#discussion_r910578409


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java:
##########
@@ -50,50 +55,99 @@ public List<Rule<Plan>> buildRules() {
         return ImmutableList.of(
             RuleType.BINDING_PROJECT_SLOT.build(
                 logicalProject().then(project -> {
-                    List<NamedExpression> boundSlots = 
bind(project.operator.getProjects(), project.children());
-                    return plan(new LogicalProject(boundSlots), 
project.child());
+                    List<NamedExpression> boundSlots =
+                            bind(project.operator.getProjects(), 
project.children(), true);
+                    return plan(new LogicalProject(flatBoundStar(boundSlots)), 
project.child());
                 })
             ),
             RuleType.BINDING_FILTER_SLOT.build(
                 logicalFilter().then(filter -> {
-                    Expression boundPredicates = 
bind(filter.operator.getPredicates(), filter.children());
+                    Expression boundPredicates = bind(
+                            filter.operator.getPredicates(), 
filter.children(), false);
                     return plan(new LogicalFilter(boundPredicates), 
filter.child());
                 })
             ),
             RuleType.BINDING_JOIN_SLOT.build(
                 logicalJoin().then(join -> {
-                    Optional<Expression> cond = 
join.operator.getCondition().map(expr -> bind(expr, join.children()));
+                    Optional<Expression> cond = join.operator.getCondition()
+                            .map(expr -> bind(expr, join.children(), false));
                     LogicalJoin op = new 
LogicalJoin(join.operator.getJoinType(), cond);
                     return plan(op, join.left(), join.right());
                 })
+            ),
+            RuleType.BINDING_AGGREGATE_SLOT.build(
+                logicalAggregate().then(agg -> {
+                    List<Expression> groupBy = bind(
+                            agg.operator.getGroupByExprList(), agg.children(), 
false);
+                    List<NamedExpression> output = bind(
+                            agg.operator.getOutputExpressionList(), 
agg.children(), false);
+                    LogicalAggregate op = new LogicalAggregate(groupBy, 
output);
+                    return plan(op, agg.child());
+                })
+            ),
+            RuleType.BINDING_SORT_SLOT.build(
+                logicalSort().then(sort -> {
+                    List<OrderKey> sortItemList = sort.operator.getOrderKeys()
+                            .stream()
+                            .map(orderKey -> {
+                                Expression item = bind(orderKey.getExpr(), 
sort.children(), false);
+                                return new OrderKey(item, orderKey.isAsc(), 
orderKey.isNullFirst());
+                            }).collect(Collectors.toList());
+
+                    LogicalSort op = new LogicalSort(sortItemList);
+                    return plan(op, sort.child());
+                })
             )
         );
     }
 
-    private <E extends Expression> List<E> bind(List<E> exprList, List<Plan> 
inputs) {
+    private List<NamedExpression> flatBoundStar(List<NamedExpression> 
boundSlots) {
+        return boundSlots
+            .stream()
+            .flatMap(slot -> {
+                if (slot instanceof BoundStar) {
+                    return ((BoundStar) slot).getSlots().stream();
+                } else {
+                    return Stream.of(slot);
+                }
+            }).collect(Collectors.toList());
+    }
+
+    private <E extends Expression> List<E> bind(List<E> exprList, List<Plan> 
inputs, boolean isProjection) {

Review Comment:
   I will replace the isProjection to Plan plan, and check `plan instanceof 
LogicalProject` in the visitUnboundStar()



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