Skip to content

Commit

Permalink
keep-order
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Nov 11, 2024
1 parent b98467d commit a5b1938
Showing 1 changed file with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
import org.apache.doris.nereids.util.ExpressionUtils;
import org.apache.doris.nereids.util.PlanUtils;
import org.apache.doris.qe.ConnectContext;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -84,8 +87,15 @@ private static Plan pushDownFilterThroughProject(LogicalFilter<LogicalProject<Pl
// just return unchanged plan
return null;
}
project = (LogicalProject<? extends Plan>) project.withChildren(new LogicalFilter<>(
ExpressionUtils.replace(eliminateDecodeAndEncode(splitConjuncts.second), project.getAliasToProducer()),
Set<Expression> conjuncts;
if (ConnectContext.get() != null && ConnectContext.get().getSessionVariable().enableCompressMaterialize) {
conjuncts = ExpressionUtils.replace(eliminateDecodeAndEncode(splitConjuncts.second),
project.getAliasToProducer());
} else {
conjuncts = ExpressionUtils.replace(splitConjuncts.second,
project.getAliasToProducer());
}
project = (LogicalProject<? extends Plan>) project.withChildren(new LogicalFilter<>(conjuncts,
project.child()));
return PlanUtils.filterOrSelf(splitConjuncts.first, project);
}
Expand All @@ -101,10 +111,17 @@ private static Plan pushDownFilterThroughLimitProject(
if (splitConjuncts.second.isEmpty()) {
return null;
}
Set<Expression> conjuncts;
if (ConnectContext.get() != null && ConnectContext.get().getSessionVariable().enableCompressMaterialize) {
conjuncts = ExpressionUtils.replace(eliminateDecodeAndEncode(splitConjuncts.second),
project.getAliasToProducer());
} else {
conjuncts = ExpressionUtils.replace(splitConjuncts.second,
project.getAliasToProducer());
}
project = project.withProjectsAndChild(project.getProjects(),
new LogicalFilter<>(
ExpressionUtils.replace(eliminateDecodeAndEncode(splitConjuncts.second),
project.getAliasToProducer()),
conjuncts,
limit.withChildren(project.child())));
return PlanUtils.filterOrSelf(splitConjuncts.first, project);
}
Expand All @@ -125,9 +142,12 @@ private static Pair<Set<Expression>, Set<Expression>> splitConjunctsByChildOutpu
}

private static Set<Expression> eliminateDecodeAndEncode(Set<Expression> expressions) {
return expressions.stream()
.map(PushDownFilterThroughProject::eliminateDecodeAndEncode)
.collect(Collectors.toSet());
LinkedHashSet<Expression> eliminated = new LinkedHashSet<Expression>();
// keep expression order
for (Expression expression : expressions) {
eliminated.add(eliminateDecodeAndEncode(expression));
}
return eliminated;
}

private static Expression eliminateDecodeAndEncode(Expression expression) {
Expand Down

0 comments on commit a5b1938

Please sign in to comment.