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 da1195f58ffe3c..f576f02bd8fde9 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 @@ -439,26 +439,23 @@ public QueryStmt getQueryStmt() { } @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 676380bbb9dc1f..c6fc843b7c50f4 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 @@ -205,8 +205,7 @@ private void analyzeLimit(Analyzer analyzer) throws AnalysisException { * (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 getCorrelatedTupleIds(Analyzer analyzer) - throws AnalysisException { + public List getCorrelatedTupleIds(Analyzer analyzer) throws AnalysisException { // Correlated tuple ids of this stmt. List 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 0160aedb41fdde..0102115a0893ec 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 @@ -631,20 +631,12 @@ public List getAllTableRefIds() { /** * 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 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(); @@ -653,6 +645,16 @@ public String tableRefToSql() { 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; + } + public String tableRefToDigest() { return tableRefToSql(); }