[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.
This commit is contained in:
@ -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
|
||||
|
||||
@ -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());
|
||||
});
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user