This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push: new 3ae6488 [Syntax] Support CTE statement without use db (#4622) 3ae6488 is described below commit 3ae64884f8719d693a370b056a1a6f3cf8c7cf7d Author: xueyan.li <astrali...@163.com> AuthorDate: Sun Sep 20 20:56:11 2020 +0800 [Syntax] Support CTE statement without use db (#4622) --- .../main/java/org/apache/doris/analysis/SelectStmt.java | 14 ++++++++++++++ .../java/org/apache/doris/analysis/SelectStmtTest.java | 7 +++++++ .../test/java/org/apache/doris/utframe/DorisAssert.java | 5 +++++ 3 files changed, 26 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java index 90c9a87..2da1133 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java @@ -25,6 +25,7 @@ import org.apache.doris.catalog.FunctionSet; 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; @@ -289,6 +290,9 @@ public class SelectStmt extends QueryStmt { } 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); } @@ -313,6 +317,16 @@ public class SelectStmt extends QueryStmt { } } + 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; diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java index b46c3aa..d57fe5c 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java @@ -520,4 +520,11 @@ public class SelectStmtTest { 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(); + } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/utframe/DorisAssert.java b/fe/fe-core/src/test/java/org/apache/doris/utframe/DorisAssert.java index 4ec7c03..d3d8780 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/utframe/DorisAssert.java +++ b/fe/fe-core/src/test/java/org/apache/doris/utframe/DorisAssert.java @@ -73,6 +73,11 @@ public class DorisAssert { 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); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org