Skip to content

Commit 7f12cfe

Browse files
EmmyMiao87morningman
authored andcommitted
[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.
1 parent ff4f4a3 commit 7f12cfe

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
@@ -437,26 +437,23 @@ public QueryStmt getQueryStmt() {
437437
}
438438

439439
@Override
440-
public String tableRefToSql() {
440+
public String tableNameToSql() {
441441
// Enclose the alias in quotes if Hive cannot parse it without quotes.
442442
// This is needed for view compatibility between Impala and Hive.
443-
String aliasSql = null;
444-
String alias = getExplicitAlias();
445-
if (alias != null) {
446-
aliasSql = ToSqlUtils.getIdentSql(alias);
447-
}
448-
449443
if (view != null) {
450444
// FIXME: this may result in a sql cache problem
451445
// See pr #6736 and issue #6735
452-
return name.toSql() + (aliasSql == null ? "" : " " + aliasSql);
446+
return super.tableNameToSql();
453447
}
454448

449+
String aliasSql = null;
450+
String alias = getExplicitAlias();
451+
if (alias != null) {
452+
aliasSql = ToSqlUtils.getIdentSql(alias);
453+
}
455454
StringBuilder sb = new StringBuilder();
456-
sb.append("(")
457-
.append(queryStmt.toSql())
458-
.append(") ")
459-
.append(aliasSql);
455+
sb.append("(").append(queryStmt.toSql()).append(") ")
456+
.append(aliasSql);
460457

461458
return sb.toString();
462459
}

‎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
@@ -203,8 +203,7 @@ private void analyzeLimit(Analyzer analyzer) throws AnalysisException {
203203
* (3) a mix of correlated table refs and table refs rooted at those refs
204204
* (the statement is 'self-contained' with respect to correlation)
205205
*/
206-
public List<TupleId> getCorrelatedTupleIds(Analyzer analyzer)
207-
throws AnalysisException {
206+
public List<TupleId> getCorrelatedTupleIds(Analyzer analyzer) throws AnalysisException {
208207
// Correlated tuple ids of this stmt.
209208
List<TupleId> correlatedTupleIds = Lists.newArrayList();
210209
// 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
@@ -624,20 +624,12 @@ public List<TupleId> getAllTableRefIds() {
624624
/**
625625
* Return the table ref presentation to be used in the toSql string
626626
*/
627+
// tbl1
628+
// tbl1 alias_tbl1
629+
// tbl1 alias_tbl1 lateral view explode_split(k1, ",") tmp1 as e1
630+
// (select xxx from xxx) t1 alias_tbl1 xxx
627631
public String tableRefToSql() {
628-
String aliasSql = null;
629-
String alias = getExplicitAlias();
630-
if (alias != null) aliasSql = ToSqlUtils.getIdentSql(alias);
631-
632-
// TODO(zc):
633-
// List<String> path = rawPath_;
634-
// if (resolvedPath_ != null) path = resolvedPath_.getFullyQualifiedRawPath();
635-
// return ToSqlUtils.getPathSql(path) + ((aliasSql != null) ? " " + aliasSql : "");
636-
637-
// tbl1
638-
// tbl1 alias_tbl1
639-
// tbl1 alias_tbl1 lateral view explode_split(k1, ",") tmp1 as e1
640-
String tblName = name.toSql() + ((aliasSql != null) ? " " + aliasSql : "");
632+
String tblName = tableNameToSql();
641633
if (lateralViewRefs != null) {
642634
for (LateralViewRef viewRef : lateralViewRefs) {
643635
tblName += " " + viewRef.toSql();
@@ -646,6 +638,16 @@ public String tableRefToSql() {
646638
return tblName;
647639
}
648640

641+
protected String tableNameToSql() {
642+
String aliasSql = null;
643+
String alias = getExplicitAlias();
644+
if (alias != null) {
645+
aliasSql = ToSqlUtils.getIdentSql(alias);
646+
}
647+
String tblName = name.toSql() + ((aliasSql != null) ? " " + aliasSql : "");
648+
return tblName;
649+
}
650+
649651
@Override
650652
public String toSql() {
651653
if (joinOp == null) {

0 commit comments

Comments
 (0)