924060929 commented on code in PR #11209: URL: https://github.com/apache/doris/pull/11209#discussion_r932170082
########## fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java: ########## @@ -532,13 +534,23 @@ public List<Expression> visitNamedExpressionSeq(NamedExpressionSeqContext namedC * @return List of OrderKey */ @Override - public List<OrderKey> visitQueryOrganization(QueryOrganizationContext ctx) { + public QueryOrganization visitQueryOrganization(QueryOrganizationContext ctx) { return ParserUtils.withOrigin(ctx, () -> { + List<OrderKey> orderKeys; if (ctx.sortClause().ORDER() != null) { - return visit(ctx.sortClause().sortItem(), OrderKey.class); + orderKeys = visit(ctx.sortClause().sortItem(), OrderKey.class); } else { - return ImmutableList.of(); + orderKeys = ImmutableList.of(); } + long limit = Long.MAX_VALUE; Review Comment: the limitClause definition above can ensure this limit must has a value. If you keep the definition as before, I think this limit should be `Optional.empty()` and return originPlan without wrap a QueryOrganization. ########## fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4: ########## @@ -119,6 +119,12 @@ sortItem : expression ordering = (ASC | DESC)? ; +limitClause + : (LIMIT limit=INTEGER_VALUE)? + | (LIMIT limit=INTEGER_VALUE OFFSET offset=INTEGER_VALUE)? + | (LIMIT offset=INTEGER_VALUE COMMA limit=INTEGER_VALUE)? + ; Review Comment: why not set sortClause and limitClause to optional? ```antlr4 queryOrganization : sortClause? limitClause? ; sortItem : expression ordering = (ASC | DESC) ; limitClause : (LIMIT limit=INTEGER_VALUE) | (LIMIT limit=INTEGER_VALUE OFFSET offset=INTEGER_VALUE) | (LIMIT offset=INTEGER_VALUE COMMA limit=INTEGER_VALUE) ; ``` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java: ########## @@ -532,13 +534,23 @@ public List<Expression> visitNamedExpressionSeq(NamedExpressionSeqContext namedC * @return List of OrderKey */ @Override - public List<OrderKey> visitQueryOrganization(QueryOrganizationContext ctx) { + public QueryOrganization visitQueryOrganization(QueryOrganizationContext ctx) { return ParserUtils.withOrigin(ctx, () -> { + List<OrderKey> orderKeys; if (ctx.sortClause().ORDER() != null) { - return visit(ctx.sortClause().sortItem(), OrderKey.class); + orderKeys = visit(ctx.sortClause().sortItem(), OrderKey.class); } else { - return ImmutableList.of(); + orderKeys = ImmutableList.of(); } + long limit = Long.MAX_VALUE; + long offset = 0; + if (ctx.limitClause().LIMIT() != null) { + limit = Long.parseLong(ctx.limitClause().limit.getText()); + if (ctx.limitClause().OFFSET() != null || ctx.limitClause().COMMA() != null) { + offset = Long.parseLong(ctx.limitClause().offset.getText()); + } + } + return new QueryOrganization(orderKeys, limit, offset); Review Comment: I think QueryOrganization is should be divided into LogicalSort and LogicalLimit. -- 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