This is an automated email from the ASF dual-hosted git repository.
kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 6dc5469c9f1 [fix](Nereids) should only do bind relation in view
analyzer #28637 (#28643)
6dc5469c9f1 is described below
commit 6dc5469c9f11b58e6e035f9bc4ab697ddac1af98
Author: morrySnow <[email protected]>
AuthorDate: Tue Dec 19 19:40:40 2023 +0800
[fix](Nereids) should only do bind relation in view analyzer #28637 (#28643)
---
.../org/apache/doris/nereids/CascadesContext.java | 12 ++-
.../doris/nereids/jobs/executor/Analyzer.java | 46 ++++++++--
.../doris/nereids/rules/analysis/BindRelation.java | 5 +-
.../nereids_rules_p0/bind_relation/bind_view.out | 5 ++
.../bind_relation/bind_view.groovy | 97 ++++++++++++++++++++++
5 files changed, 156 insertions(+), 9 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java
index 39edea95d20..6618393092a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java
@@ -203,11 +203,19 @@ public class CascadesContext implements ScheduleContext {
}
public Analyzer newAnalyzer() {
- return new Analyzer(this);
+ return newAnalyzer(false);
+ }
+
+ public Analyzer newAnalyzer(boolean analyzeView) {
+ return new Analyzer(this, analyzeView);
+ }
+
+ public Analyzer newAnalyzer(boolean analyzeView,
Optional<CustomTableResolver> customTableResolver) {
+ return new Analyzer(this, analyzeView, customTableResolver);
}
public Analyzer newAnalyzer(Optional<CustomTableResolver>
customTableResolver) {
- return new Analyzer(this, customTableResolver);
+ return newAnalyzer(false, customTableResolver);
}
@Override
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Analyzer.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Analyzer.java
index a4a8dd10988..82be7f61d66 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Analyzer.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Analyzer.java
@@ -50,6 +50,7 @@ import java.util.Optional;
public class Analyzer extends AbstractBatchJobExecutor {
public static final List<RewriteJob> DEFAULT_ANALYZE_JOBS =
buildAnalyzeJobs(Optional.empty());
+ public static final List<RewriteJob> DEFAULT_ANALYZE_VIEW_JOBS =
buildAnalyzeViewJobs(Optional.empty());
private final List<RewriteJob> jobs;
@@ -58,13 +59,37 @@ public class Analyzer extends AbstractBatchJobExecutor {
* @param cascadesContext planner context for execute job
*/
public Analyzer(CascadesContext cascadesContext) {
- this(cascadesContext, Optional.empty());
+ this(cascadesContext, false);
}
- public Analyzer(CascadesContext cascadesContext,
Optional<CustomTableResolver> customTableResolver) {
+ public Analyzer(CascadesContext cascadesContext, boolean analyzeView) {
+ this(cascadesContext, analyzeView, Optional.empty());
+ }
+
+ /**
+ * constructor of Analyzer. For view, we only do bind relation since other
analyze step will do by outer Analyzer.
+ *
+ * @param cascadesContext current context for analyzer
+ * @param analyzeView analyze view or user sql. If true, analyzer is used
for view.
+ * @param customTableResolver custom resolver for outer catalog.
+ */
+ public Analyzer(CascadesContext cascadesContext, boolean analyzeView,
+ Optional<CustomTableResolver> customTableResolver) {
super(cascadesContext);
Objects.requireNonNull(customTableResolver, "customTableResolver
cannot be null");
- this.jobs = !customTableResolver.isPresent() ? DEFAULT_ANALYZE_JOBS :
buildAnalyzeJobs(customTableResolver);
+ if (analyzeView) {
+ if (customTableResolver.isPresent()) {
+ this.jobs = buildAnalyzeViewJobs(customTableResolver);
+ } else {
+ this.jobs = DEFAULT_ANALYZE_VIEW_JOBS;
+ }
+ } else {
+ if (customTableResolver.isPresent()) {
+ this.jobs = buildAnalyzeJobs(customTableResolver);
+ } else {
+ this.jobs = DEFAULT_ANALYZE_JOBS;
+ }
+ }
}
@Override
@@ -79,15 +104,26 @@ public class Analyzer extends AbstractBatchJobExecutor {
execute();
}
+ private static List<RewriteJob>
buildAnalyzeViewJobs(Optional<CustomTableResolver> customTableResolver) {
+ return jobs(
+ topDown(new AnalyzeCTE()),
+ bottomUp(
+ new BindRelation(customTableResolver),
+ new CheckPolicy(),
+ new UserAuthentication()
+ )
+ );
+ }
+
private static List<RewriteJob>
buildAnalyzeJobs(Optional<CustomTableResolver> customTableResolver) {
return jobs(
topDown(new AnalyzeCTE()),
bottomUp(
new BindRelation(customTableResolver),
new CheckPolicy(),
- new UserAuthentication(),
- new BindExpression()
+ new UserAuthentication()
),
+ bottomUp(new BindExpression()),
topDown(new BindSink()),
bottomUp(new CheckAfterBind()),
bottomUp(
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java
index badefd91b3c..6980817db09 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java
@@ -45,6 +45,7 @@ import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.PreAggStatus;
+import org.apache.doris.nereids.trees.plans.algebra.Relation;
import org.apache.doris.nereids.trees.plans.logical.LogicalCTEConsumer;
import org.apache.doris.nereids.trees.plans.logical.LogicalEsScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalFileScan;
@@ -87,7 +88,7 @@ public class BindRelation extends OneAnalysisRuleFactory {
public Rule build() {
return unboundRelation().thenApply(ctx -> {
Plan plan = doBindRelation(ctx);
- if (!(plan instanceof Unbound)) {
+ if (!(plan instanceof Unbound) && plan instanceof Relation) {
// init output and allocate slot id immediately, so that the
slot id increase
// in the order in which the table appears.
LogicalProperties logicalProperties =
plan.getLogicalProperties();
@@ -253,7 +254,7 @@ public class BindRelation extends OneAnalysisRuleFactory {
}
CascadesContext viewContext = CascadesContext.initContext(
parentContext.getStatementContext(), parsedViewPlan,
PhysicalProperties.ANY);
- viewContext.newAnalyzer().analyze();
+ viewContext.newAnalyzer(true, customTableResolver).analyze();
// we should remove all group expression of the plan which in other
memo, so the groupId would not conflict
return viewContext.getRewritePlan();
}
diff --git a/regression-test/data/nereids_rules_p0/bind_relation/bind_view.out
b/regression-test/data/nereids_rules_p0/bind_relation/bind_view.out
new file mode 100644
index 00000000000..3084841a79c
--- /dev/null
+++ b/regression-test/data/nereids_rules_p0/bind_relation/bind_view.out
@@ -0,0 +1,5 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !select_view --
+20231214 1 A 2 1 120.000000000000
70.000000000000 3.0 11.1110000000
+20231214 1 B 9 8 290.000000000000
260.000000000000 10.615384615384615 12.6151153846
+
diff --git
a/regression-test/suites/nereids_rules_p0/bind_relation/bind_view.groovy
b/regression-test/suites/nereids_rules_p0/bind_relation/bind_view.groovy
new file mode 100644
index 00000000000..f3f7641b732
--- /dev/null
+++ b/regression-test/suites/nereids_rules_p0/bind_relation/bind_view.groovy
@@ -0,0 +1,97 @@
+// 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.
+
+suite("test_bind_view") {
+ sql "SET enable_nereids_planner=true"
+ sql "SET enable_fallback_to_original_planner=false"
+
+ def table_name = "base_table"
+ def view_name = "decimal_view"
+
+ sql """
+ DROP TABLE IF EXISTS ${table_name};
+ """
+ sql """
+ DROP VIEW IF EXISTS ${view_name};
+ """
+
+ sql """
+ CREATE TABLE IF NOT EXISTS ${table_name}
+ (
+ `c1` varchar(255),
+ `c2` TINYINT,
+ `c3` varchar(65533),
+ `c4` varchar(255),
+ `c5` varchar(255),
+ `c6` DECIMAL(26,8),
+ `c7` varchar(255),
+ `c8` DECIMAL(35,8)
+ )
+ DUPLICATE KEY(`c1`)
+ DISTRIBUTED BY HASH(`c1`) BUCKETS 1
+ PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1"
+ );
+ """
+
+ try {
+
+ sql """
+ create view ${view_name} AS
+ SELECT
+ substr(c1,1,8) c1
+ ,c2 c2
+ ,c3 c3
+ ,count(c4) c4
+ ,count(CASE WHEN c5='PA' THEN c4 end) c5
+ ,sum(c6 / 100) c6
+ ,sum(CASE WHEN c5='PA' THEN c6/100 end) c7
+ ,sum(CASE WHEN c5 = 'PA' THEN c6 * c7 END) / sum(CASE WHEN c5
= 'PA' THEN c6 end) c8
+ ,sum(CASE WHEN c5 = 'PA' THEN c6 * c8 END) / sum(CASE WHEN c5
= 'PA' THEN c6 END) c9
+ FROM ${table_name}
+ GROUP BY 1,2,3
+ ORDER BY 1,2,3;
+ """
+
+ sql """
+ INSERT INTO ${table_name} values
+ ('20231214142039',1,'B','12312872384723','PA',3000,'12',11.111)
+
,('20231214132039',1,'B','12312872384723','PA',4000,'12',12.222)
+
,('20231214142239',1,'B','12312872384723','PA',3000,'12',13.333)
+ ,('20231214162339',1,'B','12312872384723','PA',4000,'3',11.111)
+
,('20231214152139',1,'B','12312872384723','RJ',3000,'12',11.111)
+ ,('20231214152339',1,'A','12312872384723','RJ',5000,'3',11.111)
+
,('20231214162139',1,'B','12312872384723','PA',5000,'12',13.444)
+
,('20231214132439',1,'B','12312872384723','PA',3000,'12',12.111)
+ ,('20231214162039',1,'A','12312872384723','PA',7000,'3',11.111)
+
,('20231214142039',1,'B','12312872384723','PA',1000,'12',11.111)
+
,('20231214142039',1,'B','12312872384723','PA',3000,'12',15.555);
+ """
+
+ order_qt_select_view """
+ select * from ${view_name}
+ """
+ } finally {
+ sql """
+ DROP VIEW IF EXISTS ${view_name};
+ """
+ sql """
+ DROP TABLE IF EXISTS ${table_name};
+ """
+
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]