englefly commented on code in PR #23763: URL: https://github.com/apache/doris/pull/23763#discussion_r1313709470
########## fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java: ########## @@ -599,34 +600,75 @@ public LogicalPlan visitQuery(QueryContext ctx) { @Override public LogicalPlan visitSetOperation(SetOperationContext ctx) { return ParserUtils.withOrigin(ctx, () -> { - LogicalPlan leftQuery = plan(ctx.left); - LogicalPlan rightQuery = plan(ctx.right); - Qualifier qualifier; - if (ctx.setQuantifier() == null || ctx.setQuantifier().DISTINCT() != null) { - qualifier = Qualifier.DISTINCT; - } else { - qualifier = Qualifier.ALL; - } - - List<Plan> newChildren = new ImmutableList.Builder<Plan>() - .add(leftQuery) - .add(rightQuery) - .build(); - LogicalPlan plan; if (ctx.UNION() != null) { - plan = new LogicalUnion(qualifier, newChildren); - } else if (ctx.EXCEPT() != null) { - plan = new LogicalExcept(qualifier, newChildren); - } else if (ctx.INTERSECT() != null) { - plan = new LogicalIntersect(qualifier, newChildren); + Qualifier qualifier = getQualifier(ctx); + List<QueryTermContext> contexts = Lists.newArrayList(ctx.right); + QueryTermContext current = ctx.left; + while (true) { + if (current instanceof SetOperationContext + && getQualifier((SetOperationContext) current) == qualifier + && ((SetOperationContext) current).UNION() != null) { + contexts.add(((SetOperationContext) current).right); + current = ((SetOperationContext) current).left; + } else { + contexts.add(current); + break; + } + } + Collections.reverse(contexts); + List<LogicalPlan> logicalPlans = contexts.stream().map(this::plan).collect(Collectors.toList()); + return reduceToLogicalPlanTree(0, logicalPlans.size() - 1, logicalPlans, qualifier); } else { - throw new ParseException("not support", ctx); + LogicalPlan leftQuery = plan(ctx.left); + LogicalPlan rightQuery = plan(ctx.right); + Qualifier qualifier = getQualifier(ctx); + + List<Plan> newChildren = ImmutableList.of(leftQuery, rightQuery); + LogicalPlan plan; + if (ctx.UNION() != null) { + plan = new LogicalUnion(qualifier, newChildren); Review Comment: when ctx.union() != null, shall we go back to if branch? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org