This is an automated email from the ASF dual-hosted git repository.
morrysnow 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 8c34bfea870 [fix](nereids)adjust conjunct's nullable info in
LogicalExternalRelation (#41014)
8c34bfea870 is described below
commit 8c34bfea87010ac0e2debcd4375729c84b701785
Author: starocean999 <[email protected]>
AuthorDate: Mon Sep 23 11:04:46 2024 +0800
[fix](nereids)adjust conjunct's nullable info in LogicalExternalRelation
(#41014)
---
.../nereids/rules/rewrite/AdjustNullable.java | 12 ++++
.../nereids/rules/rewrite/AdjustNullableTest.java | 74 ++++++++++++++++++++++
2 files changed, 86 insertions(+)
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 808288b8fe3..198b6363d9a 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
@@ -31,6 +31,7 @@ import
org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionRewri
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
import org.apache.doris.nereids.trees.plans.logical.LogicalCTEConsumer;
+import org.apache.doris.nereids.trees.plans.logical.LogicalExternalRelation;
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
import org.apache.doris.nereids.trees.plans.logical.LogicalGenerate;
import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
@@ -276,6 +277,17 @@ public class AdjustNullable extends
DefaultPlanRewriter<Map<ExprId, Slot>> imple
return cteConsumer.withTwoMaps(consumerToProducerOutputMap,
producerToConsumerOutputMap);
}
+ @Override
+ public Plan visitLogicalExternalRelation(LogicalExternalRelation relation,
Map<ExprId, Slot> replaceMap) {
+ if (!relation.getConjuncts().isEmpty()) {
+ relation.getOutputSet().forEach(s -> replaceMap.put(s.getExprId(),
s));
+ Set<Expression> conjuncts =
updateExpressions(relation.getConjuncts(), replaceMap);
+ return
relation.withConjuncts(conjuncts).recomputeLogicalProperties();
+ } else {
+ return relation;
+ }
+ }
+
private <T extends Expression> T updateExpression(T input, Map<ExprId,
Slot> replaceMap) {
return (T) input.rewriteDownShortCircuit(e ->
e.accept(SlotReferenceReplacer.INSTANCE, replaceMap));
}
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..023f9c4f7ff
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/AdjustNullableTest.java
@@ -0,0 +1,74 @@
+// 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.ExprId;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.GreaterThan;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.plans.RelationId;
+import org.apache.doris.nereids.trees.plans.logical.LogicalJdbcScan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
+import org.apache.doris.nereids.types.IntegerType;
+import org.apache.doris.nereids.util.MemoPatternMatchSupported;
+import org.apache.doris.nereids.util.PlanConstructor;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * Tests for {@link AdjustNullableTest}.
+ */
+class AdjustNullableTest implements MemoPatternMatchSupported {
+ private final LogicalOlapScan scan = PlanConstructor.newLogicalOlapScan(0,
"t1", 0);
+
+ @Test
+ void testLogicalExternalRelation() {
+ new MockUp<LogicalJdbcScan>() {
+ @Mock
+ public Set<Slot> getOutputSet() {
+ Set<Slot> output = new HashSet<>();
+ output.add(new SlotReference(new ExprId(1), "id",
IntegerType.INSTANCE, false,
+ new ArrayList<>()));
+ return output;
+ }
+ };
+
+ GreaterThan gt = new GreaterThan(new SlotReference(new ExprId(1), "id",
+ IntegerType.INSTANCE, true, new ArrayList<>()),
Literal.of("1"));
+ Set<Expression> conjuncts = new HashSet<>();
+ conjuncts.add(gt);
+ Assertions.assertTrue(conjuncts.iterator().next().nullable());
+ LogicalJdbcScan jdbcScan =
+ new LogicalJdbcScan(new RelationId(1),
PlanConstructor.newOlapTable(0, "t1", 0),
+ new ArrayList<>(), Optional.empty(), Optional.empty(),
conjuncts);
+ AdjustNullable adjustNullable = new AdjustNullable();
+ LogicalJdbcScan newJdbcScan = (LogicalJdbcScan)
adjustNullable.rewriteRoot(jdbcScan, null);
+ conjuncts = newJdbcScan.getConjuncts();
+ Assertions.assertFalse(conjuncts.iterator().next().nullable());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]