This is an automated email from the ASF dual-hosted git repository.

chengzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 324c3c17243 Enhance mysql json function visit statement result (#31190)
324c3c17243 is described below

commit 324c3c1724321d0224a95ff845ae7d79d5a9d7a7
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Fri May 10 11:06:50 2024 +0800

    Enhance mysql json function visit statement result (#31190)
---
 .../visitor/statement/MySQLStatementVisitor.java   | 16 +++++++++----
 .../main/resources/case/dml/select-expression.xml  | 27 +++++++++++++++++++---
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git 
a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
 
b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
index 40cc9cb90c8..db555edf20f 100644
--- 
a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
+++ 
b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
@@ -77,6 +77,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.JoinSpe
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.JoinedTableContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.JsonFunctionContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.JsonFunctionNameContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.JsonTableFunctionContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LimitClauseContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LimitOffsetContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LimitRowCountContext;
@@ -146,7 +147,6 @@ import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ViewNam
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.WeightStringFunctionContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.WhereClauseContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.WithClauseContext;
-import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.JsonTableFunctionContext;
 import org.apache.shardingsphere.sql.parser.sql.common.enums.AggregationType;
 import org.apache.shardingsphere.sql.parser.sql.common.enums.CombineType;
 import org.apache.shardingsphere.sql.parser.sql.common.enums.JoinType;
@@ -931,17 +931,23 @@ public abstract class MySQLStatementVisitor extends 
MySQLStatementBaseVisitor<AS
                 result.getParameters().add((ExpressionSegment) visit(each));
             }
         } else if (null != ctx.JSON_SEPARATOR()) {
-            functionName = ctx.JSON_SEPARATOR().getText();
-            result = new FunctionSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), functionName, getOriginalText(ctx));
+            result = 
createJsonSeparatorFunction(ctx.JSON_SEPARATOR().getText(), ctx);
         } else if (null != ctx.JSON_UNQUOTED_SEPARATOR()) {
-            functionName = ctx.JSON_UNQUOTED_SEPARATOR().getText();
-            result = new FunctionSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), functionName, getOriginalText(ctx));
+            result = 
createJsonSeparatorFunction(ctx.JSON_UNQUOTED_SEPARATOR().getText(), ctx);
         } else {
             result = (FunctionSegment) 
visitJsonTableFunction(ctx.jsonTableFunction());
         }
         return result;
     }
     
+    private FunctionSegment createJsonSeparatorFunction(final String 
functionName, final JsonFunctionContext ctx) {
+        FunctionSegment result;
+        result = new FunctionSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), functionName, getOriginalText(ctx));
+        result.getParameters().add((ExpressionSegment) visit(ctx.columnRef()));
+        result.getParameters().add(new 
LiteralExpressionSegment(ctx.path().getStart().getStartIndex(), 
ctx.path().getStop().getStopIndex(), ctx.path().getText()));
+        return result;
+    }
+    
     @Override
     public final ASTNode visitJsonTableFunction(final JsonTableFunctionContext 
ctx) {
         FunctionSegment result = new 
FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), 
ctx.JSON_TABLE().getText(), ctx.getText());
diff --git a/test/it/parser/src/main/resources/case/dml/select-expression.xml 
b/test/it/parser/src/main/resources/case/dml/select-expression.xml
index c5b51bb447b..13d327c064f 100644
--- a/test/it/parser/src/main/resources/case/dml/select-expression.xml
+++ b/test/it/parser/src/main/resources/case/dml/select-expression.xml
@@ -2024,7 +2024,14 @@
         </projections>
         <where start-index="22" stop-index="44">
             <expr>
-                <function function-name="-&gt;" text="order_id 
-&gt;&quot;$[1]&quot;" start-index="28" stop-index="44"/>
+                <function function-name="-&gt;" text="order_id 
-&gt;&quot;$[1]&quot;" start-index="28" stop-index="44">
+                    <parameter>
+                        <column name="order_id" start-index="28" 
stop-index="35" />
+                    </parameter>
+                    <parameter>
+                        <literal-expression value="&quot;$[1]&quot;" 
start-index="39" stop-index="44" />
+                    </parameter>
+                </function>
             </expr>
         </where>
     </select>
@@ -2060,7 +2067,14 @@
         </projections>
         <where start-index="22" stop-index="46">
             <expr>
-                <function function-name="-&gt;&gt;" text="order_id -&gt;&gt; 
&quot;$[1]&quot;" start-index="28" stop-index="46" />
+                <function function-name="-&gt;&gt;" text="order_id -&gt;&gt; 
&quot;$[1]&quot;" start-index="28" stop-index="46">
+                    <parameter>
+                        <column name="order_id" start-index="28" 
stop-index="35" />
+                    </parameter>
+                    <parameter>
+                        <literal-expression value="&quot;$[1]&quot;" 
start-index="41" stop-index="46" />
+                    </parameter>
+                </function>
             </expr>
         </where>
     </select>
@@ -2076,7 +2090,14 @@
             <expr>
                 <function function-name="JSON_CONTAINS" 
text="JSON_CONTAINS(order_msg -> '$[*].code', 'x', '$')" start-index="28" 
stop-index="76" >
                     <parameter>
-                        <function start-index="42" stop-index="65" 
function-name="->" text="order_msg -> '$[*].code'" />
+                        <function start-index="42" stop-index="65" 
function-name="->" text="order_msg -> '$[*].code'">
+                            <parameter>
+                                <column start-index="42" stop-index="50" 
name="order_msg" />
+                            </parameter>
+                            <parameter>
+                                <literal-expression start-index="55" 
stop-index="65" value="'$[*].code'" />
+                            </parameter>
+                        </function>
                     </parameter>
                     <parameter>
                         <literal-expression start-index="68" stop-index="70" 
value="x" />

Reply via email to