tuichenchuxin commented on code in PR #18045:
URL: https://github.com/apache/shardingsphere/pull/18045#discussion_r885132651


##########
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 +773,33 @@ 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);
+        if (null != ctx.distinct()) {
+            AggregationDistinctProjectionSegment distinctProjectionSegment = 
new AggregationDistinctProjectionSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(),
+                    type, innerExpression, getDistinctExpression(ctx));
+            
distinctProjectionSegment.getParameters().addAll(getExpressions(ctx));
+            return distinctProjectionSegment;
+        }
+        AggregationProjectionSegment projectionSegment = new 
AggregationProjectionSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), type, innerExpression);
+        projectionSegment.getParameters().addAll(getExpressions(ctx));
+        return projectionSegment;
+    }
+    
+    private Collection<ExpressionSegment> getExpressions(final 
AggregationFunctionContext ctx) {
+        if (null == ctx.expr()) {
+            return Collections.emptyList();
         }
-        return new 
AggregationDistinctProjectionSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), type, innerExpression, 
getDistinctExpression(ctx));
+        Collection<ExpressionSegment> result = new LinkedList<>();
+        for (ExprContext each : ctx.expr()) {
+            ASTNode visitNode = visit(each);
+            if (visitNode instanceof ColumnSegment) {

Review Comment:
   There is no need to judge instance of. Can cast to expressionSegment 
directly, and add to list.



-- 
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]

Reply via email to