This is an automated email from the ASF dual-hosted git repository.
starocean999 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 5ab2aea8af add test for bindExpr (#24032)
5ab2aea8af is described below
commit 5ab2aea8afda5640c7f060e00dcf88f7f1ee2e9a
Author: 谢健 <[email protected]>
AuthorDate: Tue Sep 12 11:00:57 2023 +0800
add test for bindExpr (#24032)
add unit test for bindExpression rule
---
.../nereids/rules/analysis/BindExpressionTest.java | 161 +++++++++++++++++++++
1 file changed, 161 insertions(+)
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindExpressionTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindExpressionTest.java
new file mode 100644
index 0000000000..684c55bf4a
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindExpressionTest.java
@@ -0,0 +1,161 @@
+// 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.pattern.GeneratedPlanPatterns;
+import org.apache.doris.nereids.rules.RulePromise;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.plans.JoinType;
+import org.apache.doris.nereids.util.PlanChecker;
+import org.apache.doris.utframe.TestWithFeService;
+
+import org.junit.jupiter.api.Test;
+
+class BindExpressionTest extends TestWithFeService implements
GeneratedPlanPatterns {
+
+ @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
+ void testJoin() {
+ for (JoinType joinType : JoinType.values()) {
+ String sql = String.format("select * from t1 %s t2 on t1.col2 =
t2.col2",
+ joinType.toString().replace("_", " "));
+ if (joinType.isCrossJoin()) {
+ sql = String.format("select * from t1 %s t2",
+ joinType.toString().replace("_", " "));
+ }
+ if (joinType.isNullAwareLeftAntiJoin()) {
+ continue;
+ }
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .nonMatch(any()
+ .when(e ->
e.getExpressions().stream().anyMatch(Expression::hasUnbound)));
+ }
+ }
+
+ @Test
+ void testAggHaving() {
+ String sql = "select sum(col2) from t1 group by col1";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .nonMatch(any()
+ .when(e ->
e.getExpressions().stream().anyMatch(Expression::hasUnbound)));
+
+ sql = "select sum(col2) from t1 group by col2";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .nonMatch(any()
+ .when(e ->
e.getExpressions().stream().anyMatch(Expression::hasUnbound)));
+
+ sql = "select sum(col2) from t1 group by col2, col1 having col1 > 0";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .nonMatch(any()
+ .when(e ->
e.getExpressions().stream().anyMatch(Expression::hasUnbound)));
+
+ }
+
+ @Test
+ void testFilter() {
+ String sql = "select * from t1 where t1.col1 = 1";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .nonMatch(any()
+ .when(e ->
e.getExpressions().stream().anyMatch(Expression::hasUnbound)));
+
+ }
+
+ @Test
+ void testSubquery() {
+ String sql = "select * from t1 where t1.col2 = (select sum(col2) from
t2)";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .nonMatch(any()
+ .when(e ->
e.getExpressions().stream().anyMatch(Expression::hasUnbound)));
+
+ }
+
+ @Test
+ void testFilterSort() {
+ String sql = "select * from t1 where t1.col2 = 1 order by col2";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .nonMatch(any()
+ .when(e ->
e.getExpressions().stream().anyMatch(Expression::hasUnbound)));
+ sql = "select * from t1 where t1.col2 = 1 order by col1";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .nonMatch(any()
+ .when(e ->
e.getExpressions().stream().anyMatch(Expression::hasUnbound)));
+
+ }
+
+ @Test
+ void testOneRealation() {
+ String sql = "select 1 + 2";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .nonMatch(any()
+ .when(e ->
e.getExpressions().stream().anyMatch(Expression::hasUnbound)));
+ }
+
+ @Test
+ void testSetOperation() {
+ String sql = "select * from t1 union all select * from t2";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .nonMatch(any()
+ .when(e ->
e.getExpressions().stream().anyMatch(Expression::hasUnbound)));
+ sql = "select * from t1 union select * from t2";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .nonMatch(any()
+ .when(e ->
e.getExpressions().stream().anyMatch(Expression::hasUnbound)));
+ sql = "select * from t1 intersect select * from t2";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .nonMatch(any()
+ .when(e ->
e.getExpressions().stream().anyMatch(Expression::hasUnbound)));
+ }
+
+ @Test
+ void testRepeat() {
+ String sql = "select repeat(\"a\", 3)";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .nonMatch(any()
+ .when(e ->
e.getExpressions().stream().anyMatch(Expression::hasUnbound)));
+ }
+
+ @Override
+ public RulePromise defaultPromise() {
+ return RulePromise.REWRITE;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]