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 2022/10/26 02:14:10 UTC

[doris] branch master updated: [fix](planner) inlineView alias error (#13600)

This is an automated email from the ASF dual-hosted git repository.

yiguolei 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 e5b33abd3c [fix](planner) inlineView alias error (#13600)
e5b33abd3c is described below

commit e5b33abd3c724ebbf1531c1bca1e8f31d56620f2
Author: minghong <mi...@163.com>
AuthorDate: Wed Oct 26 10:14:04 2022 +0800

    [fix](planner) inlineView alias error (#13600)
---
 .../java/org/apache/doris/analysis/Analyzer.java   | 24 ++++++-----
 .../org/apache/doris/analysis/InlineViewRef.java   |  3 ++
 .../correctness/test_pushdown_pred_to_view.groovy  |  2 +-
 .../suites/correctness/test_table_alias.groovy     | 47 ++++++++++++++++++++++
 4 files changed, 65 insertions(+), 11 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
index d3399be467..6777e3e0b2 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
@@ -152,18 +152,10 @@ public class Analyzer {
 
     // Flag indicating if this analyzer instance belongs to a subquery.
     private boolean isSubquery = false;
-
-    public boolean isInlineView() {
-        return isInlineView;
-    }
-
-    public void setInlineView(boolean inlineView) {
-        isInlineView = inlineView;
-    }
-
     // Flag indicating if this analyzer instance belongs to an inlineview.
     private boolean isInlineView = false;
 
+    private String explicitViewAlias;
     // Flag indicating whether this analyzer belongs to a WITH clause view.
     private boolean isWithClause = false;
 
@@ -519,6 +511,18 @@ public class Analyzer {
         return callDepth;
     }
 
+    public void setInlineView(boolean inlineView) {
+        isInlineView = inlineView;
+    }
+
+    public void setExplicitViewAlias(String alias) {
+        explicitViewAlias = alias;
+    }
+
+    public String getExplicitViewAlias() {
+        return explicitViewAlias;
+    }
+
     /**
      * Registers a local view definition with this analyzer. Throws an exception if a view
      * definition with the same alias has already been registered or if the number of
@@ -806,7 +810,7 @@ public class Analyzer {
             // ===================================================
             // Someone may concern that if t2 is not alias of t, this fix will cause incorrect resolve. In fact,
             // this does not happen, since we push t2.a in (1.2) down to this inline view, t2 must be alias of t.
-            if (d == null && isInlineView) {
+            if (d == null && isInlineView && newTblName.getTbl().equals(explicitViewAlias)) {
                 d = resolveColumnRef(colName);
             }
         }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/InlineViewRef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/InlineViewRef.java
index 8adc8047f0..cf7b459005 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/InlineViewRef.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/InlineViewRef.java
@@ -187,6 +187,9 @@ public class InlineViewRef extends TableRef {
         // Analyze the inline view query statement with its own analyzer
         inlineViewAnalyzer = new Analyzer(analyzer);
         inlineViewAnalyzer.setInlineView(true);
+        if (hasExplicitAlias) {
+            inlineViewAnalyzer.setExplicitViewAlias(aliases[0]);
+        }
         queryStmt.analyze(inlineViewAnalyzer);
         correlatedTupleIds.addAll(queryStmt.getCorrelatedTupleIds(inlineViewAnalyzer));
 
diff --git a/regression-test/suites/correctness/test_pushdown_pred_to_view.groovy b/regression-test/suites/correctness/test_pushdown_pred_to_view.groovy
index 2d5169f3a5..ed9d9ae3dd 100644
--- a/regression-test/suites/correctness/test_pushdown_pred_to_view.groovy
+++ b/regression-test/suites/correctness/test_pushdown_pred_to_view.groovy
@@ -54,7 +54,7 @@ The same resolve error occurs when re-analyze v2.
      """
 
      qt_sql """
-         select * from ${viewName} as v1 join ${viewName} as v2 on v1.id=v2.id and v1.id>0;
+         select * from ${viewName} as v1 join ${viewName} as v2 where v1.id=v2.id and v1.id>0;
      """
      sql "DROP VIEW ${viewName}"
      sql "DROP TABLE ${tableName}"
diff --git a/regression-test/suites/correctness/test_table_alias.groovy b/regression-test/suites/correctness/test_table_alias.groovy
new file mode 100644
index 0000000000..7c81a703d3
--- /dev/null
+++ b/regression-test/suites/correctness/test_table_alias.groovy
@@ -0,0 +1,47 @@
+// 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_table_alias") {
+     sql """ DROP TABLE IF EXISTS tbl_alias """
+     sql """
+         CREATE TABLE tbl_alias (
+             `id` int
+         ) ENGINE=OLAP
+         AGGREGATE KEY(`id`)
+         COMMENT "OLAP"
+         DISTRIBUTED BY HASH(`id`) BUCKETS 1
+         PROPERTIES (
+             "replication_allocation" = "tag.location.default: 1",
+             "in_memory" = "false",
+             "storage_format" = "V2"
+         );
+     """
+
+    try {
+        test {
+            sql """
+            select * 
+            from (select t3.id 
+                  from (select * from tbl_alias) t1
+                 ) t2
+            """
+            exception "errCode = 2, detailMessage = Unknown column 'id' in 't3'"            
+        }
+    } finally {
+        sql "drop table if exists tbl_alias"
+    }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org