Skip to content
Permalink
Browse files
[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.
  • Loading branch information
EmmyMiao87 committed May 14, 2022
1 parent fa6e4db commit a9653f00bb7ea7a0d3d03bd4cea44e3ca0fc6aa4
Showing 3 changed files with 25 additions and 27 deletions.
@@ -439,26 +439,23 @@ 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();
}
@@ -205,8 +205,7 @@ private void analyzeLimit(Analyzer analyzer) throws AnalysisException {
* (3) a mix of correlated table refs and table refs rooted at those refs
* (the statement is 'self-contained' with respect to correlation)
*/
public List<TupleId> getCorrelatedTupleIds(Analyzer analyzer)
throws AnalysisException {
public List<TupleId> getCorrelatedTupleIds(Analyzer analyzer) throws AnalysisException {
// Correlated tuple ids of this stmt.
List<TupleId> correlatedTupleIds = Lists.newArrayList();
// First correlated and absolute table refs. Used for error detection/reporting.
@@ -626,20 +626,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();
@@ -648,6 +640,16 @@ 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();
}

0 comments on commit a9653f0

Please sign in to comment.