This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new 0a8b9eabbd0 [fix](join) Preserve input nullability for ASOF match
conditions (#69616)
0a8b9eabbd0 is described below
commit 0a8b9eabbd056c515e282e528510dfc6cdc5154c
Author: Mryange <[email protected]>
AuthorDate: Tue Oct 27 09:21:29 2026 +0800
[fix](join) Preserve input nullability for ASOF match conditions (#69616)
[fix](join) Preserve input nullability for ASOF match conditions
### What problem does this PR solve?
Issue Number: N/A
Related PR: N/A
Problem Summary: The final `AdjustNullable` pass rewrites other join
conjuncts using join output slots. For outer ASOF joins, the sole other
conjunct is the match condition, which BE evaluates on child input
blocks before null padding. This can make an input NOT NULL slot
nullable only in the FE expression and cause a nullable column shape
mismatch during build-key evaluation. Keep ASOF match conditions tied to
child input nullability while retaining the existing rule for other
joins.
### Release note
ASOF JOIN planning preserves child input nullability in match
conditions, preventing nullable column shape mismatches during build-key
evaluation.
### Check List (For Author)
- Test: Added focused FE coverage for all ASOF join types plus a regular
LEFT OUTER JOIN control; not run locally.
- Behavior changed: Yes. ASOF match conditions retain child input
nullability.
- Does this need documentation: No
---
.../nereids/rules/rewrite/AdjustNullable.java | 8 ++-
.../nereids/rules/rewrite/AdjustNullableTest.java | 68 ++++++++++++++++++++++
2 files changed, 73 insertions(+), 3 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AdjustNullable.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AdjustNullable.java
index 734779de37a..394801a7f0c 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AdjustNullable.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AdjustNullable.java
@@ -199,9 +199,11 @@ public class AdjustNullable extends
DefaultPlanRewriter<Map<ExprId, Slot>> imple
// then later at rewrite phase, the join conditions may push down,
and the push down condition with proper
// nullable attribute.
// 2) when at the end of rewrite phase, update other conjuncts with
join output nullables.
- // Just change it to be consistent with BE.
+ // Just change it to be consistent with BE. ASOF match conditions
are evaluated on child input blocks before
+ // outer-join null padding, so they keep the child nullable
attributes in both phases.
Optional<List<Expression>> otherConjuncts = Optional.empty();
- if (isAnalyzedPhase) {
+ boolean useJoinOutputNullableForOtherConjuncts = !isAnalyzedPhase &&
!join.getJoinType().isAsofJoin();
+ if (!useJoinOutputNullableForOtherConjuncts) {
otherConjuncts = doUpdateExpressions(join.getOtherJoinConjuncts(),
replaceMap, false);
}
for (Slot slot : join.getOutput()) {
@@ -210,7 +212,7 @@ public class AdjustNullable extends
DefaultPlanRewriter<Map<ExprId, Slot>> imple
if (!hadUpdatedMarkConjuncts) {
markConjuncts = doUpdateExpressions(join.getMarkJoinConjuncts(),
replaceMap, false);
}
- if (!isAnalyzedPhase) {
+ if (useJoinOutputNullableForOtherConjuncts) {
otherConjuncts = doUpdateExpressions(join.getOtherJoinConjuncts(),
replaceMap, false);
}
if (!hashConjuncts.isPresent() && !markConjuncts.isPresent() &&
!otherConjuncts.isPresent()) {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/AdjustNullableTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/AdjustNullableTest.java
new file mode 100644
index 00000000000..ee05d8f4378
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/AdjustNullableTest.java
@@ -0,0 +1,68 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.rules.rewrite;
+
+import org.apache.doris.nereids.trees.expressions.EqualTo;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.GreaterThan;
+import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.plans.JoinType;
+import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
+import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
+import org.apache.doris.nereids.util.LogicalPlanBuilder;
+import org.apache.doris.nereids.util.PlanConstructor;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+
+class AdjustNullableTest {
+
+ @Test
+ void testAsofMatchConditionUsesChildNullability() {
+ assertOtherConjunctNullability(JoinType.ASOF_LEFT_INNER_JOIN, false);
+ assertOtherConjunctNullability(JoinType.ASOF_RIGHT_INNER_JOIN, false);
+ assertOtherConjunctNullability(JoinType.ASOF_LEFT_OUTER_JOIN, false);
+ assertOtherConjunctNullability(JoinType.ASOF_RIGHT_OUTER_JOIN, false);
+ }
+
+ @Test
+ void testRegularOuterJoinOtherConditionUsesJoinOutputNullability() {
+ assertOtherConjunctNullability(JoinType.LEFT_OUTER_JOIN, true);
+ }
+
+ private void assertOtherConjunctNullability(JoinType joinType, boolean
rightNullable) {
+ LogicalOlapScan left = new
LogicalOlapScan(PlanConstructor.getNextRelationId(), PlanConstructor.student,
+ ImmutableList.of(""));
+ LogicalOlapScan right = new
LogicalOlapScan(PlanConstructor.getNextRelationId(), PlanConstructor.student,
+ ImmutableList.of(""));
+ Expression hashCondition = new EqualTo(left.getOutput().get(0),
right.getOutput().get(0));
+ Expression matchCondition = new GreaterThan(left.getOutput().get(1),
right.getOutput().get(1));
+ LogicalJoin<?, ?> join = (LogicalJoin<?, ?>) new
LogicalPlanBuilder(left)
+ .join(right, joinType, ImmutableList.of(hashCondition),
ImmutableList.of(matchCondition))
+ .build();
+
+ LogicalJoin<?, ?> adjustedJoin =
AdjustNullable.doVisitLogicalJoin(join, new HashMap<>(), false, false);
+ GreaterThan adjustedCondition = (GreaterThan)
adjustedJoin.getOtherJoinConjuncts().get(0);
+
+ Assertions.assertFalse(((SlotReference)
adjustedCondition.left()).nullable());
+ Assertions.assertEquals(rightNullable, ((SlotReference)
adjustedCondition.right()).nullable());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]