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 2024/11/19 01:14:54 UTC
(shardingsphere) branch master updated: Issue 31553 Improving parsing for MYSQL queries (#33444)
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 520325d46f6 Issue 31553 Improving parsing for MYSQL queries (#33444)
520325d46f6 is described below
commit 520325d46f61a639a0c30d87c53009466b7572ab
Author: Yash-cor <ya...@coriolis.co.in>
AuthorDate: Tue Nov 19 06:44:47 2024 +0530
Issue 31553 Improving parsing for MYSQL queries (#33444)
* QUOTE QUERY
* Undo grammar changes.
* Added the test queries
* made correction in MySql test case.
* Added a testing class
* Added test MYSQL queries
* solved the differences
---
.../resources/case/dml/select-math-function.xml | 32 ++++
.../resources/case/dml/select-special-function.xml | 191 +++++++++++++++++++++
.../sql/supported/dml/select-math-function.xml | 1 +
.../sql/supported/dml/select-special-function.xml | 12 ++
4 files changed, 236 insertions(+)
diff --git a/test/it/parser/src/main/resources/case/dml/select-math-function.xml b/test/it/parser/src/main/resources/case/dml/select-math-function.xml
index 38e572452f5..484f7e1805b 100644
--- a/test/it/parser/src/main/resources/case/dml/select-math-function.xml
+++ b/test/it/parser/src/main/resources/case/dml/select-math-function.xml
@@ -73,6 +73,38 @@
</projections>
</select>
+ <select sql-case-id="select_interval">
+ <projections start-index="7" stop-index="42">
+ <expression-projection text="INTERVAL(23, 1, 15, 17, 30, 44, 200)" start-index="7" stop-index="42">
+ <expr>
+ <function function-name="INTERVAL" start-index="7" stop-index="42" text="INTERVAL(23, 1, 15, 17, 30, 44, 200)" >
+ <parameter>
+ <literal-expression value="23" start-index="16" stop-index="17" />
+ </parameter>
+ <parameter>
+ <literal-expression value="1" start-index="20" stop-index="20" />
+ </parameter>
+ <parameter>
+ <literal-expression value="15" start-index="23" stop-index="24" />
+ </parameter>
+ <parameter>
+ <literal-expression value="17" start-index="27" stop-index="28" />
+ </parameter>
+ <parameter>
+ <literal-expression value="30" start-index="31" stop-index="32" />
+ </parameter>
+ <parameter>
+ <literal-expression value="44" start-index="35" stop-index="36" />
+ </parameter>
+ <parameter>
+ <literal-expression value="200" start-index="39" stop-index="41" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
<select sql-case-id="select_pow">
<projections start-index="7" stop-index="14">
<expression-projection text="POW(2,2)" start-index="7" stop-index="14">
diff --git a/test/it/parser/src/main/resources/case/dml/select-special-function.xml b/test/it/parser/src/main/resources/case/dml/select-special-function.xml
index 6712182134b..9f5b98b7e93 100644
--- a/test/it/parser/src/main/resources/case/dml/select-special-function.xml
+++ b/test/it/parser/src/main/resources/case/dml/select-special-function.xml
@@ -2836,6 +2836,197 @@
</projections>
</select>
+ <select sql-case-id="select_gtid_subtract">
+ <projections start-index="7" stop-index="107">
+ <expression-projection start-index="7" stop-index="107" text="GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57','3E11FA47-71CA-11E1-9E33-C80AA9429562:21')">
+ <expr>
+ <function start-index="7" stop-index="107" function-name="GTID_SUBTRACT" text="GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57','3E11FA47-71CA-11E1-9E33-C80AA9429562:21')">
+ <parameter>
+ <literal-expression start-index="21" stop-index="64" value="3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57" />
+ </parameter>
+ <parameter>
+ <literal-expression start-index="66" stop-index="106" value="3E11FA47-71CA-11E1-9E33-C80AA9429562:21" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_hex">
+ <projections start-index="7" stop-index="16">
+ <expression-projection start-index="7" stop-index="16" text="HEX('abc')">
+ <expr>
+ <function function-name="HEX" text="HEX('abc')" start-index="7" stop-index="16">
+ <parameter>
+ <literal-expression start-index="11" stop-index="15" value="abc" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_hour">
+ <projections start-index="7" stop-index="22">
+ <expression-projection start-index="7" stop-index="22" text="HOUR('10:05:03')">
+ <expr>
+ <function function-name="HOUR" text="HOUR('10:05:03')" start-index="7" stop-index="22">
+ <parameter>
+ <literal-expression start-index="12" stop-index="21" value="10:05:03" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_is_ipv4">
+ <projections start-index="7" stop-index="25">
+ <expression-projection start-index="7" stop-index="25" text="IS_IPV4('10.0.5.9')">
+ <expr>
+ <function function-name="IS_IPV4" text="IS_IPV4('10.0.5.9')" start-index="7" stop-index="25">
+ <parameter>
+ <literal-expression start-index="15" stop-index="24" value="10.0.5.9" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_is_ipv4_compat">
+ <projections start-index="7" stop-index="46">
+ <expression-projection start-index="7" stop-index="46" text="IS_IPV4_COMPAT(INET6_ATON('::10.0.5.9'))">
+ <expr>
+ <function function-name="IS_IPV4_COMPAT" text="IS_IPV4_COMPAT(INET6_ATON('::10.0.5.9'))" start-index="7" stop-index="46">
+ <parameter>
+ <function function-name="INET6_ATON" text="INET6_ATON('::10.0.5.9')" start-index="22" stop-index="45">
+ <parameter>
+ <literal-expression start-index="33" stop-index="44" value="::10.0.5.9" />
+ </parameter>
+ </function>
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_is_ipv4_mapped">
+ <projections start-index="7" stop-index="46">
+ <expression-projection start-index="7" stop-index="46" text="IS_IPV4_MAPPED(INET6_ATON('::10.0.5.9'))">
+ <expr>
+ <function function-name="IS_IPV4_MAPPED" text="IS_IPV4_MAPPED(INET6_ATON('::10.0.5.9'))" start-index="7" stop-index="46">
+ <parameter>
+ <function function-name="INET6_ATON" text="INET6_ATON('::10.0.5.9')" start-index="22" stop-index="45">
+ <parameter>
+ <literal-expression start-index="33" stop-index="44" value="::10.0.5.9" />
+ </parameter>
+ </function>
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_is_ipv6">
+ <projections start-index="7" stop-index="25">
+ <expression-projection start-index="7" stop-index="25" text="IS_IPV6('10.0.5.9')">
+ <expr>
+ <function function-name="IS_IPV6" text="IS_IPV6('10.0.5.9')" start-index="7" stop-index="25">
+ <parameter>
+ <literal-expression start-index="15" stop-index="24" value="10.0.5.9" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_is_free_lock">
+ <projections start-index="7" stop-index="27">
+ <expression-projection start-index="7" stop-index="27" text="IS_FREE_LOCK('lock1')">
+ <expr>
+ <function function-name="IS_FREE_LOCK" text="IS_FREE_LOCK('lock1')" start-index="7" stop-index="27">
+ <parameter>
+ <literal-expression start-index="20" stop-index="26" value="lock1" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_is_used_lock">
+ <projections start-index="7" stop-index="27">
+ <expression-projection start-index="7" stop-index="27" text="IS_USED_LOCK('lock1')">
+ <expr>
+ <function function-name="IS_USED_LOCK" text="IS_USED_LOCK('lock1')" start-index="7" stop-index="27">
+ <parameter>
+ <literal-expression start-index="20" stop-index="26" value="lock1" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_is_null">
+ <projections start-index="7" stop-index="17">
+ <expression-projection start-index="7" stop-index="17" text="ISNULL(1+1)">
+ <expr>
+ <function function-name="ISNULL" text="ISNULL(1+1)" start-index="7" stop-index="17">
+ <parameter>
+ <binary-operation-expression start-index="14" stop-index="16" literal-start-index="14" literal-stop-index="16">
+ <left>
+ <literal-expression value="1" start-index="14" stop-index="14" literal-start-index="14" literal-stop-index="14" />
+ </left>
+ <operator>+</operator>
+ <right>
+ <literal-expression value="1" start-index="16" stop-index="16" literal-start-index="16" literal-stop-index="16" />
+ </right>
+ </binary-operation-expression>
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_is_not_null">
+ <projections start-index="7" stop-index="19">
+ <expression-projection text="1 IS NOT NULL" start-index="7" stop-index="19">
+ <expr>
+ <binary-operation-expression start-index="7" stop-index="19">
+ <left>
+ <literal-expression value="1" start-index="7" stop-index="7" />
+ </left>
+ <operator>IS</operator>
+ <right>
+ <literal-expression value="NOT NULL" start-index="12" stop-index="19" />
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_is_uuid">
+ <projections start-index="7" stop-index="53">
+ <expression-projection start-index="7" stop-index="53" text="IS_UUID('6ccd780c-baba-1026-9564-5b8c656024db')">
+ <expr>
+ <function function-name="IS_UUID" text="IS_UUID('6ccd780c-baba-1026-9564-5b8c656024db')" start-index="7" stop-index="53">
+ <parameter>
+ <literal-expression start-index="15" stop-index="52" value="6ccd780c-baba-1026-9564-5b8c656024db" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
<select sql-case-id="select_random_bytes">
<projections start-index="7" stop-index="22">
<expression-projection start-index="7" stop-index="22" text="RANDOM_BYTES(16)">
diff --git a/test/it/parser/src/main/resources/sql/supported/dml/select-math-function.xml b/test/it/parser/src/main/resources/sql/supported/dml/select-math-function.xml
index f4d79159f32..4f9a93f13ca 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/select-math-function.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/select-math-function.xml
@@ -21,6 +21,7 @@
<sql-case id="select_acos" value="SELECT ACOS(0)" db-types="MySQL" />
<sql-case id="select_asin" value="SELECT ASIN(0.2)" db-types="MySQL" />
<sql-case id="select_atan" value="SELECT ATAN(2)" db-types="MySQL" />
+ <sql-case id="select_interval" value="SELECT INTERVAL(23, 1, 15, 17, 30, 44, 200)" db-types="MySQL" />
<sql-case id="select_pow" value="SELECT POW(2,2)" db-types="MySQL" />
<sql-case id="select_power" value="SELECT POWER(2,2)" db-types="MySQL" />
<sql-case id="select_rand" value="SELECT RAND()" db-types="MySQL" />
diff --git a/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml b/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
index 17a6a5208a8..3a979772c31 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
@@ -167,6 +167,18 @@
<sql-case id="select_greatest" value="SELECT GREATEST(2,0)" db-types="MySQL" />
<sql-case id="select_grouping" value="SELECT GROUPING(status) FROM t_order order by status" db-types="MySQL" />
<sql-case id="select_gtid_subset" value="SELECT GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:23','3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57')" db-types="MySQL" />
+ <sql-case id="select_gtid_subtract" value="SELECT GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57','3E11FA47-71CA-11E1-9E33-C80AA9429562:21')" db-types="MySQL" />
+ <sql-case id="select_hex" value="SELECT HEX('abc')" db-types="MySQL" />
+ <sql-case id="select_hour" value="SELECT HOUR('10:05:03')" db-types="MySQL" />
+ <sql-case id="select_is_ipv4" value="SELECT IS_IPV4('10.0.5.9')" db-types="MySQL" />
+ <sql-case id="select_is_ipv4_compat" value="SELECT IS_IPV4_COMPAT(INET6_ATON('::10.0.5.9'))" db-types="MySQL" />
+ <sql-case id="select_is_ipv4_mapped" value="SELECT IS_IPV4_MAPPED(INET6_ATON('::10.0.5.9'))" db-types="MySQL" />
+ <sql-case id="select_is_ipv6" value="SELECT IS_IPV6('10.0.5.9')" db-types="MySQL" />
+ <sql-case id="select_is_free_lock" value="SELECT IS_FREE_LOCK('lock1')" db-types="MySQL" />
+ <sql-case id="select_is_used_lock" value="SELECT IS_USED_LOCK('lock1')" db-types="MySQL" />
+ <sql-case id="select_is_null" value="SELECT ISNULL(1+1)" db-types="MySQL" />
+ <sql-case id="select_is_not_null" value="SELECT 1 IS NOT NULL" db-types="MySQL" />
+ <sql-case id="select_is_uuid" value="SELECT IS_UUID('6ccd780c-baba-1026-9564-5b8c656024db')" db-types="MySQL" />
<sql-case id="select_random_bytes" value="SELECT RANDOM_BYTES(16)" db-types="MySQL" />
<sql-case id="select_rank" value="SELECT RANK() FROM numbers" db-types="MySQL" />
<sql-case id="select_regexp_instr" value="SELECT REGEXP_INSTR('dog cat dog', 'dog')" db-types="MySQL" />