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 2021/07/07 08:25:19 UTC

[shardingsphere] branch master updated: fix mysql select cast(a as signed) (#11189)

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 c1b52b1  fix mysql select cast(a as signed) (#11189)
c1b52b1 is described below

commit c1b52b142dca45a40a81c1ae907419814fb5c55c
Author: tuichenchuxin <86...@users.noreply.github.com>
AuthorDate: Wed Jul 7 16:24:52 2021 +0800

    fix mysql select cast(a as signed) (#11189)
    
    * fix mysql select cast(a as signed)
    
    * fix mysql select cast(a as signed)
---
 .../src/main/antlr4/imports/mysql/BaseRule.g4       |  2 ++
 .../src/main/resources/case/dml/select.xml          | 21 +++++++++++++++++++++
 .../src/main/resources/sql/supported/dml/select.xml |  2 ++
 3 files changed, 25 insertions(+)

diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/BaseRule.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/BaseRule.g4
index f6c39de..2904bc1 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/BaseRule.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/BaseRule.g4
@@ -1102,6 +1102,7 @@ dataType
     | dataTypeName = (BOOL | BOOLEAN)
     | dataTypeName = CHAR fieldLength? charsetWithOptBinary?
     | (dataTypeName = NCHAR | dataTypeName = NATIONAL CHAR) fieldLength? BINARY?
+    | dataTypeName = SIGNED
     | dataTypeName = BINARY fieldLength?
     | (dataTypeName = CHAR VARYING | dataTypeName = VARCHAR) fieldLength charsetWithOptBinary?
     | (dataTypeName = NATIONAL VARCHAR | dataTypeName = NVARCHAR | dataTypeName = NCHAR VARCHAR | dataTypeName = NATIONAL CHAR VARYING | dataTypeName = NCHAR VARYING) fieldLength BINARY?
@@ -1109,6 +1110,7 @@ dataType
     | dataTypeName = YEAR fieldLength? fieldOptions?
     | dataTypeName = DATE
     | dataTypeName = TIME typeDatetimePrecision?
+    | dataTypeName = UNSIGNED
     | dataTypeName = TIMESTAMP typeDatetimePrecision?
     | dataTypeName = DATETIME typeDatetimePrecision?
     | dataTypeName = TINYBLOB
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
index 6950720..8cdee57 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
@@ -2921,5 +2921,26 @@
             <expression-projection text="1" start-index="7" stop-index="7" />
         </projections>
     </select>
+
+    <select sql-case-id="select_with_cast_as_signed">
+        <from>
+            <simple-table name="t_order" start-index="45" stop-index="51" />
+        </from>
+        <projections start-index="7" stop-index="38">
+            <column-projection name="user_id" start-index="7" stop-index="13"/>
+            <expression-projection text="CAST(order_id AS SIGNED)" start-index="15" stop-index="38" />
+        </projections>
+    </select>
+
+    <select sql-case-id="select_with_cast_as_unsigned">
+        <from>
+            <simple-table name="t_order" start-index="47" stop-index="53"/>
+        </from>
+        <projections start-index="7" stop-index="40">
+            <expression-projection text="CAST(order_id AS UNSIGNED)" start-index="7" stop-index="32" />
+            <column-projection name="user_id" start-index="34" stop-index="40"/>
+        </projections>
+    </select>
+
 </sql-parser-test-cases>
 
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select.xml
index dd73b76..e211a16 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select.xml
@@ -81,4 +81,6 @@
     <sql-case id="select_with_jsonb_path_predicate_check" value="SELECT content_json::jsonb@@'$.keyword[*]==&quot;ss&quot;' FROM tb_content_json" db-types="PostgreSQL" />
     <sql-case id="select_with_assignment_operator" value="SELECT @rn := 1, @now_code := '' FROM t_order" db-types="MySQL" />
     <sql-case id="select_from_dual" value="SELECT 1 FROM DUAL" db-types="MySQL" />
+    <sql-case id="select_with_cast_as_signed" value="SELECT user_id,CAST(order_id AS SIGNED) FROM t_order" db-types="MySQL"/>
+    <sql-case id="select_with_cast_as_unsigned" value="SELECT CAST(order_id AS UNSIGNED),user_id FROM t_order" db-types="MySQL"/>
 </sql-cases>