You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/07/20 08:39:38 UTC

[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #6380: parse innerExpression and remove sql parameter in SelectStatementContext

strongduanmu commented on a change in pull request #6380:
URL: https://github.com/apache/shardingsphere/pull/6380#discussion_r457181138



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/SQLServerVisitor.java
##########
@@ -430,11 +431,11 @@ public final ASTNode visitAggregationFunction(final AggregationFunctionContext c
     
     private ASTNode createAggregationSegment(final AggregationFunctionContext ctx, final String aggregationType) {
         AggregationType type = AggregationType.valueOf(aggregationType.toUpperCase());
-        int innerExpressionStartIndex = ((TerminalNode) ctx.getChild(1)).getSymbol().getStartIndex();
+        String innerExpression = ctx.start.getInputStream().getText(new Interval(((TerminalNode) ctx.getChild(1)).getSymbol().getStartIndex(), ctx.stop.getStopIndex()));

Review comment:
       > The result of `ctx.start.getInputStream().getText()` and `ctx.getText()` are the same?
   
   @tristaZero According to the documentation of the `ctx.getText()` method, we can find that the method does not return whitespace.
   ```
   /** 
     *  Return the combined text of all leaf nodes. Does not get any
     *  off-channel tokens (if any) so won't return whitespace and
     *  comments if they are sent to parser on hidden channel.
     */
   String getText();
   ```
   In order to get the original sql that contains whitespace, we need to use the `ctx.start.getInputStream().getText()` method to specify the start and end interval through Interval.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org