Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.UserException;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;

Expand All @@ -42,7 +43,8 @@ public MVRefreshInfo getRefreshInfo() {
}

@Override
public void analyze(Analyzer analyzer) throws AnalysisException {
public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
super.analyze(analyzer);
mvName.analyze(analyzer);
if (!Env.getCurrentEnv().getAccessManager().checkTblPriv(ConnectContext.get(), mvName.getDb(), mvName.getTbl(),
PrivPredicate.ALTER)) {
Expand Down
12 changes: 12 additions & 0 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 @@ -320,6 +320,10 @@ private static class GlobalState {
// analysis.
public boolean isExplain;

// Record the statement clazz that the analyzer would to analyze,
// this give an opportunity to control analyzing behavior according to the statement type.
public Class<? extends StatementBase> rootStatementClazz;

// Indicates whether the query has plan hints.
public boolean hasPlanHints = false;

Expand Down Expand Up @@ -568,6 +572,14 @@ public boolean isExplain() {
return globalState.isExplain;
}

public void setRootStatementClazz(Class<? extends StatementBase> statementClazz) {
globalState.rootStatementClazz = statementClazz;
}

public Class<? extends StatementBase> getRootStatementClazz() {
return globalState.rootStatementClazz;
}

public int incrementCallDepth() {
return ++callDepth;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void analyze(Analyzer analyzer) throws UserException {
// To avoid duplicate registrations of table/colRefs,
// create a new root analyzer and clone the query statement for this initial pass.
Analyzer dummyRootAnalyzer = new Analyzer(analyzer.getEnv(), analyzer.getContext());
super.analyze(dummyRootAnalyzer);
QueryStmt tmpStmt = queryStmt.clone();
tmpStmt.analyze(dummyRootAnalyzer);
this.queryStmt = tmpStmt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public String getComment() {

@Override
public void analyze(Analyzer analyzer) throws UserException {
super.analyze(analyzer);
tableName.analyze(analyzer);
FeNameFormat.checkTableName(tableName.getTbl());
viewDefStmt.setNeedToSql(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public String toDigest() {
* Return a column label for the select list item. Without generate column name
* automatically.
*/
@Deprecated
public String toColumnLabel() {
Preconditions.checkState(!isStar());
if (alias != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,17 @@ public void analyze(Analyzer analyzer) throws UserException {
throw new AnalysisException("Subquery is not supported in the select list.");
}
resultExprs.add(rewriteQueryExprByMvColumnExpr(item.getExpr(), analyzer));
String columnLabel = item.toColumnLabel(i);
String columnLabel = null;
Class<? extends StatementBase> statementClazz = analyzer.getRootStatementClazz();
if (statementClazz != null && !QueryStmt.class.isAssignableFrom(statementClazz)) {
// Infer column name when item is expr
columnLabel = item.toColumnLabel(i);
}
if (columnLabel == null) {
// column label without position is applicative for query and do not infer
// column name when item is expr
columnLabel = item.toColumnLabel();
}
SlotRef aliasRef = new SlotRef(null, columnLabel);
Expr existingAliasExpr = aliasSMap.get(aliasRef);
if (existingAliasExpr != null && !existingAliasExpr.equals(item.getExpr())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ protected StatementBase(StatementBase other) {
* were missing from the catalog.
* It is up to the analysis() implementation to ensure the maximum number of missing
* tables/views get collected in the Analyzer before failing analyze().
* Should call the method firstly when override the method, the analyzer param should be
* the one which statement would use.
*/
public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
if (isAnalyzed()) {
return;
}
this.analyzer = analyzer;
if (analyzer.getRootStatementClazz() == null) {
analyzer.setRootStatementClazz(this.getClass());
}
if (Strings.isNullOrEmpty(analyzer.getClusterName())) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_CLUSTER_NO_SELECT_CLUSTER);
}
Expand Down
Loading