You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "TherChenYang (via GitHub)" <gi...@apache.org> on 2024/01/14 15:05:23 UTC

[PR] Support parsing SQL Server open json function [shardingsphere]

TherChenYang opened a new pull request, #29721:
URL: https://github.com/apache/shardingsphere/pull/29721

   Fixes #29153 .
   
   Changes proposed in this pull request:
     - Support parsing SQL Server open json function [Official website grammar definition](https://learn.microsoft.com/zh-cn/sql/t-sql/functions/openjson-transact-sql?view=sql-server-ver16)
   <img width="738" alt="image" src="https://github.com/apache/shardingsphere/assets/124348939/6a3a8b17-c97a-40ea-acbe-9d523b1133f7">
     - Fixed the problem with parsing errors in projection compound expressions
       > examle
   ![image](https://github.com/apache/shardingsphere/assets/124348939/fe7dba7d-0f47-4542-8006-beed184c5c81)
   ![image](https://github.com/apache/shardingsphere/assets/124348939/180cd927-ff64-4ad7-84c7-46cd0f9e258a)
     - Support for sql parsing in issule #29153 
   
   ```sql
   INSERT @table1 (c2, is_transient) VALUES (N'sample durable', 0)
   ```
   
   ```sql
   SELECT product_id   
   FROM products   
   WHERE CONTAINS(product_description, '"Snap Happy 100EZ" OR FORMSOF(THESAURUS,"Snap Happy") OR "100EZ"')
   AND product_cost < 200
   ```
   
   ```sql
   SELECT * FROM OPENJSON(@array)
           WITH (  month VARCHAR(3),
                   temp int,
                   month_id tinyint '$.sql:identity()') as months
   ```
   
   ```sql
   SELECT [key], value
   FROM OPENJSON(@json,'$.path.to."sub-object"')
   ```
   
   ```sql
   SELECT reason, score,
         script = JSON_VALUE(details, '$.implementationDetails.script'),
         planForceDetails.*,
         estimated_gain = (regressedPlanExecutionCount + recommendedPlanExecutionCount)
                     * (regressedPlanCpuTimeAverage - recommendedPlanCpuTimeAverage)/1000000,
         error_prone = IIF(regressedPlanErrorCount > recommendedPlanErrorCount, 'YES','NO')
   FROM sys.dm_db_tuning_recommendations
   CROSS APPLY OPENJSON (Details, '$.planForceDetails')
       WITH (  [query_id] int '$.queryId',
               regressedPlanId int '$.regressedPlanId',
               recommendedPlanId int '$.recommendedPlanId',
               regressedPlanErrorCount int,
               recommendedPlanErrorCount int,
               regressedPlanExecutionCount int,
               regressedPlanCpuTimeAverage float,
               recommendedPlanExecutionCount int,
               recommendedPlanCpuTimeAverage float
             ) AS planForceDetails
   ```
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [x] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [x] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [x] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [x] I have added corresponding unit tests for my changes.
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


Re: [PR] Support parsing SQL Server open json function [shardingsphere]

Posted by "TherChenYang (via GitHub)" <gi...@apache.org>.
TherChenYang commented on code in PR #29721:
URL: https://github.com/apache/shardingsphere/pull/29721#discussion_r1451952385


##########
parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java:
##########
@@ -687,6 +695,15 @@ public final ASTNode visitCharFunction(final CharFunctionContext ctx) {
         return new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.CHAR().getText(), getOriginalText(ctx));
     }
     
+    @Override
+    public final ASTNode visitOpenJsonFunction(final OpenJsonFunctionContext ctx) {
+        FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.OPENJSON().getText(), getOriginalText(ctx));
+        for (ExprContext exprContext : ctx.expr()) {

Review Comment:
   Already modified, thank you for the review.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


Re: [PR] Support parsing SQL Server open json function [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on code in PR #29721:
URL: https://github.com/apache/shardingsphere/pull/29721#discussion_r1451887448


##########
parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java:
##########
@@ -687,6 +695,15 @@ public final ASTNode visitCharFunction(final CharFunctionContext ctx) {
         return new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.CHAR().getText(), getOriginalText(ctx));
     }
     
+    @Override
+    public final ASTNode visitOpenJsonFunction(final OpenJsonFunctionContext ctx) {
+        FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.OPENJSON().getText(), getOriginalText(ctx));
+        for (ExprContext exprContext : ctx.expr()) {

Review Comment:
   Please rename exprContext to each.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


Re: [PR] Support parsing SQL Server open json function [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu merged PR #29721:
URL: https://github.com/apache/shardingsphere/pull/29721


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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