diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java index ac925c48ecbf726..292a7a1f3e2780f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java @@ -250,6 +250,7 @@ public class Rewriter extends AbstractBatchJobExecutor { new NormalizeAggregate(), new CountLiteralRewrite(), new NormalizeSort(), + new MergeProjects(), new PushDownEncodeSlot() ), topic("Window analysis", diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownEncodeSlot.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownEncodeSlot.java index 69565166953db68..1ddc44dfb3152b4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownEncodeSlot.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownEncodeSlot.java @@ -29,6 +29,7 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalCatalogRelation; import org.apache.doris.nereids.trees.plans.logical.LogicalProject; import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; +import org.apache.doris.nereids.util.PlanUtils; import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; @@ -142,9 +143,8 @@ public Plan visit(Plan plan, List encodeAlias) { if (toBePushed.containsKey(child)) { if (child instanceof LogicalProject && child.child(0) instanceof LogicalCatalogRelation) { LogicalProject project = (LogicalProject) child; - List projections = new ArrayList<>(); - projections.addAll(toBePushed.get(project)); - projections.addAll(project.getProjects()); + List projections = + PlanUtils.mergeProjections(project.getProjects(), toBePushed.get(child)); newChild = project.withProjects(projections); } else if (child instanceof LogicalCatalogRelation) { List newProjections = new ArrayList<>(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/EncodeStr.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/EncodeStr.java index 520db4c3e65d669..d97bea748326e47 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/EncodeStr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/EncodeStr.java @@ -28,6 +28,6 @@ public abstract class EncodeStr extends ScalarFunction implements UnaryExpressio * constructor with 1 argument. */ public EncodeStr(String name, Expression arg0) { - super("encode_as_int", arg0); + super(name, arg0); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java index bf4d6e084795f10..ab3688a9b53d0d5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java @@ -351,7 +351,7 @@ public static Optional extractSlotOrCastOnSlot(Expression expr) { /** * Generate replaceMap Slot -> Expression from NamedExpression[Expression as name] */ - public static Map generateReplaceMap(List namedExpressions) { + public static Map generateReplaceMap(List namedExpressions) { Map replaceMap = Maps.newLinkedHashMapWithExpectedSize(namedExpressions.size()); for (NamedExpression namedExpression : namedExpressions) { if (namedExpression instanceof Alias) { @@ -415,7 +415,7 @@ public static Set replace(Set exprs, /** * Replace expression node in the expression tree by `replaceMap` in top-down manner. */ - public static List replaceNamedExpressions(List namedExpressions, + public static List replaceNamedExpressions(List namedExpressions, Map replaceMap) { Builder replaceExprs = ImmutableList.builderWithExpectedSize(namedExpressions.size()); for (NamedExpression namedExpression : namedExpressions) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/PlanUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/PlanUtils.java index 0076c232340d29f..28f7cda427ed7fe 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/PlanUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/PlanUtils.java @@ -121,8 +121,8 @@ public static List adjustNullableForRepeat( /** * merge childProjects with parentProjects */ - public static List mergeProjections(List childProjects, - List parentProjects) { + public static List mergeProjections(List childProjects, + List parentProjects) { Map replaceMap = ExpressionUtils.generateReplaceMap(childProjects); return ExpressionUtils.replaceNamedExpressions(parentProjects, replaceMap); }