tuichenchuxin commented on code in PR #18045:
URL: https://github.com/apache/shardingsphere/pull/18045#discussion_r884560626
##########
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParameterizedTest.java:
##########
@@ -104,6 +104,20 @@ public final class MySQLParameterizedTest {
+ "\t`submission_date` DATE,\n"
+ "\tPRIMARY KEY (`runoob_id`)\n"
+ ") ENGINE = InnoDB DEFAULT CHARSET = utf8"});
+ testUnits.add(new String[]{"select_with_column", "select id, name,
age, count(table1.id) as n, (select id, name, age, sex from table2 where id=2)
as sid, yyyy from table1 where id=1",
Review Comment:
This test is for format. It's better add test in shardingsphere-parser-test
moudle.
##########
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java:
##########
@@ -773,10 +774,30 @@ public final ASTNode visitAggregationFunction(final
AggregationFunctionContext c
private ASTNode createAggregationSegment(final AggregationFunctionContext
ctx, final String aggregationType) {
AggregationType type =
AggregationType.valueOf(aggregationType.toUpperCase());
String innerExpression = ctx.start.getInputStream().getText(new
Interval(ctx.LP_().getSymbol().getStartIndex(), ctx.stop.getStopIndex()));
- if (null == ctx.distinct()) {
- return new
AggregationProjectionSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), type, innerExpression);
- }
- return new
AggregationDistinctProjectionSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), type, innerExpression,
getDistinctExpression(ctx));
+ if (null != ctx.distinct()) {
+ AggregationDistinctProjectionSegment distinctProjectionSegment =
new AggregationDistinctProjectionSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(),
+ type, innerExpression, getDistinctExpression(ctx));
+ getExpression(ctx).ifPresent(each ->
distinctProjectionSegment.getParameters().add(each));
+ return distinctProjectionSegment;
+ }
+ AggregationProjectionSegment projectionSegment = new
AggregationProjectionSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), type, innerExpression);
+ getExpression(ctx).ifPresent(each ->
projectionSegment.getParameters().add(each));
+ return projectionSegment;
+ }
+
+ private Optional<ExpressionSegment> getExpression(final
AggregationFunctionContext ctx) {
+ if (null == ctx.expr(0)) {
Review Comment:
I think it's possible have multi expr. Should we visit and extract them too?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]