You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2022/05/16 16:39:25 UTC

[incubator-doris] 15/17: [fix](lateral-view) Error view includes lateral view (#9530)

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

morningman pushed a commit to branch dev-1.0.1
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git

commit 7f12cfe240cc6bed73ca46b93c106f09c6a48917
Author: EmmyMiao87 <52...@qq.com>
AuthorDate: Sat May 14 09:57:08 2022 +0800

    [fix](lateral-view) Error view includes lateral view (#9530)
    
    Fixed #9529
    
    When the lateral view based on a inline view which belongs to a view,
    Doris could not resolve the column of lateral view in query.
    When a query uses a view, it mainly refers to the string representation of the view.
    That is, if the view's string representation is wrong, the view is wrong.
    The string representation of the inline view lacks the handling of the lateral view.
    This leads to query errors when using such views.
    This PR mainly fixes the string representation of inline views.
---
 .../org/apache/doris/analysis/InlineViewRef.java   | 21 +++++++---------
 .../java/org/apache/doris/analysis/QueryStmt.java  |  3 +--
 .../java/org/apache/doris/analysis/TableRef.java   | 28 ++++++++++++----------
 3 files changed, 25 insertions(+), 27 deletions(-)

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 8df63b4492..a8ae56b61c 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
@@ -437,26 +437,23 @@ public class InlineViewRef extends TableRef {
     }
 
     @Override
-    public String tableRefToSql() {
+    public String tableNameToSql() {
         // Enclose the alias in quotes if Hive cannot parse it without quotes.
         // This is needed for view compatibility between Impala and Hive.
-        String aliasSql = null;
-        String alias = getExplicitAlias();
-        if (alias != null) {
-            aliasSql = ToSqlUtils.getIdentSql(alias);
-        }
-
         if (view != null) {
             // FIXME: this may result in a sql cache problem
             // See pr #6736 and issue #6735
-            return name.toSql() + (aliasSql == null ? "" : " " + aliasSql);
+            return super.tableNameToSql();
         }
 
+        String aliasSql = null;
+        String alias = getExplicitAlias();
+        if (alias != null) {
+            aliasSql = ToSqlUtils.getIdentSql(alias);
+        }
         StringBuilder sb = new StringBuilder();
-        sb.append("(")
-                .append(queryStmt.toSql())
-                .append(") ")
-                .append(aliasSql);
+        sb.append("(").append(queryStmt.toSql()).append(") ")
+            .append(aliasSql);
 
         return sb.toString();
     }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/QueryStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/QueryStmt.java
index 4888ab7566..1617ec4aeb 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/QueryStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/QueryStmt.java
@@ -203,8 +203,7 @@ public abstract class QueryStmt extends StatementBase {
      * (3) a mix of correlated table refs and table refs rooted at those refs
      *     (the statement is 'self-contained' with respect to correlation)
      */
-    public List<TupleId> getCorrelatedTupleIds(Analyzer analyzer)
-            throws AnalysisException {
+    public List<TupleId> getCorrelatedTupleIds(Analyzer analyzer) throws AnalysisException {
         // Correlated tuple ids of this stmt.
         List<TupleId> correlatedTupleIds = Lists.newArrayList();
         // First correlated and absolute table refs. Used for error detection/reporting.
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java
index a911d27227..d78aac9c46 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java
@@ -624,20 +624,12 @@ public class TableRef implements ParseNode, Writable {
     /**
      * Return the table ref presentation to be used in the toSql string
      */
+    // tbl1
+    // tbl1 alias_tbl1
+    // tbl1 alias_tbl1 lateral view explode_split(k1, ",") tmp1 as e1
+    // (select xxx from xxx) t1 alias_tbl1 xxx
     public String tableRefToSql() {
-        String aliasSql = null;
-        String alias = getExplicitAlias();
-        if (alias != null) aliasSql = ToSqlUtils.getIdentSql(alias);
-
-        // TODO(zc):
-        // List<String> path = rawPath_;
-        // if (resolvedPath_ != null) path = resolvedPath_.getFullyQualifiedRawPath();
-        // return ToSqlUtils.getPathSql(path) + ((aliasSql != null) ? " " + aliasSql : "");
-
-        // tbl1
-        // tbl1 alias_tbl1
-        // tbl1 alias_tbl1 lateral view explode_split(k1, ",") tmp1 as e1
-        String tblName = name.toSql() + ((aliasSql != null) ? " " + aliasSql : "");
+        String tblName = tableNameToSql();
         if (lateralViewRefs != null) {
             for (LateralViewRef viewRef : lateralViewRefs) {
                 tblName += " " + viewRef.toSql();
@@ -646,6 +638,16 @@ public class TableRef implements ParseNode, Writable {
         return tblName;
     }
 
+    protected String tableNameToSql() {
+        String aliasSql = null;
+        String alias = getExplicitAlias();
+        if (alias != null) {
+            aliasSql = ToSqlUtils.getIdentSql(alias);
+        }
+        String tblName = name.toSql() + ((aliasSql != null) ? " " + aliasSql : "");
+        return tblName;
+    }
+
     @Override
     public String toSql() {
         if (joinOp == null) {


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