Skip to content

Commit eb3bcf2

Browse files
committed
[Fix](Lateral View) Error view includes lateral view
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.
1 parent d26f5d2 commit eb3bcf2

3 files changed

Lines changed: 21 additions & 26 deletions

File tree

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -440,26 +440,21 @@ public QueryStmt getQueryStmt() {
440440
}
441441

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

452+
String aliasSql = null;
453+
String alias = getExplicitAlias();
454+
if (alias != null) aliasSql = ToSqlUtils.getIdentSql(alias);
458455
StringBuilder sb = new StringBuilder();
459-
sb.append("(")
460-
.append(queryStmt.toSql())
461-
.append(") ")
462-
.append(aliasSql);
456+
sb.append("(").append(queryStmt.toSql()).append(") ")
457+
.append(aliasSql);
463458

464459
return sb.toString();
465460
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private void analyzeLimit(Analyzer analyzer) throws AnalysisException {
207207
* (the statement is 'self-contained' with respect to correlation)
208208
*/
209209
public List<TupleId> getCorrelatedTupleIds(Analyzer analyzer)
210-
throws AnalysisException {
210+
throws AnalysisException {
211211
// Correlated tuple ids of this stmt.
212212
List<TupleId> correlatedTupleIds = Lists.newArrayList();
213213
// 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: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -627,20 +627,12 @@ public List<TupleId> getAllTableRefIds() {
627627
/**
628628
* Return the table ref presentation to be used in the toSql string
629629
*/
630+
// tbl1
631+
// tbl1 alias_tbl1
632+
// tbl1 alias_tbl1 lateral view explode_split(k1, ",") tmp1 as e1
633+
// (select xxx from xxx) t1 alias_tbl1 xxx
630634
public String tableRefToSql() {
631-
String aliasSql = null;
632-
String alias = getExplicitAlias();
633-
if (alias != null) aliasSql = ToSqlUtils.getIdentSql(alias);
634-
635-
// TODO(zc):
636-
// List<String> path = rawPath_;
637-
// if (resolvedPath_ != null) path = resolvedPath_.getFullyQualifiedRawPath();
638-
// return ToSqlUtils.getPathSql(path) + ((aliasSql != null) ? " " + aliasSql : "");
639-
640-
// tbl1
641-
// tbl1 alias_tbl1
642-
// tbl1 alias_tbl1 lateral view explode_split(k1, ",") tmp1 as e1
643-
String tblName = name.toSql() + ((aliasSql != null) ? " " + aliasSql : "");
635+
String tblName = tableNameToSql();
644636
if (lateralViewRefs != null) {
645637
for (LateralViewRef viewRef : lateralViewRefs) {
646638
tblName += " " + viewRef.toSql();
@@ -649,6 +641,14 @@ public String tableRefToSql() {
649641
return tblName;
650642
}
651643

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

0 commit comments

Comments
 (0)