Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](planner) inlineView alias error #13600

Merged
merged 3 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,10 @@ public class Analyzer {

// Flag indicating if this analyzer instance belongs to a subquery.
private boolean isSubquery = false;

public boolean isInlineView() {
return isInlineView;
}

public void setInlineView(boolean inlineView) {
isInlineView = inlineView;
}

// Flag indicating if this analyzer instance belongs to an inlineview.
private boolean isInlineView = false;

private String explicitViewAlias;
// Flag indicating whether this analyzer belongs to a WITH clause view.
private boolean isWithClause = false;

Expand Down Expand Up @@ -519,6 +511,18 @@ public int getCallDepth() {
return callDepth;
}

public void setInlineView(boolean inlineView) {
isInlineView = inlineView;
}

public void setExplicitViewAlias(String alias) {
explicitViewAlias = alias;
}

public String getExplicitViewAlias() {
return explicitViewAlias;
}

/**
* Registers a local view definition with this analyzer. Throws an exception if a view
* definition with the same alias has already been registered or if the number of
Expand Down Expand Up @@ -806,7 +810,7 @@ public SlotDescriptor registerColumnRef(TableName tblName, String colName) throw
// ===================================================
// Someone may concern that if t2 is not alias of t, this fix will cause incorrect resolve. In fact,
// this does not happen, since we push t2.a in (1.2) down to this inline view, t2 must be alias of t.
if (d == null && isInlineView) {
if (d == null && isInlineView && newTblName.getTbl().equals(explicitViewAlias)) {
d = resolveColumnRef(colName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
// Analyze the inline view query statement with its own analyzer
inlineViewAnalyzer = new Analyzer(analyzer);
inlineViewAnalyzer.setInlineView(true);
if (hasExplicitAlias) {
inlineViewAnalyzer.setExplicitViewAlias(aliases[0]);
}
queryStmt.analyze(inlineViewAnalyzer);
correlatedTupleIds.addAll(queryStmt.getCorrelatedTupleIds(inlineViewAnalyzer));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The same resolve error occurs when re-analyze v2.
"""

qt_sql """
select * from ${viewName} as v1 join ${viewName} as v2 on v1.id=v2.id and v1.id>0;
select * from ${viewName} as v1 join ${viewName} as v2 where v1.id=v2.id and v1.id>0;
englefly marked this conversation as resolved.
Show resolved Hide resolved
"""
sql "DROP VIEW ${viewName}"
sql "DROP TABLE ${tableName}"
Expand Down