You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/06/25 03:39:01 UTC

[GitHub] [doris] 924060929 opened a new pull request, #10415: [feature](nereids) Support analyze for test SSB

924060929 opened a new pull request, #10415:
URL: https://github.com/apache/doris/pull/10415

   # Proposed changes
   
   Issue Number: no issue
   
   ## Problem Summary:
   
   support analyze for test SSB.
   
   add describe later.
   
   ## Checklist(Required)
   
   1. Does it affect the original behavior: (Yes/No/I Don't know)
   2. Has unit tests been added: (Yes/No/No Need)
   3. Has document been added or modified: (Yes/No/No Need)
   4. Does it need to update dependencies: (Yes/No)
   5. Are there any changes that cannot be rolled back: (Yes/No)


-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] 924060929 commented on a diff in pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
924060929 commented on code in PR #10415:
URL: https://github.com/apache/doris/pull/10415#discussion_r910575894


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/TreeNode.java:
##########
@@ -46,4 +48,27 @@
 
     NODE_TYPE withChildren(List<NODE_TYPE> children);
 
+    default void foreach(Consumer<TreeNode<NODE_TYPE>> func) {

Review Comment:
   I think we have a promise: if the traverse function no order info, it must be top-down implicitly



-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] EmmyMiao87 merged pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
EmmyMiao87 merged PR #10415:
URL: https://github.com/apache/doris/pull/10415


-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] yinzhijian commented on a diff in pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
yinzhijian commented on code in PR #10415:
URL: https://github.com/apache/doris/pull/10415#discussion_r910757341


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ExpressionConverter.java:
##########
@@ -44,19 +45,14 @@
  * Used to convert expression of new optimizer to stale expr.
  */
 @SuppressWarnings("rawtypes")
