You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2023/02/02 01:49:56 UTC
[shardingsphere] branch master updated: Fix parameters in the json function are not recognized(#23875) (#23894)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 3fe6411283c Fix parameters in the json function are not recognized(#23875) (#23894)
3fe6411283c is described below
commit 3fe6411283c5a2bb13c0a4f3255ec92a717e1f6b
Author: ZhangCheng <fl...@outlook.com>
AuthorDate: Thu Feb 2 09:49:36 2023 +0800
Fix parameters in the json function are not recognized(#23875) (#23894)
* Fix parameters in the json function are not recognized
* Fix parameters in the json function are not recognized
* Fix
---
.../statement/impl/MySQLStatementSQLVisitor.java | 3 +++
.../main/resources/case/dml/select-expression.xml | 25 +++++++++++++++++++---
.../sql/supported/dml/select-expression.xml | 1 +
3 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java b/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
index 33051ba2ef0..b408bb24e3e 100644
--- a/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
+++ b/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
@@ -784,6 +784,9 @@ public abstract class MySQLStatementSQLVisitor extends MySQLStatementBaseVisitor
String functionName;
if (null != functionNameContext) {
functionName = functionNameContext.getText();
+ for (ExprContext each : ctx.expr()) {
+ visit(each);
+ }
} else if (null != ctx.JSON_SEPARATOR()) {
functionName = ctx.JSON_SEPARATOR().getText();
} else {
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 fafbb2f8396..8eea084b322 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
@@ -1692,7 +1692,7 @@
</projections>
<where start-index="22" stop-index="44">
<expr>
- <function function-name="->" text="order_id ->"$[1]"" start-index="28" stop-index="44"></function>
+ <function function-name="->" text="order_id ->"$[1]"" start-index="28" stop-index="44"/>
</expr>
</where>
</select>
@@ -1706,7 +1706,7 @@
</projections>
<where start-index="22" stop-index="46">
<expr>
- <function function-name="->>" text="order_id ->> "$[1]"" start-index="28" stop-index="46"></function>
+ <function function-name="->>" text="order_id ->> "$[1]"" start-index="28" stop-index="46" />
</expr>
</where>
</select>
@@ -1720,10 +1720,29 @@
</projections>
<where start-index="22" stop-index="76">
<expr>
- <function function-name="JSON_CONTAINS" text="JSON_CONTAINS(order_msg -> '$[*].code', 'x', '$')" start-index="28" stop-index="76"></function>
+ <function function-name="JSON_CONTAINS" text="JSON_CONTAINS(order_msg -> '$[*].code', 'x', '$')" start-index="28" stop-index="76" />
</expr>
</where>
</select>
+
+ <select sql-case-id="select_where_with_simple_expr_with_json_contains_and_limit" parameters="1, 0, 1">
+ <projections start-index="7" stop-index="28">
+ <column-projection name="id" start-index="7" stop-index="8"/>
+ <expression-projection text="order_info->'$.id'" start-index="11" stop-index="28"/>
+ </projections>
+ <from>
+ <simple-table name="t_order" start-index="35" stop-index="41" />
+ </from>
+ <where start-index="43" stop-index="84">
+ <expr>
+ <function function-name="json_contains" text="json_contains(order_info, ?, '$.id')" literal-text="json_contains(order_info, 1, '$.id')" start-index="49" stop-index="84" />
+ </expr>
+ </where>
+ <limit start-index="86" stop-index="95">
+ <offset value="0" parameter-index="1" start-index="92" stop-index="92" />
+ <row-count value="1" parameter-index="2" start-index="95" stop-index="95"/>
+ </limit>
+ </select>
<select sql-case-id="select_where_with_simple_expr_with_match" parameters="'keyword'">
<from start-index="14" stop-index="20">
diff --git a/test/it/parser/src/main/resources/sql/supported/dml/select-expression.xml b/test/it/parser/src/main/resources/sql/supported/dml/select-expression.xml
index 03d168f9bfa..30463401e0a 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/select-expression.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/select-expression.xml
@@ -76,6 +76,7 @@
<sql-case id="select_where_with_simple_expr_with_json_extract_sign" value="SELECT * FROM t_order WHERE order_id ->"$[1]"" db-types="MySQL" />
<sql-case id="select_where_with_simple_expr_with_json_unquote_extract_sign" value="SELECT * FROM t_order WHERE order_id ->> "$[1]"" db-types="MySQL" />
<sql-case id="select_where_with_simple_expr_with_json_contains" value="SELECT * FROM t_order WHERE JSON_CONTAINS(order_msg -> '$[*].code', 'x', '$') " db-types="MySQL" />
+ <sql-case id="select_where_with_simple_expr_with_json_contains_and_limit" value="SELECT id, order_info->'$.id' FROM t_order where json_contains(order_info, ?, '$.id') limit ?, ?" db-types="MySQL" />
<sql-case id="select_where_with_simple_expr_with_match" value="SELECT * FROM t_order WHERE MATCH (order_id) AGAINST (? IN NATURAL LANGUAGE MODE)" db-types="MySQL" />
<sql-case id="select_where_with_simple_expr_with_case" value="SELECT * FROM t_order WHERE CASE WHEN order_id > ? THEN ? ELSE ? END" db-types="MySQL" />
<sql-case id="select_where_with_expr_with_not_with_order_by" value="SELECT last_name, job_id, salary, department_id FROM employees WHERE NOT (job_id = 'PU_CLERK' AND department_id = 30) ORDER BY last_name" db-types="Oracle" />