[fix](Nereids) join condition not extract as conjunctions (#20498)

This commit is contained in:
morrySnow
2023-06-06 20:34:19 +08:00
committed by GitHub
parent 05bdbce8fc
commit 82cf76f92b

View File

@ -42,7 +42,6 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@ -189,7 +188,7 @@ public class ExpressionRewrite implements RewriteRuleFactory {
for (Expression expr : hashJoinConjuncts) {
Expression newExpr = rewriter.rewrite(expr, context);
hashJoinConjunctsChanged = hashJoinConjunctsChanged || !newExpr.equals(expr);
rewriteHashJoinConjuncts.add(newExpr);
rewriteHashJoinConjuncts.addAll(ExpressionUtils.extractConjunction(newExpr));
}
List<Expression> rewriteOtherJoinConjuncts = Lists.newArrayList();
@ -197,7 +196,7 @@ public class ExpressionRewrite implements RewriteRuleFactory {
for (Expression expr : otherJoinConjuncts) {
Expression newExpr = rewriter.rewrite(expr, context);
otherJoinConjunctsChanged = otherJoinConjunctsChanged || !newExpr.equals(expr);
rewriteOtherJoinConjuncts.add(newExpr);
rewriteOtherJoinConjuncts.addAll(ExpressionUtils.extractConjunction(newExpr));
}
if (!hashJoinConjunctsChanged && !otherJoinConjunctsChanged) {
@ -233,12 +232,13 @@ public class ExpressionRewrite implements RewriteRuleFactory {
public Rule build() {
return logicalHaving().thenApply(ctx -> {
LogicalHaving<Plan> having = ctx.root;
Set<Expression> rewrittenExpr = new HashSet<>();
ExpressionRewriteContext context = new ExpressionRewriteContext(ctx.cascadesContext);
for (Expression e : having.getExpressions()) {
rewrittenExpr.add(rewriter.rewrite(e, context));
Set<Expression> newConjuncts = ImmutableSet.copyOf(ExpressionUtils.extractConjunction(
rewriter.rewrite(having.getPredicate(), context)));
if (newConjuncts.equals(having.getConjuncts())) {
return having;
}
return having.withExpressions(rewrittenExpr);
return having.withExpressions(newConjuncts);
}).toRule(RuleType.REWRITE_HAVING_EXPRESSION);
}
}