-public class ExpressionConverter extends ExpressionVisitor<Expr, PlanTranslatorContext> {
+public class ExpressionConverter extends DefaultExpressionVisitor<Expr, PlanTranslatorContext> {
 
     public static ExpressionConverter converter = new ExpressionConverter();
 
     public static Expr convert(Expression expression, PlanTranslatorContext planContext) {
         return converter.visit(expression, planContext);

Review Comment:
   ```suggestion
           return expression.accept(converter, planContext);
   ```



-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] morrySnow commented on a diff in pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
morrySnow commented on code in PR #10415:
URL: https://github.com/apache/doris/pull/10415#discussion_r906932104


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundAlias.java:
##########
@@ -34,18 +38,28 @@
         extends NamedExpression
         implements UnaryExpression<CHILD_TYPE>, Unbound {
 
-    public UnboundAlias(CHILD_TYPE child) {
+    private final ExprId exprId;
+    private final String name;
+
+    public UnboundAlias(ExprId exprId, CHILD_TYPE child) {
         super(NodeType.UNBOUND_ALIAS, child);
+        this.exprId = Objects.requireNonNull(exprId, "exprId can not be null");
+        this.name = "expr_" + exprId;
     }
 
     @Override
     public String sql() {
-        return null;
+        return child().sql();

Review Comment:
   i think all unbound should not generate sql



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -143,265 +130,47 @@ public Object visitChildren(RuleNode node) {
 
     @Override
     public LogicalPlan visitSingleStatement(SingleStatementContext ctx) {
-        Supplier<LogicalPlan> f = () -> (LogicalPlan) visit(ctx.statement());
-        return ParserUtils.withOrigin(ctx, f);
+        return ParserUtils.withOrigin(ctx, () -> (LogicalPlan) visit(ctx.statement()));
     }
 
     /* ********************************************************************************************
      * Plan parsing
      * ******************************************************************************************** */
-    private LogicalPlan plan(ParserRuleContext tree) {
-        return (LogicalPlan) tree.accept(this);
-    }
-
     @Override
     public LogicalPlan visitQuery(QueryContext ctx) {
-        Supplier<LogicalPlan> f = () -> {
+        return ParserUtils.withOrigin(ctx, () -> {
             // TODO: need to add withQueryResultClauses and withCTE
             LogicalPlan query = plan(ctx.queryTerm());
-            LogicalPlan queryOrganization = withQueryOrganization(ctx.queryOrganization(), query);
+            LogicalPlan queryOrganization = withOrganization(query, ctx.queryOrganization());
             return queryOrganization;
-        };
-        return ParserUtils.withOrigin(ctx, f);
-    }
-
-    private LogicalPlan withQueryOrganization(QueryOrganizationContext ctx, LogicalPlan children) {
-        List<SortItems> sortItems = visitQueryOrganization(ctx);
-        return sortItems == null ? children : new LogicalUnaryPlan(new LogicalSort(sortItems), children);
+        });
     }
 
     @Override
     public LogicalPlan visitRegularQuerySpecification(RegularQuerySpecificationContext ctx) {
-        Supplier<LogicalPlan> f = () -> {
+        return ParserUtils.withOrigin(ctx, () -> {
             // TODO: support on row relation
-            LogicalPlan from = visitFromClause(ctx.fromClause());
+            LogicalPlan relation = withRelation(Optional.ofNullable(ctx.fromClause()));
             return withSelectQuerySpecification(
-                    ctx,
-                    ctx.selectClause(),
-                    ctx.whereClause(),
-                    from,
-                    ctx.aggClause());
-        };
-        return ParserUtils.withOrigin(ctx, f);
-    }
-
-    @Override
-    public Expression visitExpression(ExpressionContext ctx) {
-        Supplier<Expression> f = () -> (Expression) visit(ctx.booleanExpression());
-        return ParserUtils.withOrigin(ctx, f);
-    }
-
-    @Override
-    public List<Expression> visitNamedExpressionSeq(NamedExpressionSeqContext ctx) {
-        List<Expression> expressions = Lists.newArrayList();
-        if (ctx != null) {
-            for (NamedExpressionContext namedExpressionContext : ctx.namedExpression()) {
-                Expression expression = typedVisit(namedExpressionContext);
-                expressions.add(expression);
-            }
-        }
-        return expressions;
-    }
-
-    /**
-     * Add a regular (SELECT) query specification to a logical plan. The query specification
-     * is the core of the logical plan, this is where sourcing (FROM clause), projection (SELECT),
-     * aggregation (GROUP BY ... HAVING ...) and filtering (WHERE) takes place.
-     *
-     * <p>Note that query hints are ignored (both by the parser and the builder).
-     */
-    private LogicalPlan withSelectQuerySpecification(
-            ParserRuleContext ctx,
-            SelectClauseContext selectClause,
-            WhereClauseContext whereClause,
-            LogicalPlan relation,
-            AggClauseContext aggClause) {
-        Supplier<LogicalPlan> f = () -> {
-            //        Filter(expression(ctx.booleanExpression), plan);
-            LogicalPlan plan = visitCommonSelectQueryClausePlan(
-                    relation,
-                    visitNamedExpressionSeq(selectClause.namedExpressionSeq()),
-                    whereClause,
-                    aggClause);
-            // TODO: process hint
-            return plan;
-        };
-        return ParserUtils.withOrigin(ctx, f);
-    }
-
-    private LogicalPlan visitCommonSelectQueryClausePlan(
-            LogicalPlan relation,
-            List<Expression> expressions,
-            WhereClauseContext whereClause,
-            AggClauseContext aggClause) {
-        // TODO: add lateral views
-        // val withLateralView = lateralView.asScala.foldLeft(relation)(withGenerate)
-
-        // add where
-        LogicalPlan withFilter = relation.optionalMap(whereClause, withWhereClause);
-
-        List<NamedExpression> namedExpressions = expressions.stream().map(expression -> {
-            if (expression instanceof NamedExpression) {
-                return (NamedExpression) expression;
-            } else {
-                return new UnboundAlias(expression);
-            }
-        }).collect(Collectors.toList());
-
-        LogicalPlan withProject;
-        if (CollectionUtils.isNotEmpty(namedExpressions)) {
-            withProject = new LogicalUnaryPlan(new LogicalProject(namedExpressions), withFilter);
-        } else {
-            withProject = withFilter;
-        }
-
-        LogicalPlan withAgg;
-        if (aggClause != null) {
-            withAgg = withAggClause(namedExpressions, aggClause.groupByItem(), withFilter);
-        } else {
-            withAgg = withProject;
-        }
-
-        return withAgg;
-    }
-
-    @Override
-    public LogicalPlan visitFromClause(FromClauseContext ctx) {

Review Comment:
   should not remove this function, from clause use in more than one place in the future



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -143,265 +130,47 @@ public Object visitChildren(RuleNode node) {
 
     @Override
     public LogicalPlan visitSingleStatement(SingleStatementContext ctx) {
-        Supplier<LogicalPlan> f = () -> (LogicalPlan) visit(ctx.statement());
-        return ParserUtils.withOrigin(ctx, f);
+        return ParserUtils.withOrigin(ctx, () -> (LogicalPlan) visit(ctx.statement()));
     }
 
     /* ********************************************************************************************
      * Plan parsing
      * ******************************************************************************************** */
-    private LogicalPlan plan(ParserRuleContext tree) {
-        return (LogicalPlan) tree.accept(this);
-    }
-
     @Override
     public LogicalPlan visitQuery(QueryContext ctx) {
-        Supplier<LogicalPlan> f = () -> {
+        return ParserUtils.withOrigin(ctx, () -> {
             // TODO: need to add withQueryResultClauses and withCTE
             LogicalPlan query = plan(ctx.queryTerm());
-            LogicalPlan queryOrganization = withQueryOrganization(ctx.queryOrganization(), query);
+            LogicalPlan queryOrganization = withOrganization(query, ctx.queryOrganization());
             return queryOrganization;
-        };
-        return ParserUtils.withOrigin(ctx, f);
-    }
-
-    private LogicalPlan withQueryOrganization(QueryOrganizationContext ctx, LogicalPlan children) {
-        List<SortItems> sortItems = visitQueryOrganization(ctx);
-        return sortItems == null ? children : new LogicalUnaryPlan(new LogicalSort(sortItems), children);
+        });
     }
 
     @Override
     public LogicalPlan visitRegularQuerySpecification(RegularQuerySpecificationContext ctx) {
-        Supplier<LogicalPlan> f = () -> {
+        return ParserUtils.withOrigin(ctx, () -> {
             // TODO: support on row relation
-            LogicalPlan from = visitFromClause(ctx.fromClause());
+            LogicalPlan relation = withRelation(Optional.ofNullable(ctx.fromClause()));

Review Comment:
   from clause is not only include relation, but also other plans, i think the original name `from` is better than `relation`



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundAlias.java:
##########
@@ -34,18 +38,28 @@
         extends NamedExpression
         implements UnaryExpression<CHILD_TYPE>, Unbound {
 
-    public UnboundAlias(CHILD_TYPE child) {
+    private final ExprId exprId;
+    private final String name;
+
+    public UnboundAlias(ExprId exprId, CHILD_TYPE child) {

Review Comment:
   unbound alias do not need ExprId at all, We only create unbound alias when we cannot ensure this expression represent one column, so no slot reference could refer to one UnboundAlias



-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] github-actions[bot] commented on pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #10415:
URL: https://github.com/apache/doris/pull/10415#issuecomment-1170776904

   PR approved by anyone and no changes requested.


-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] github-actions[bot] commented on pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #10415:
URL: https://github.com/apache/doris/pull/10415#issuecomment-1170921377

   PR approved by at least one committer and no changes requested.


-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] EmmyMiao87 commented on a diff in pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
EmmyMiao87 commented on code in PR #10415:
URL: https://github.com/apache/doris/pull/10415#discussion_r908345298


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalAggregation.java:
##########
@@ -42,13 +41,12 @@
 public class LogicalAggregation extends LogicalUnaryOperator {
 
     private final List<Expression> groupByExpressions;
-    private final List<? extends NamedExpression> outputExpressions;
+    private final List<NamedExpression> outputExpressions;

Review Comment:
   This piece of code was fixed in Wenjie's pr and needs to be rebase.



-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] 924060929 commented on a diff in pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
924060929 commented on code in PR #10415:
URL: https://github.com/apache/doris/pull/10415#discussion_r910578515


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindFunction.java:
##########
@@ -0,0 +1,91 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.rules.analysis;
+
+import org.apache.doris.nereids.analyzer.UnboundFunction;
+import org.apache.doris.nereids.operators.plans.logical.LogicalAggregate;
+import org.apache.doris.nereids.operators.plans.logical.LogicalProject;
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import org.apache.doris.nereids.trees.expressions.DefaultExpressionRewriter;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.functions.Sum;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * BindFunction.
+ */
+public class BindFunction implements AnalysisRuleFactory {
+    @Override
+    public List<Rule<Plan>> buildRules() {
+        return ImmutableList.of(
+            RuleType.BINDING_PROJECT_FUNCTION.build(
+                logicalProject().then(project -> {
+                    List<NamedExpression> boundExpr = bind(project.operator.getProjects());
+                    LogicalProject op = new LogicalProject(boundExpr);
+                    return plan(op, project.child());
+                })
+            ),
+            RuleType.BINDING_AGGREGATE_FUNCTION.build(
+                logicalAggregate().then(agg -> {
+                    List<Expression> groupBy = bind(agg.operator.getGroupByExprList());
+                    List<NamedExpression> output = bind(agg.operator.getOutputExpressionList());
+                    LogicalAggregate op = new LogicalAggregate(groupBy, output);
+                    return plan(op, agg.child());
+                })
+            )
+        );
+    }
+
+    private <E extends Expression> List<E> bind(List<E> exprList) {
+        return exprList.stream()
+            .map(expr -> bind(expr))
+            .collect(Collectors.toList());
+    }
+
+    private <E extends Expression> E bind(E expr) {
+        return new FunctionBinder().bind(expr);

Review Comment:
   okey



-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] 924060929 commented on a diff in pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
924060929 commented on code in PR #10415:
URL: https://github.com/apache/doris/pull/10415#discussion_r907128438


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundAlias.java:
##########
@@ -34,18 +38,28 @@
         extends NamedExpression
         implements UnaryExpression<CHILD_TYPE>, Unbound {
 
-    public UnboundAlias(CHILD_TYPE child) {
+    private final ExprId exprId;
+    private final String name;
+
+    public UnboundAlias(ExprId exprId, CHILD_TYPE child) {

Review Comment:
   okey



-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] 924060929 commented on a diff in pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
924060929 commented on code in PR #10415:
URL: https://github.com/apache/doris/pull/10415#discussion_r910575241


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/pattern/GroupExpressionMatching.java:
##########
@@ -102,9 +104,12 @@ public GroupExpressionIterator(Pattern<Plan, Plan> pattern, GroupExpression grou
                     Group childGroup = groupExpression.child(i);
                     List<Plan> childrenPlan = matchingChildGroup(pattern, childGroup, i);
                     childrenPlans.add(childrenPlan);
+                    if (childrenPlans.isEmpty()) {

Review Comment:
   yes



-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] 924060929 commented on a diff in pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
924060929 commented on code in PR #10415:
URL: https://github.com/apache/doris/pull/10415#discussion_r910584924


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java:
##########
@@ -114,35 +168,60 @@ public Slot visitUnboundSlot(UnboundSlot unboundSlot, Void context) {
 
         @Override
         public Expression visitUnboundStar(UnboundStar unboundStar, Void context) {
+            if (!isProjection) {
+                throw new AnalysisException("UnboundStar must exists in Projection");
+            }
             List<String> qualifier = unboundStar.getQualifier();
-            List<Slot> boundSlots = Lists.newArrayList();
             switch (qualifier.size()) {
                 case 0: // select *
-                    boundSlots.addAll(boundSlots);
-                    break;
+                    return new BoundStar(boundSlots);
                 case 1: // select table.*
-                    analyzeBoundSlots(qualifier, context);
-                    break;
                 case 2: // select db.table.*
-                    analyzeBoundSlots(qualifier, context);
-                    break;
+                    return bindQualifiedStar(qualifier, context);
                 default:
                     throw new AnalysisException("Not supported qualifier: "
                         + StringUtils.join(qualifier, "."));
             }
-            return null;
         }
 
-        private void analyzeBoundSlots(List<String> qualifier, Void context) {
-            this.boundSlots.stream()
-                    .forEach(slot ->
-                        boundSlots.add(visitUnboundSlot(new UnboundSlot(
-                            ImmutableList.<String>builder()
-                                .addAll(qualifier)
-                                .add(slot.getName())
-                                .build()
-                        ), context))
-                    );
+        private BoundStar bindQualifiedStar(List<String> qualifierStar, Void context) {
+            List<Slot> slots = boundSlots.stream().filter(boundSlot -> {
+                switch (qualifierStar.size()) {
+                    // table.*
+                    case 1:
+                        List<String> boundSlotQualifier = boundSlot.getQualifier();
+                        switch (boundSlotQualifier.size()) {
+                            // bound slot is `column` and no qualified
+                            case 0: return false;
+                            case 1: // bound slot is `table`.`column`
+                                return qualifierStar.get(0).equalsIgnoreCase(boundSlotQualifier.get(0));
+                            case 2:// bound slot is `db`.`table`.`column`
+                                return qualifierStar.get(0).equalsIgnoreCase(boundSlotQualifier.get(1));

Review Comment:
   > what will happen?
   
   sparksql will select all column in the db.t1 and the t1.
   doris legacy analyzer will throw exception: Column 'xxx' in is ambiguous.
   
   > what should happen?
   
   compatible with previous behavior and throw exception.
   
   ---
   I will add a fixme comment
   
   



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/pattern/GroupExpressionMatching.java:
##########
@@ -102,9 +104,12 @@ public GroupExpressionIterator(Pattern<Plan, Plan> pattern, GroupExpression grou
                     Group childGroup = groupExpression.child(i);
                     List<Plan> childrenPlan = matchingChildGroup(pattern, childGroup, i);
                     childrenPlans.add(childrenPlan);
+                    if (childrenPlans.isEmpty()) {

Review Comment:
   I add a ut



-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] yinzhijian commented on a diff in pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
yinzhijian commented on code in PR #10415:
URL: https://github.com/apache/doris/pull/10415#discussion_r910724625


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ExpressionConverter.java:
##########
@@ -134,16 +130,16 @@ public Expr visitLiteral(Literal literal, PlanTranslatorContext context) {
 
     // TODO: Supports for `distinct`
     @Override
-    public Expr visitFunctionCall(FunctionCall function, PlanTranslatorContext context) {
+    public Expr visitBoundFunction(BoundFunction function, PlanTranslatorContext context) {
         List<Expr> paramList = new ArrayList<>();
-        for (Expression expr : function.getFnParams().getExpressionList()) {
+        for (Expression expr : function.getArguments()) {
             paramList.add(visit(expr, context));

Review Comment:
   DefaultExpressionVisitor.visit always returns null
   ```suggestion
               paramList.add(expr.accept(this, context));
   ```



-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] yinzhijian commented on a diff in pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
yinzhijian commented on code in PR #10415:
URL: https://github.com/apache/doris/pull/10415#discussion_r910752345


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ExpressionConverter.java:
##########
@@ -44,19 +45,14 @@
  * Used to convert expression of new optimizer to stale expr.
  */
 @SuppressWarnings("rawtypes")
-public class ExpressionConverter extends ExpressionVisitor<Expr, PlanTranslatorContext> {
+public class ExpressionConverter extends DefaultExpressionVisitor<Expr, PlanTranslatorContext> {
 
     public static ExpressionConverter converter = new ExpressionConverter();
 
     public static Expr convert(Expression expression, PlanTranslatorContext planContext) {
         return converter.visit(expression, planContext);

Review Comment:
   ```suggestion
           return expression.accept(converter, planContext);
   ```



-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] morrySnow commented on a diff in pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
morrySnow commented on code in PR #10415:
URL: https://github.com/apache/doris/pull/10415#discussion_r910174240


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/pattern/GroupExpressionMatching.java:
##########
@@ -102,9 +104,12 @@ public GroupExpressionIterator(Pattern<Plan, Plan> pattern, GroupExpression grou
                     Group childGroup = groupExpression.child(i);
                     List<Plan> childrenPlan = matchingChildGroup(pattern, childGroup, i);
                     childrenPlans.add(childrenPlan);
+                    if (childrenPlans.isEmpty()) {

Review Comment:
   childrenPlans could not be empty. do u want to add `childrenPlan.isEmpty()`?



##########
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:
   if only project use `isProjection = true`, should we provide a wrapper function that set isProjection default to true?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ProjectToGlobalAggregate.java:
##########
@@ -0,0 +1,53 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.rules.analysis;
+
+import org.apache.doris.nereids.operators.plans.logical.LogicalAggregate;
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.functions.AggregateFunction;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+
+/** ProjectToGlobalAggregate. */
+public class ProjectToGlobalAggregate extends OneAnalysisRuleFactory {

Review Comment:
   coool~



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java:
##########
@@ -114,35 +168,60 @@ public Slot visitUnboundSlot(UnboundSlot unboundSlot, Void context) {
 
         @Override
         public Expression visitUnboundStar(UnboundStar unboundStar, Void context) {
+            if (!isProjection) {
+                throw new AnalysisException("UnboundStar must exists in Projection");
+            }
             List<String> qualifier = unboundStar.getQualifier();
-            List<Slot> boundSlots = Lists.newArrayList();
             switch (qualifier.size()) {
                 case 0: // select *
-                    boundSlots.addAll(boundSlots);
-                    break;
+                    return new BoundStar(boundSlots);
                 case 1: // select table.*
-                    analyzeBoundSlots(qualifier, context);
-                    break;
                 case 2: // select db.table.*
-                    analyzeBoundSlots(qualifier, context);
-                    break;
+                    return bindQualifiedStar(qualifier, context);
                 default:
                     throw new AnalysisException("Not supported qualifier: "
                         + StringUtils.join(qualifier, "."));
             }
-            return null;
         }
 
-        private void analyzeBoundSlots(List<String> qualifier, Void context) {
-            this.boundSlots.stream()
-                    .forEach(slot ->
-                        boundSlots.add(visitUnboundSlot(new UnboundSlot(
-                            ImmutableList.<String>builder()
-                                .addAll(qualifier)
-                                .add(slot.getName())
-                                .build()
-                        ), context))
-                    );
+        private BoundStar bindQualifiedStar(List<String> qualifierStar, Void context) {
+            List<Slot> slots = boundSlots.stream().filter(boundSlot -> {
+                switch (qualifierStar.size()) {
+                    // table.*
+                    case 1:
+                        List<String> boundSlotQualifier = boundSlot.getQualifier();
+                        switch (boundSlotQualifier.size()) {
+                            // bound slot is `column` and no qualified
+                            case 0: return false;
+                            case 1: // bound slot is `table`.`column`
+                                return qualifierStar.get(0).equalsIgnoreCase(boundSlotQualifier.get(0));
+                            case 2:// bound slot is `db`.`table`.`column`
+                                return qualifierStar.get(0).equalsIgnoreCase(boundSlotQualifier.get(1));

Review Comment:
   if we have to table, one's qualifier is db.t1 and another's qualifier is t1. When we bind t1.*, what will happen? and what should happen? i think maybe we need to throw a ambiguous exception?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/TreeNode.java:
##########
@@ -46,4 +48,27 @@
 
     NODE_TYPE withChildren(List<NODE_TYPE> children);
 
+    default void foreach(Consumer<TreeNode<NODE_TYPE>> func) {

Review Comment:
   this is a top-down foreach, so maybe it is better to add traverse order info into function name



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindFunction.java:
##########
@@ -0,0 +1,91 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.rules.analysis;
+
+import org.apache.doris.nereids.analyzer.UnboundFunction;
+import org.apache.doris.nereids.operators.plans.logical.LogicalAggregate;
+import org.apache.doris.nereids.operators.plans.logical.LogicalProject;
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import org.apache.doris.nereids.trees.expressions.DefaultExpressionRewriter;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.functions.Sum;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * BindFunction.
+ */
+public class BindFunction implements AnalysisRuleFactory {
+    @Override
+    public List<Rule<Plan>> buildRules() {
+        return ImmutableList.of(
+            RuleType.BINDING_PROJECT_FUNCTION.build(
+                logicalProject().then(project -> {
+                    List<NamedExpression> boundExpr = bind(project.operator.getProjects());
+                    LogicalProject op = new LogicalProject(boundExpr);
+                    return plan(op, project.child());
+                })
+            ),
+            RuleType.BINDING_AGGREGATE_FUNCTION.build(
+                logicalAggregate().then(agg -> {
+                    List<Expression> groupBy = bind(agg.operator.getGroupByExprList());
+                    List<NamedExpression> output = bind(agg.operator.getOutputExpressionList());
+                    LogicalAggregate op = new LogicalAggregate(groupBy, output);
+                    return plan(op, agg.child());
+                })
+            )
+        );
+    }
+
+    private <E extends Expression> List<E> bind(List<E> exprList) {
+        return exprList.stream()
+            .map(expr -> bind(expr))
+            .collect(Collectors.toList());
+    }
+
+    private <E extends Expression> E bind(E expr) {
+        return new FunctionBinder().bind(expr);

Review Comment:
   could use singleton for `new FunctionBinder()`?



-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] 924060929 commented on a diff in pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
924060929 commented on code in PR #10415:
URL: https://github.com/apache/doris/pull/10415#discussion_r907126581


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -143,265 +130,47 @@ public Object visitChildren(RuleNode node) {
 
     @Override
     public LogicalPlan visitSingleStatement(SingleStatementContext ctx) {
-        Supplier<LogicalPlan> f = () -> (LogicalPlan) visit(ctx.statement());
-        return ParserUtils.withOrigin(ctx, f);
+        return ParserUtils.withOrigin(ctx, () -> (LogicalPlan) visit(ctx.statement()));
     }
 
     /* ********************************************************************************************
      * Plan parsing
      * ******************************************************************************************** */
-    private LogicalPlan plan(ParserRuleContext tree) {
-        return (LogicalPlan) tree.accept(this);
-    }
-
     @Override
     public LogicalPlan visitQuery(QueryContext ctx) {
-        Supplier<LogicalPlan> f = () -> {
+        return ParserUtils.withOrigin(ctx, () -> {
             // TODO: need to add withQueryResultClauses and withCTE
             LogicalPlan query = plan(ctx.queryTerm());
-            LogicalPlan queryOrganization = withQueryOrganization(ctx.queryOrganization(), query);
+            LogicalPlan queryOrganization = withOrganization(query, ctx.queryOrganization());
             return queryOrganization;
-        };
-        return ParserUtils.withOrigin(ctx, f);
-    }
-
-    private LogicalPlan withQueryOrganization(QueryOrganizationContext ctx, LogicalPlan children) {
-        List<SortItems> sortItems = visitQueryOrganization(ctx);
-        return sortItems == null ? children : new LogicalUnaryPlan(new LogicalSort(sortItems), children);
+        });
     }
 
     @Override
     public LogicalPlan visitRegularQuerySpecification(RegularQuerySpecificationContext ctx) {
-        Supplier<LogicalPlan> f = () -> {
+        return ParserUtils.withOrigin(ctx, () -> {
             // TODO: support on row relation
-            LogicalPlan from = visitFromClause(ctx.fromClause());
+            LogicalPlan relation = withRelation(Optional.ofNullable(ctx.fromClause()));
             return withSelectQuerySpecification(
-                    ctx,
-                    ctx.selectClause(),
-                    ctx.whereClause(),
-                    from,
-                    ctx.aggClause());
-        };
-        return ParserUtils.withOrigin(ctx, f);
-    }
-
-    @Override
-    public Expression visitExpression(ExpressionContext ctx) {
-        Supplier<Expression> f = () -> (Expression) visit(ctx.booleanExpression());
-        return ParserUtils.withOrigin(ctx, f);
-    }
-
-    @Override
-    public List<Expression> visitNamedExpressionSeq(NamedExpressionSeqContext ctx) {
-        List<Expression> expressions = Lists.newArrayList();
-        if (ctx != null) {
-            for (NamedExpressionContext namedExpressionContext : ctx.namedExpression()) {
-                Expression expression = typedVisit(namedExpressionContext);
-                expressions.add(expression);
-            }
-        }
-        return expressions;
-    }
-
-    /**
-     * Add a regular (SELECT) query specification to a logical plan. The query specification
-     * is the core of the logical plan, this is where sourcing (FROM clause), projection (SELECT),
-     * aggregation (GROUP BY ... HAVING ...) and filtering (WHERE) takes place.
-     *
-     * <p>Note that query hints are ignored (both by the parser and the builder).
-     */
-    private LogicalPlan withSelectQuerySpecification(
-            ParserRuleContext ctx,
-            SelectClauseContext selectClause,
-            WhereClauseContext whereClause,
-            LogicalPlan relation,
-            AggClauseContext aggClause) {
-        Supplier<LogicalPlan> f = () -> {
-            //        Filter(expression(ctx.booleanExpression), plan);
-            LogicalPlan plan = visitCommonSelectQueryClausePlan(
-                    relation,
-                    visitNamedExpressionSeq(selectClause.namedExpressionSeq()),
-                    whereClause,
-                    aggClause);
-            // TODO: process hint
-            return plan;
-        };
-        return ParserUtils.withOrigin(ctx, f);
-    }
-
-    private LogicalPlan visitCommonSelectQueryClausePlan(
-            LogicalPlan relation,
-            List<Expression> expressions,
-            WhereClauseContext whereClause,
-            AggClauseContext aggClause) {
-        // TODO: add lateral views
-        // val withLateralView = lateralView.asScala.foldLeft(relation)(withGenerate)
-
-        // add where
-        LogicalPlan withFilter = relation.optionalMap(whereClause, withWhereClause);
-
-        List<NamedExpression> namedExpressions = expressions.stream().map(expression -> {
-            if (expression instanceof NamedExpression) {
-                return (NamedExpression) expression;
-            } else {
-                return new UnboundAlias(expression);
-            }
-        }).collect(Collectors.toList());
-
-        LogicalPlan withProject;
-        if (CollectionUtils.isNotEmpty(namedExpressions)) {
-            withProject = new LogicalUnaryPlan(new LogicalProject(namedExpressions), withFilter);
-        } else {
-            withProject = withFilter;
-        }
-
-        LogicalPlan withAgg;
-        if (aggClause != null) {
-            withAgg = withAggClause(namedExpressions, aggClause.groupByItem(), withFilter);
-        } else {
-            withAgg = withProject;
-        }
-
-        return withAgg;
-    }
-
-    @Override
-    public LogicalPlan visitFromClause(FromClauseContext ctx) {

Review Comment:
   okey



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -143,265 +130,47 @@ public Object visitChildren(RuleNode node) {
 
     @Override
     public LogicalPlan visitSingleStatement(SingleStatementContext ctx) {
-        Supplier<LogicalPlan> f = () -> (LogicalPlan) visit(ctx.statement());
-        return ParserUtils.withOrigin(ctx, f);
+        return ParserUtils.withOrigin(ctx, () -> (LogicalPlan) visit(ctx.statement()));
     }
 
     /* ********************************************************************************************
      * Plan parsing
      * ******************************************************************************************** */
-    private LogicalPlan plan(ParserRuleContext tree) {
-        return (LogicalPlan) tree.accept(this);
-    }
-
     @Override
     public LogicalPlan visitQuery(QueryContext ctx) {
-        Supplier<LogicalPlan> f = () -> {
+        return ParserUtils.withOrigin(ctx, () -> {
             // TODO: need to add withQueryResultClauses and withCTE
             LogicalPlan query = plan(ctx.queryTerm());
-            LogicalPlan queryOrganization = withQueryOrganization(ctx.queryOrganization(), query);
+            LogicalPlan queryOrganization = withOrganization(query, ctx.queryOrganization());
             return queryOrganization;
-        };
-        return ParserUtils.withOrigin(ctx, f);
-    }
-
-    private LogicalPlan withQueryOrganization(QueryOrganizationContext ctx, LogicalPlan children) {
-        List<SortItems> sortItems = visitQueryOrganization(ctx);
-        return sortItems == null ? children : new LogicalUnaryPlan(new LogicalSort(sortItems), children);
+        });
     }
 
     @Override
     public LogicalPlan visitRegularQuerySpecification(RegularQuerySpecificationContext ctx) {
-        Supplier<LogicalPlan> f = () -> {
+        return ParserUtils.withOrigin(ctx, () -> {
             // TODO: support on row relation
-            LogicalPlan from = visitFromClause(ctx.fromClause());
+            LogicalPlan relation = withRelation(Optional.ofNullable(ctx.fromClause()));

Review Comment:
   okey



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundAlias.java:
##########
@@ -34,18 +38,28 @@
         extends NamedExpression
         implements UnaryExpression<CHILD_TYPE>, Unbound {
 
-    public UnboundAlias(CHILD_TYPE child) {
+    private final ExprId exprId;
+    private final String name;
+
+    public UnboundAlias(ExprId exprId, CHILD_TYPE child) {
         super(NodeType.UNBOUND_ALIAS, child);
+        this.exprId = Objects.requireNonNull(exprId, "exprId can not be null");
+        this.name = "expr_" + exprId;
     }
 
     @Override
     public String sql() {
-        return null;
+        return child().sql();

Review Comment:
   okey



-- 
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] 924060929 commented on a diff in pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
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-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] 924060929 commented on a diff in pull request #10415: [feature](nereids) Support analyze for test SSB

Posted by GitBox <gi...@apache.org>.
924060929 commented on code in PR #10415:
URL: https://github.com/apache/doris/pull/10415#discussion_r910575894


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/TreeNode.java:
##########
@@ -46,4 +48,27 @@
 
     NODE_TYPE withChildren(List<NODE_TYPE> children);
 
+    default void foreach(Consumer<TreeNode<NODE_TYPE>> func) {

Review Comment:
   I think we have a promise: if the traverse function no order info, it must be top-down implicitly for shorter names
   
   



-- 
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-unsubscribe@doris.apache.org

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


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