morrySnow commented on code in PR #11589: URL: https://github.com/apache/doris/pull/11589#discussion_r944365812
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Alias.java: ########## @@ -35,7 +35,7 @@ public class Alias extends NamedExpression implements UnaryExpression { private final ExprId exprId; private final String name; - private final List<String> qualifier; + private List<String> qualifier; Review Comment: add back final ``` ImmutableList.copyOf(Objects.requireNonNull(qualifier, "qualifier can not be null")); ``` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java: ########## @@ -398,6 +399,12 @@ public PlanFragment visitPhysicalNestedLoopJoin(PhysicalNestedLoopJoin<Plan, Pla @Override public PlanFragment visitPhysicalProject(PhysicalProject<Plan> project, PlanTranslatorContext context) { PlanFragment inputFragment = project.child(0).accept(this, context); + + project.getProjects().stream().filter(p -> p instanceof Alias).forEach(p -> { Review Comment: ```suggestion project.getProjects().stream().filter(Alias.class::isInstance).forEach(p -> { ``` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/batch/MergeConsecutiveProjectJob.java: ########## @@ -0,0 +1,44 @@ +// 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.jobs.batch; + +import org.apache.doris.nereids.CascadesContext; +import org.apache.doris.nereids.rules.rewrite.logical.MergeConsecutiveProjects; + +import com.google.common.collect.ImmutableList; + +/** + * Merge consecutive project rules. + */ +public class MergeConsecutiveProjectJob extends BatchRulesJob { + + /** + * Execute the merge consecutive job. + * @param ctx planner context for execute job + */ + public MergeConsecutiveProjectJob(CascadesContext ctx) { + //TODO: eliminate consecutive projects for view + super(ctx); + rulesJob.addAll(ImmutableList.of( + bottomUpBatch(ImmutableList.of( + new MergeConsecutiveProjects() + ) + ) Review Comment: ```suggestion bottomUpBatch(ImmutableList.of(new MergeConsecutiveProjects())) ``` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java: ########## @@ -269,38 +269,40 @@ private BoundStar bindQualifiedStar(List<String> qualifierStar, Void context) { private List<Slot> bindSlot(UnboundSlot unboundSlot, List<Slot> boundSlots) { return boundSlots.stream().filter(boundSlot -> { List<String> nameParts = unboundSlot.getNameParts(); - switch (nameParts.size()) { - case 1: - // Unbound slot name is `column` - return nameParts.get(0).equalsIgnoreCase(boundSlot.getName()); - case 2: - // Unbound slot name is `table`.`column` - List<String> qualifier = boundSlot.getQualifier(); - String name = boundSlot.getName(); - switch (qualifier.size()) { - case 2: - // qualifier is `db`.`table` - return nameParts.get(0).equalsIgnoreCase(qualifier.get(1)) - && nameParts.get(1).equalsIgnoreCase(name); - case 1: - // qualifier is `table` - return nameParts.get(0).equalsIgnoreCase(qualifier.get(0)) - && nameParts.get(1).equalsIgnoreCase(name); - case 0: - // has no qualifiers - return nameParts.get(1).equalsIgnoreCase(name); - default: - throw new AnalysisException("Not supported qualifier: " - + StringUtils.join(qualifier, ".")); - } - default: - throw new AnalysisException("Not supported name: " - + StringUtils.join(nameParts, ".")); + if (nameParts.size() == 1) { + return nameParts.get(0).equalsIgnoreCase(boundSlot.getName()); + } else if (nameParts.size() <= 3) { + int size = nameParts.size(); + return handleNamePartsLessThanThree(boundSlot, nameParts.subList(size - 2, size)); Review Comment: could merge nameParts.size() == 1 branch into it? ########## fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java: ########## @@ -398,6 +399,12 @@ public PlanFragment visitPhysicalNestedLoopJoin(PhysicalNestedLoopJoin<Plan, Pla @Override public PlanFragment visitPhysicalProject(PhysicalProject<Plan> project, PlanTranslatorContext context) { PlanFragment inputFragment = project.child(0).accept(this, context); + + project.getProjects().stream().filter(p -> p instanceof Alias).forEach(p -> { + SlotRef ref = context.findSlotRef(((NamedExpression) p.child(0)).getExprId()); Review Comment: add a todo yo handle Alias's child is not NamedExpression -- 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