This is an automated email from the ASF dual-hosted git repository. jakevin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 1e4a69c2a43 [fix](Nereids): fix some bugs in or expansion (#34837) 1e4a69c2a43 is described below commit 1e4a69c2a43ae0078092bd709008a313cad280a4 Author: 谢健 <jianx...@gmail.com> AuthorDate: Wed May 15 15:27:05 2024 +0800 [fix](Nereids): fix some bugs in or expansion (#34837) add unit test --- .../doris/nereids/rules/rewrite/OrExpansion.java | 25 ++++++++++++++++++++++ .../trees/copier/LogicalPlanDeepCopier.java | 8 ++++++- .../nereids/rules/rewrite/OrExpansionTest.java | 4 ++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/OrExpansion.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/OrExpansion.java index 9f9257f5f60..61a90e3aea4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/OrExpansion.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/OrExpansion.java @@ -104,6 +104,31 @@ public class OrExpansion extends DefaultPlanRewriter<OrExpandsionContext> implem return hasNewChildren ? plan.withChildren(newChildren) : plan; } + @Override + public Plan visitLogicalCTEAnchor( + LogicalCTEAnchor<? extends Plan, ? extends Plan> anchor, OrExpandsionContext ctx) { + Plan child1 = anchor.child(0).accept(this, ctx); + // Consumer's CTE must be child of the cteAnchor in this case: + // anchor + // +-producer1 + // +-agg(consumer1) join agg(consumer1) + // ------------> + // anchor + // +-producer1 + // +-anchor + // +--producer2(agg2(consumer1)) + // +--producer3(agg3(consumer1)) + // +-consumer2 join consumer3 + OrExpandsionContext consumerContext = + new OrExpandsionContext(ctx.statementContext, ctx.cascadesContext); + Plan child2 = anchor.child(1).accept(this, consumerContext); + for (int i = consumerContext.cteProducerList.size() - 1; i >= 0; i--) { + LogicalCTEProducer<? extends Plan> producer = consumerContext.cteProducerList.get(i); + child2 = new LogicalCTEAnchor<>(producer.getCteId(), producer, child2); + } + return anchor.withChildren(ImmutableList.of(child1, child2)); + } + @Override public Plan visitLogicalJoin(LogicalJoin<? extends Plan, ? extends Plan> join, OrExpandsionContext ctx) { join = (LogicalJoin<? extends Plan, ? extends Plan>) this.visit(join, ctx); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/copier/LogicalPlanDeepCopier.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/copier/LogicalPlanDeepCopier.java index dfa881aa2e6..197de0089a3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/copier/LogicalPlanDeepCopier.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/copier/LogicalPlanDeepCopier.java @@ -340,8 +340,14 @@ public class LogicalPlanDeepCopier extends DefaultPlanRewriter<DeepCopierContext List<Expression> markJoinConjuncts = join.getMarkJoinConjuncts().stream() .map(c -> ExpressionDeepCopier.INSTANCE.deepCopy(c, context)) .collect(ImmutableList.toImmutableList()); + Optional<MarkJoinSlotReference> markJoinSlotReference = Optional.empty(); + if (join.getMarkJoinSlotReference().isPresent()) { + markJoinSlotReference = Optional.of((MarkJoinSlotReference) ExpressionDeepCopier.INSTANCE + .deepCopy(join.getMarkJoinSlotReference().get(), context)); + + } return new LogicalJoin<>(join.getJoinType(), hashJoinConjuncts, otherJoinConjuncts, markJoinConjuncts, - join.getDistributeHint(), join.getMarkJoinSlotReference(), children, join.getJoinReorderContext()); + join.getDistributeHint(), markJoinSlotReference, children, join.getJoinReorderContext()); } @Override diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/OrExpansionTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/OrExpansionTest.java index 9f8bd8bcc55..0f2d9418bff 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/OrExpansionTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/OrExpansionTest.java @@ -19,6 +19,7 @@ package org.apache.doris.nereids.rules.rewrite; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalCTEAnchor; +import org.apache.doris.nereids.trees.plans.logical.LogicalCTEConsumer; import org.apache.doris.nereids.util.MemoPatternMatchSupported; import org.apache.doris.nereids.util.PlanChecker; import org.apache.doris.utframe.TestWithFeService; @@ -81,6 +82,9 @@ class OrExpansionTest extends TestWithFeService implements MemoPatternMatchSuppo Assertions.assertTrue(plan instanceof LogicalCTEAnchor); Assertions.assertTrue(plan.child(1) instanceof LogicalCTEAnchor); Assertions.assertTrue(plan.child(1).child(1) instanceof LogicalCTEAnchor); + Assertions.assertTrue(plan.child(1).child(1).anyMatch(x -> x instanceof LogicalCTEConsumer)); Assertions.assertTrue(plan.child(1).child(1).child(1) instanceof LogicalCTEAnchor); + Assertions.assertTrue(plan.child(1).child(1).child(1) + .anyMatch(x -> x instanceof LogicalCTEConsumer)); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org