Skip to content

Commit ebe6865

Browse files
EmmyMiao87starocean999
authored andcommitted
[fix](lateral-view) Error view includes lateral view (apache#9530)
Fixed apache#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.
1 parent 26f6c7e commit ebe6865

3 files changed

Lines changed: 25 additions & 27 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/analysis/InlineViewRef.java‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -439,26 +439,23 @@ public QueryStmt getQueryStmt() {
439439
}
440440

441441
@Override
442-
public String tableRefToSql() {
442+
public String tableNameToSql() {
443443
// Enclose the alias in quotes if Hive cannot parse it without quotes.
444444
// This is needed for view compatibility between Impala and Hive.
445-
String aliasSql = null;
446-
String alias = getExplicitAlias();
447-
if (alias != null) {
448-
aliasSql = ToSqlUtils.getIdentSql(alias);
449-
}
450-
451445
if (view != null) {
452446
// FIXME: this may result in a sql cache problem
453447
// See pr #6736 and issue #6735
454-
return name.toSql() + (aliasSql == null ? "" : " " + aliasSql);
448+
return super.tableNameToSql();
455449
}
456450

451+
String aliasSql = null;
452+
String alias = getExplicitAlias();
453+
if (alias != null) {
454+
aliasSql = ToSqlUtils.getIdentSql(alias);
455+
}
457456
StringBuilder sb = new StringBuilder();
458-
sb.append("(")
459-
.append(queryStmt.toSql())
460-
.append(") ")
461-
.append(aliasSql);
457+
sb.append("(").append(queryStmt.toSql()).append(") ")
458+
.append(aliasSql);
462459

463460
return sb.toString();
464461
}

‎fe/fe-core/src/main/java/org/apache/doris/analysis/QueryStmt.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ private void analyzeLimit(Analyzer analyzer) throws AnalysisException {
205205
* (3) a mix of correlated table refs and table refs rooted at those refs
206206
* (the statement is 'self-contained' with respect to correlation)
207207
*/
208-
public List<TupleId> getCorrelatedTupleIds(Analyzer analyzer)
209-
throws AnalysisException {
208+
public List<TupleId> getCorrelatedTupleIds(Analyzer analyzer) throws AnalysisException {
210209
// Correlated tuple ids of this stmt.
211210
List<TupleId> correlatedTupleIds = Lists.newArrayList();
212211
// First correlated and absolute table refs. Used for error detection/reporting.

‎fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -631,20 +631,12 @@ public List<TupleId> getAllTableRefIds() {
631631
/**
632632
* Return the table ref presentation to be used in the toSql string
633633
*/
634+
// tbl1
635+
// tbl1 alias_tbl1
636+
// tbl1 alias_tbl1 lateral view explode_split(k1, ",") tmp1 as e1
637+
// (select xxx from xxx) t1 alias_tbl1 xxx
634638
public String tableRefToSql() {
635-
String aliasSql = null;
636-
String alias = getExplicitAlias();
637-
if (alias != null) aliasSql = ToSqlUtils.getIdentSql(alias);
638-
639-
// TODO(zc):
640-
// List<String> path = rawPath_;
641-
// if (resolvedPath_ != null) path = resolvedPath_.getFullyQualifiedRawPath();
642-
// return ToSqlUtils.getPathSql(path) + ((aliasSql != null) ? " " + aliasSql : "");
643-
644-
// tbl1
645-
// tbl1 alias_tbl1
646-
// tbl1 alias_tbl1 lateral view explode_split(k1, ",") tmp1 as e1
647-
String tblName = name.toSql() + ((aliasSql != null) ? " " + aliasSql : "");
639+
String tblName = tableNameToSql();
648640
if (lateralViewRefs != null) {
649641
for (LateralViewRef viewRef : lateralViewRefs) {
650642
tblName += " " + viewRef.toSql();
@@ -653,6 +645,16 @@ public String tableRefToSql() {
653645
return tblName;
654646
}
655647

648+
protected String tableNameToSql() {
649+
String aliasSql = null;
650+
String alias = getExplicitAlias();
651+
if (alias != null) {
652+
aliasSql = ToSqlUtils.getIdentSql(alias);
653+
}
654+
String tblName = name.toSql() + ((aliasSql != null) ? " " + aliasSql : "");
655+
return tblName;
656+
}
657+
656658
public String tableRefToDigest() {
657659
return tableRefToSql();
658660
}

0 commit comments

Comments
 (0)