This is an automated email from the ASF dual-hosted git repository. morrysnow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 897151fc2b [fix](Nereids) set operation syntax is not compatible with legacy planner (#23668) 897151fc2b is described below commit 897151fc2ba1b2c278d0e3e643b1e944918cced7 Author: morrySnow <101034200+morrys...@users.noreply.github.com> AuthorDate: Thu Aug 31 11:55:35 2023 +0800 [fix](Nereids) set operation syntax is not compatible with legacy planner (#23668) for example ```sql WITH A AS (SELECT * FROM B) SELECT * FROM C UNION SELECT * FROM D ``` the scope of CTE in Nereids is the first set oeprand. the scope of CTE in legacy planner is the whole statement. --- .../antlr4/org/apache/doris/nereids/DorisParser.g4 | 24 ++++++++++------------ .../doris/nereids/parser/LogicalPlanBuilder.java | 1 - .../rules/expression/rules/FunctionBinder.java | 3 +-- .../suites/nereids_syntax_p0/cte.groovy | 1 + 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 index 7dc1554ce1..ee8757f8e3 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 @@ -118,14 +118,13 @@ outFileClause ; query - : {!doris_legacy_SQL_syntax}? cte? queryTerm queryOrganization - | {doris_legacy_SQL_syntax}? queryTerm queryOrganization + : cte? queryTerm queryOrganization ; queryTerm - : queryPrimary #queryTermDefault + : queryPrimary #queryTermDefault | left=queryTerm operator=(UNION | EXCEPT | INTERSECT) - setQuantifier? right=queryTerm #setOperation + setQuantifier? right=queryTerm #setOperation ; setQuantifier @@ -134,19 +133,17 @@ setQuantifier ; queryPrimary - : querySpecification #queryPrimaryDefault - | TABLE multipartIdentifier #table - | LEFT_PAREN query RIGHT_PAREN #subquery + : querySpecification #queryPrimaryDefault + | LEFT_PAREN query RIGHT_PAREN #subquery ; querySpecification - : {doris_legacy_SQL_syntax}? cte? - selectClause + : selectClause fromClause? whereClause? aggClause? havingClause? - {doris_legacy_SQL_syntax}? queryOrganization #regularQuerySpecification + {doris_legacy_SQL_syntax}? queryOrganization #regularQuerySpecification ; cte @@ -287,11 +284,12 @@ identifierSeq ; relationPrimary - : multipartIdentifier specifiedPartition? tabletList? tableAlias relationHint? lateralView* #tableName - | LEFT_PAREN query RIGHT_PAREN tableAlias lateralView* #aliasedQuery + : multipartIdentifier specifiedPartition? + tabletList? tableAlias relationHint? lateralView* #tableName + | LEFT_PAREN query RIGHT_PAREN tableAlias lateralView* #aliasedQuery | tvfName=identifier LEFT_PAREN (properties=propertyItemList)? - RIGHT_PAREN tableAlias #tableValuedFunction + RIGHT_PAREN tableAlias #tableValuedFunction ; propertyClause diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index a0c6c09925..bf966f574f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -631,7 +631,6 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> { ); } selectPlan = withQueryOrganization(selectPlan, ctx.queryOrganization()); - selectPlan = withCte(selectPlan, ctx.cte()); return withSelectHint(selectPlan, selectCtx.selectHint()); }); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FunctionBinder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FunctionBinder.java index e049254368..cd9c16dd87 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FunctionBinder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FunctionBinder.java @@ -119,8 +119,7 @@ public class FunctionBinder extends AbstractExpressionRewriteRule { @Override public Expression visitBoundFunction(BoundFunction boundFunction, ExpressionRewriteContext context) { - boundFunction = (BoundFunction) boundFunction.withChildren(boundFunction.children().stream() - .map(e -> e.accept(this, context)).collect(Collectors.toList())); + boundFunction = (BoundFunction) super.visitBoundFunction(boundFunction, context); return TypeCoercionUtils.processBoundFunction(boundFunction); } diff --git a/regression-test/suites/nereids_syntax_p0/cte.groovy b/regression-test/suites/nereids_syntax_p0/cte.groovy index 15a7afc955..457ecc2801 100644 --- a/regression-test/suites/nereids_syntax_p0/cte.groovy +++ b/regression-test/suites/nereids_syntax_p0/cte.groovy @@ -306,5 +306,6 @@ suite("cte") { notContains "MultiCastDataSinks" } + sql "WITH cte_0 AS ( SELECT 1 AS a ) SELECT * from cte_0 t1 LIMIT 10 UNION SELECT * from cte_0 t1 LIMIT 10" } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org