Skip to content

Commit f68f76a

Browse files
EmmyMiao87weizhengte
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 a31a208 commit f68f76a

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
@@ -626,20 +626,12 @@ public List<TupleId> getAllTableRefIds() {
626626
/**
627627
* Return the table ref presentation to be used in the toSql string
628628
*/
629+
// tbl1
630+
// tbl1 alias_tbl1
631+
// tbl1 alias_tbl1 lateral view explode_split(k1, ",") tmp1 as e1
632+
// (select xxx from xxx) t1 alias_tbl1 xxx
629633
public String tableRefToSql() {
630-
String aliasSql = null;
631-
String alias = getExplicitAlias();
632-
if (alias != null) aliasSql = ToSqlUtils.getIdentSql(alias);
633-
634-
// TODO(zc):
635-
// List<String> path = rawPath_;
636-
// if (resolvedPath_ != null) path = resolvedPath_.getFullyQualifiedRawPath();
637-
// return ToSqlUtils.getPathSql(path) + ((aliasSql != null) ? " " + aliasSql : "");
638-
639-
// tbl1
640-
// tbl1 alias_tbl1
641-
// tbl1 alias_tbl1 lateral view explode_split(k1, ",") tmp1 as e1
642-
String tblName = name.toSql() + ((aliasSql != null) ? " " + aliasSql : "");
634+
String tblName = tableNameToSql();
643635
if (lateralViewRefs != null) {
644636
for (LateralViewRef viewRef : lateralViewRefs) {
645637
tblName += " " + viewRef.toSql();
@@ -648,6 +640,16 @@ public String tableRefToSql() {
648640
return tblName;
649641
}
650642

643+
protected String tableNameToSql() {
644+
String aliasSql = null;
645+
String alias = getExplicitAlias();
646+
if (alias != null) {
647+
aliasSql = ToSqlUtils.getIdentSql(alias);
648+
}
649+
String tblName = name.toSql() + ((aliasSql != null) ? " " + aliasSql : "");
650+
return tblName;
651+
}
652+
651653
public String tableRefToDigest() {
652654
return tableRefToSql();
653655
}

0 commit comments

Comments
 (0)