Skip to content

Commit

Permalink
sort-push
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Nov 28, 2024
1 parent 7ef42ed commit 318b5b2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public class Rewriter extends AbstractBatchJobExecutor {
new NormalizeAggregate(),
new CountLiteralRewrite(),
new NormalizeSort(),
new MergeProjects(),
new PushDownEncodeSlot()
),
topic("Window analysis",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -142,9 +143,8 @@ public Plan visit(Plan plan, List<Alias> encodeAlias) {
if (toBePushed.containsKey(child)) {
if (child instanceof LogicalProject && child.child(0) instanceof LogicalCatalogRelation) {
LogicalProject project = (LogicalProject) child;
List<NamedExpression> projections = new ArrayList<>();
projections.addAll(toBePushed.get(project));
projections.addAll(project.getProjects());
List<NamedExpression> projections =
PlanUtils.mergeProjections(project.getProjects(), toBePushed.get(child));
newChild = project.withProjects(projections);
} else if (child instanceof LogicalCatalogRelation) {
List<NamedExpression> newProjections = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public static Optional<Slot> extractSlotOrCastOnSlot(Expression expr) {
/**
* Generate replaceMap Slot -> Expression from NamedExpression[Expression as name]
*/
public static Map<Slot, Expression> generateReplaceMap(List<NamedExpression> namedExpressions) {
public static Map<Slot, Expression> generateReplaceMap(List<? extends NamedExpression> namedExpressions) {
Map<Slot, Expression> replaceMap = Maps.newLinkedHashMapWithExpectedSize(namedExpressions.size());
for (NamedExpression namedExpression : namedExpressions) {
if (namedExpression instanceof Alias) {
Expand Down Expand Up @@ -415,7 +415,7 @@ public static Set<Expression> replace(Set<Expression> exprs,
/**
* Replace expression node in the expression tree by `replaceMap` in top-down manner.
*/
public static List<NamedExpression> replaceNamedExpressions(List<NamedExpression> namedExpressions,
public static List<NamedExpression> replaceNamedExpressions(List<? extends NamedExpression> namedExpressions,
Map<? extends Expression, ? extends Expression> replaceMap) {
Builder<NamedExpression> replaceExprs = ImmutableList.builderWithExpectedSize(namedExpressions.size());
for (NamedExpression namedExpression : namedExpressions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public static List<NamedExpression> adjustNullableForRepeat(
/**
* merge childProjects with parentProjects
*/
public static List<NamedExpression> mergeProjections(List<NamedExpression> childProjects,
List<NamedExpression> parentProjects) {
public static List<NamedExpression> mergeProjections(List<? extends NamedExpression> childProjects,
List<? extends NamedExpression> parentProjects) {
Map<Slot, Expression> replaceMap = ExpressionUtils.generateReplaceMap(childProjects);
return ExpressionUtils.replaceNamedExpressions(parentProjects, replaceMap);
}
Expand Down

0 comments on commit 318b5b2

Please sign in to comment.