[fix](Nereids): fix some bugs in or expansion #34840

add unit test
This commit is contained in:
谢健
2024-05-14 18:14:11 +08:00
committed by GitHub
parent 47f0a6734b
commit bac51723e8
3 changed files with 36 additions and 1 deletions

View File

@ -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 = this.visit(anchor.child(0), 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 = this.visit(anchor.child(1), 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);

View File

@ -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