github-actions[bot] commented on code in PR #66806:
URL: https://github.com/apache/doris/pull/66806#discussion_r3841347352
##########
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/EliminateJoinConditionTest.java:
##########
@@ -48,4 +60,76 @@ void basicCase() {
&& join.getOtherJoinConjuncts().size() == 0)
);
}
+
+ @Test
+ void eliminateInnerJoinWithFalseCondition() {
+ LogicalPlan join = new LogicalPlanBuilder(scan1)
+ .join(scan2, JoinType.INNER_JOIN, ImmutableList.of(),
ImmutableList.of(BooleanLiteral.FALSE))
+ .build();
+
+ PlanChecker.from(MemoTestUtils.createConnectContext(), join)
+ .applyTopDown(new EliminateJoinCondition())
+ .matches(logicalEmptyRelation());
+ }
+
+ @Test
+ void eliminateLeftOuterJoinWithNullCondition() {
+ LogicalPlan join = new LogicalPlanBuilder(scan1)
+ .join(scan2, JoinType.LEFT_OUTER_JOIN, ImmutableList.of(),
+ ImmutableList.of(NullLiteral.BOOLEAN_INSTANCE))
+ .build();
+
+ assertNullPaddedProject(join, scan1);
+ }
+
+ @Test
+ void eliminateRightOuterJoinWithFalseCondition() {
+ LogicalPlan join = new LogicalPlanBuilder(scan1)
+ .join(scan2, JoinType.RIGHT_OUTER_JOIN, ImmutableList.of(),
ImmutableList.of(BooleanLiteral.FALSE))
+ .build();
+
+ assertNullPaddedProject(join, scan2);
+ }
+
+ private void assertNullPaddedProject(LogicalPlan join, LogicalPlan
preservedChild) {
+ List<Slot> originalOutput = join.getOutput();
+ Set<Slot> preservedOutput = preservedChild.getOutputSet();
+
+ LogicalPlan rewritten = (LogicalPlan)
PlanChecker.from(MemoTestUtils.createConnectContext(), join)
+ .applyTopDown(new EliminateJoinCondition())
+ .getPlan();
+ Assertions.assertInstanceOf(LogicalProject.class, rewritten);
+ LogicalProject<?> project = (LogicalProject<?>) rewritten;
+ Assertions.assertEquals(preservedChild, project.child());
+ Assertions.assertEquals(originalOutput, project.getOutput());
+ for (int i = 0; i < originalOutput.size(); i++) {
+ NamedExpression projectExpression = project.getProjects().get(i);
+ if (preservedOutput.contains(originalOutput.get(i))) {
+ Assertions.assertEquals(originalOutput.get(i),
projectExpression);
+ } else {
+ Assertions.assertInstanceOf(Alias.class, projectExpression);
+ Assertions.assertInstanceOf(NullLiteral.class,
projectExpression.child(0));
+ Assertions.assertEquals(originalOutput.get(i).getQualifier(),
projectExpression.getQualifier());
+ }
+ }
+ }
+
+ @Test
+ void propagateNullPaddedOutputToInnerJoin() {
+ LogicalPlan leftOuterJoin = new LogicalPlanBuilder(scan1)
+ .join(scan2, JoinType.LEFT_OUTER_JOIN, ImmutableList.of(),
ImmutableList.of(BooleanLiteral.FALSE))
+ .build();
+ Slot nullPaddedSlot =
leftOuterJoin.getOutput().get(scan1.getOutput().size());
+ LogicalPlan innerJoin = new LogicalPlanBuilder(leftOuterJoin)
+ .join(scan3, JoinType.INNER_JOIN, ImmutableList.of(),
+ ImmutableList.of(new EqualTo(
+ new If(BooleanLiteral.TRUE, nullPaddedSlot,
nullPaddedSlot),
+ scan3.getOutput().get(0))))
+ .build();
+
+ PlanChecker.from(MemoTestUtils.createConnectContext(), innerJoin)
+ .applyBottomUp(new EliminateJoinCondition())
Review Comment:
Please cover the direct same-pass path added here. This test pre-eliminates
the lower join with `EliminateJoinCondition`, so `ConstantPropagation` never
has to create that NULL-padded project and then consume its fresh uniform-NULL
trait while visiting the parent. The changed `InferPredicatesTest` covers
lower-join elimination but deliberately leaves its parent join, and the
regression covers only an isolated lower join. Add a case where the lower outer
condition becomes FALSE/NULL only during constant propagation, the parent
predicate references the lower nullable-side slot, and the normal traversal
must finish as `LogicalEmptyRelation`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]