You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2024/09/20 12:20:18 UTC
(doris) branch branch-2.1 updated: [fix](nereids)adjust conjunct's nullable info in LogicalExternalRelation (#41031)
This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new f60a881425f [fix](nereids)adjust conjunct's nullable info in LogicalExternalRelation (#41031)
f60a881425f is described below
commit f60a881425fbc3828c68a7438ad1c26efb15da21
Author: starocean999 <40...@users.noreply.github.com>
AuthorDate: Fri Sep 20 20:20:12 2024 +0800
[fix](nereids)adjust conjunct's nullable info in LogicalExternalRelation (#41031)
## Proposed changes
pick from master https://github.com/apache/doris/pull/41014
<!--Describe your changes.-->
---
.../nereids/rules/rewrite/AdjustNullable.java | 12 ++++
.../nereids/rules/rewrite/AdjustNullableTest.java | 75 ++++++++++++++++++++++
2 files changed, 87 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..5a6b7ac1b46
--- /dev/null
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/AdjustNullableTest.java
@@ -0,0 +1,75 @@
+// 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: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org