Skip to content

Commit

Permalink
[Fix](Lateral View) Error view includes lateral view
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EmmyMiao87 committed May 12, 2022
1 parent d26f5d2 commit eb3bcf2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,26 +440,21 @@ 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void analyzeLimit(Analyzer analyzer) throws AnalysisException {
* (the statement is 'self-contained' with respect to correlation)
*/
public List<TupleId> getCorrelatedTupleIds(Analyzer analyzer)
throws AnalysisException {
throws AnalysisException {
// Correlated tuple ids of this stmt.
List<TupleId> correlatedTupleIds = Lists.newArrayList();
// First correlated and absolute table refs. Used for error detection/reporting.
Expand Down
26 changes: 13 additions & 13 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -627,20 +627,12 @@ public List<TupleId> 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<String> 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();
Expand All @@ -649,6 +641,14 @@ 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();
}
Expand Down

0 comments on commit eb3bcf2

Please sign in to comment.