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
14 changes: 14 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.Table.TableType;
import org.apache.doris.catalog.Type;
import org.apache.doris.catalog.View;
import org.apache.doris.cluster.ClusterNamespace;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ColumnAliasGenerator;
Expand Down Expand Up @@ -289,6 +290,9 @@ public void getDbs(Analyzer analyzer, Map<String, Database> dbs) throws Analysis
} else {
dbName = ClusterNamespace.getFullName(analyzer.getClusterName(), tblRef.getName().getDb());
}
if(withClause_ != null && isViewTableRef(tblRef)){
continue;
}
if (Strings.isNullOrEmpty(dbName)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_DB_ERROR);
}
Expand All @@ -313,6 +317,16 @@ public void getDbs(Analyzer analyzer, Map<String, Database> dbs) throws Analysis
}
}

private boolean isViewTableRef(TableRef tblRef) {
List<View> views = withClause_.getViews();
for(View view : views){
if(view.getName().equals(tblRef.getName().toString())){
return true;
}
}
return false;
}

// Column alias generator used during query rewriting.
private ColumnAliasGenerator columnAliasGenerator = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,4 +520,11 @@ public void testSelectHintSetVar() throws Exception {
planner = dorisAssert.query(sql).internalExecuteOneAndGetPlan();
Assert.assertEquals(8589934592L, planner.getPlannerContext().getQueryOptions().mem_limit);
}

@Test
public void testWithWithoutDatabase() throws Exception {
String sql = "with tmp as (select count(*) from db1.table1) select * from tmp;";
dorisAssert.withoutUseDatabase();
dorisAssert.query(sql).explainQuery();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public DorisAssert useDatabase(String dbName) {
return this;
}

public DorisAssert withoutUseDatabase() {
ctx.setDatabase("");
return this;
}

public DorisAssert withTable(String sql) throws Exception {
CreateTableStmt createTableStmt = (CreateTableStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx);
Catalog.getCurrentCatalog().createTable(createTableStmt);
Expand Down