This is an automated email from the ASF dual-hosted git repository.
jakevin 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 04e5047674 [feature](Nereids): binder support bind join function.
(#15010)
04e5047674 is described below
commit 04e504767486ef95227763281a5b36d07793983d
Author: jakevin <[email protected]>
AuthorDate: Tue Dec 13 21:31:44 2022 +0800
[feature](Nereids): binder support bind join function. (#15010)
---
.../org/apache/doris/nereids/rules/RuleType.java | 1 +
.../doris/nereids/rules/analysis/BindFunction.java | 10 +++
.../rules/analysis/AnalyzeFunctionTest.java | 53 ----------------
.../nereids/rules/analysis/BindFunctionTest.java | 72 ++++++++++++++++++++++
.../org/apache/doris/nereids/sqltest/JoinTest.java | 36 +++++++++++
5 files changed, 119 insertions(+), 53 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java
index b336d7a0a7..1f97de337d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java
@@ -49,6 +49,7 @@ public enum RuleType {
BINDING_FILTER_FUNCTION(RuleTypeClass.REWRITE),
BINDING_HAVING_FUNCTION(RuleTypeClass.REWRITE),
BINDING_SORT_FUNCTION(RuleTypeClass.REWRITE),
+ BINDING_JOIN_FUNCTION(RuleTypeClass.REWRITE),
BINDING_UNBOUND_TVF_RELATION_FUNCTION(RuleTypeClass.REWRITE),
REPLACE_SORT_EXPRESSION_BY_CHILD_OUTPUT(RuleTypeClass.REWRITE),
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindFunction.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindFunction.java
index ac0c1238e0..1e6527dcce 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindFunction.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindFunction.java
@@ -43,6 +43,7 @@ import org.apache.doris.nereids.trees.plans.RelationId;
import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
import org.apache.doris.nereids.trees.plans.logical.LogicalHaving;
+import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
import org.apache.doris.nereids.trees.plans.logical.LogicalOneRowRelation;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
import org.apache.doris.nereids.trees.plans.logical.LogicalRepeat;
@@ -126,6 +127,15 @@ public class BindFunction implements AnalysisRuleFactory {
return new LogicalSort<>(orderKeys, sort.child());
})
),
+ RuleType.BINDING_JOIN_FUNCTION.build(
+ logicalJoin().thenApply(ctx -> {
+ LogicalJoin<GroupPlan, GroupPlan> join = ctx.root;
+ List<Expression> hashConjuncts =
bind(join.getHashJoinConjuncts(), ctx.connectContext.getEnv());
+ List<Expression> otherConjuncts =
bind(join.getOtherJoinConjuncts(), ctx.connectContext.getEnv());
+ return new LogicalJoin<>(join.getJoinType(),
hashConjuncts, otherConjuncts,
+ join.left(), join.right());
+ })
+ ),
RuleType.BINDING_UNBOUND_TVF_RELATION_FUNCTION.build(
unboundTVFRelation().thenApply(ctx -> {
UnboundTVFRelation relation = ctx.root;
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/AnalyzeFunctionTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/AnalyzeFunctionTest.java
deleted file mode 100644
index c60a63ce78..0000000000
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/AnalyzeFunctionTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-// 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.analysis;
-
-import org.apache.doris.nereids.parser.NereidsParser;
-import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
-import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
-import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
-import org.apache.doris.nereids.util.PlanChecker;
-import org.apache.doris.utframe.TestWithFeService;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-import java.util.Set;
-
-public class AnalyzeFunctionTest extends TestWithFeService {
-
- private final NereidsParser parser = new NereidsParser();
-
- @Override
- protected void runBeforeAll() throws Exception {
- createDatabase("test");
- connectContext.setDatabase("default_cluster:test");
- createTables("CREATE TABLE t1 (col1 date, col2 int) DISTRIBUTED BY
HASH(col2)\n" + "BUCKETS 1\n" + "PROPERTIES(\n"
- + " \"replication_num\"=\"1\"\n" + ");");
- }
-
- @Test
- public void testTimeArithmExpr() {
- String sql = "SELECT * FROM t1 WHERE col1 < date '1994-01-01' +
interval '1' year";
- LogicalPlan logicalPlan = (LogicalPlan)
PlanChecker.from(connectContext)
- .analyze(sql).getCascadesContext().getMemo().copyOut();
- Assertions.assertTrue(logicalPlan
- .<Set<LogicalFilter>>collect(LogicalFilter.class::isInstance)
- .stream().map(f ->
f.getPredicates()).noneMatch(VarcharLiteral.class::isInstance));
- }
-}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindFunctionTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindFunctionTest.java
new file mode 100644
index 0000000000..992493a9e7
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindFunctionTest.java
@@ -0,0 +1,72 @@
+// 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.analysis;
+
+import org.apache.doris.nereids.parser.NereidsParser;
+import org.apache.doris.nereids.trees.expressions.LessThan;
+import org.apache.doris.nereids.trees.expressions.literal.DateLiteral;
+import org.apache.doris.nereids.util.PatternMatchSupported;
+import org.apache.doris.nereids.util.PlanChecker;
+import org.apache.doris.utframe.TestWithFeService;
+
+import org.junit.jupiter.api.Test;
+
+public class BindFunctionTest extends TestWithFeService implements
PatternMatchSupported {
+
+ private final NereidsParser parser = new NereidsParser();
+
+ @Override
+ protected void runBeforeAll() throws Exception {
+ createDatabase("test");
+ connectContext.setDatabase("default_cluster:test");
+ createTables(
+ "CREATE TABLE t1 (col1 date, col2 int) DISTRIBUTED BY
HASH(col2)\n" + "BUCKETS 1\n" + "PROPERTIES(\n"
+ + " \"replication_num\"=\"1\"\n" + ");",
+ "CREATE TABLE t2 (col1 date, col2 int) DISTRIBUTED BY
HASH(col2)\n" + "BUCKETS 1\n" + "PROPERTIES(\n"
+ + " \"replication_num\"=\"1\"\n" + ");"
+ );
+ }
+
+ @Test
+ public void testTimeArithmExpr() {
+ String sql = "SELECT * FROM t1 WHERE col1 < date '1994-01-01' +
interval '1' year";
+
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .rewrite()
+ .matches(
+ logicalFilter(logicalOlapScan())
+ .when(f -> ((LessThan)
f.getPredicates()).right() instanceof DateLiteral)
+ );
+ }
+
+ @Test
+ void testJoinBindFunction() {
+ String sql = "SELECT * FROM t1 LEFT JOIN t2 ON abs(t1.col2) = t2.col2
where t1.col2 > 10";
+
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .rewrite()
+ .matches(
+ leftOuterLogicalJoin(
+ logicalFilter(),
+ logicalOlapScan()
+ ).when(join -> join.getHashJoinConjuncts().size() == 1)
+ );
+ }
+}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/sqltest/JoinTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/sqltest/JoinTest.java
new file mode 100644
index 0000000000..55021f1103
--- /dev/null
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/sqltest/JoinTest.java
@@ -0,0 +1,36 @@
+// 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.sqltest;
+
+import org.apache.doris.nereids.rules.rewrite.logical.ReorderJoin;
+import org.apache.doris.nereids.util.PlanChecker;
+
+import org.junit.jupiter.api.Test;
+
+public class JoinTest extends SqlTestBase {
+ @Test
+ void testJoinUsing() {
+ String sql = "SELECT * FROM T1 JOIN T2 using (id)";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .applyBottomUp(new ReorderJoin())
+ .matches(
+ innerLogicalJoin().when(j ->
j.getHashJoinConjuncts().size() == 1)
+ );
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]