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/05/17 09:51:36 UTC

[shardingsphere] branch master updated: Optimize BaseRule.g4 label castTypeName lexer. (#25728)

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 f3712756981 Optimize BaseRule.g4 label castTypeName lexer. (#25728)
f3712756981 is described below

commit f3712756981ae3a534802e78d3e99e7c9bb9c52c
Author: Cong Hu <ia...@qq.com>
AuthorDate: Wed May 17 17:51:29 2023 +0800

    Optimize BaseRule.g4 label castTypeName lexer. (#25728)
---
 .../src/main/antlr4/imports/mysql/BaseRule.g4      |  8 ++---
 .../src/main/antlr4/imports/mysql/MySQLKeyword.g4  | 16 +++++++++
 .../src/main/resources/case/ddl/create-table.xml   | 42 ++++++++++++++++++++++
 .../parser/src/main/resources/case/dml/select.xml  |  8 ++---
 .../resources/sql/supported/ddl/create-table.xml   |  4 +++
 5 files changed, 70 insertions(+), 8 deletions(-)

diff --git a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4 b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
index 05405493d8e..ff50f740ab9 100644
--- a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
+++ b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
@@ -1026,8 +1026,8 @@ castType
     : castTypeName = BINARY fieldLength?
     | castTypeName = CHAR fieldLength? charsetWithOptBinary?
     | (castTypeName = NCHAR | castTypeName = NATIONAL_CHAR) fieldLength?
-    | castTypeName = SIGNED (INT | INTEGER)?
-    | castTypeName = UNSIGNED (INT | INTEGER)?
+    | castTypeName = (SIGNED | SIGNED_INT | SIGNED_INTEGER)
+    | castTypeName = (UNSIGNED | UNSIGNED_INT | UNSIGNED_INTEGER)
     | castTypeName = DATE
     | castTypeName = TIME typeDatetimePrecision?
     | castTypeName = DATETIME typeDatetimePrecision?
@@ -1159,7 +1159,7 @@ dataType
     | dataTypeName = (BOOL | BOOLEAN)
     | dataTypeName = CHAR fieldLength? charsetWithOptBinary?
     | (dataTypeName = NCHAR | dataTypeName = NATIONAL_CHAR) fieldLength? BINARY?
-    | dataTypeName = SIGNED (INTEGER | INT)?
+    | dataTypeName = (SIGNED | SIGNED_INT | SIGNED_INTEGER)
     | dataTypeName = BINARY fieldLength?
     | (dataTypeName = CHAR_VARYING | dataTypeName = CHARACTER_VARYING | dataTypeName = VARCHAR) fieldLength charsetWithOptBinary?
     | (dataTypeName = NATIONAL VARCHAR | dataTypeName = NVARCHAR | dataTypeName = NCHAR VARCHAR | dataTypeName = NATIONAL_CHAR_VARYING | dataTypeName = NCHAR VARYING) fieldLength BINARY?
@@ -1167,7 +1167,7 @@ dataType
     | dataTypeName = YEAR fieldLength? fieldOptions?
     | dataTypeName = DATE
     | dataTypeName = TIME typeDatetimePrecision?
-    | dataTypeName = UNSIGNED (INTEGER | INT)?
+    | dataTypeName = (UNSIGNED | UNSIGNED_INT | UNSIGNED_INTEGER)
     | dataTypeName = TIMESTAMP typeDatetimePrecision?
     | dataTypeName = DATETIME typeDatetimePrecision?
     | dataTypeName = TINYBLOB
diff --git a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4 b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4
index 40dcc53bb58..84249451067 100644
--- a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4
+++ b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4
@@ -2287,6 +2287,14 @@ SIGNED
     : S I G N E D
     ;
 
+SIGNED_INT
+    : SIGNED ' ' INT
+    ;
+
+SIGNED_INTEGER
+    : SIGNED ' ' INTEGER
+    ;
+
 SIMPLE
     : S I M P L E
     ;
@@ -2695,6 +2703,14 @@ UNSIGNED
     : U N S I G N E D
     ;
 
+UNSIGNED_INT
+    : UNSIGNED ' ' INT
+    ;
+
+UNSIGNED_INTEGER
+    : UNSIGNED ' ' INTEGER
+    ;
+
 UNTIL
     : U N T I L
     ;
diff --git a/test/it/parser/src/main/resources/case/ddl/create-table.xml b/test/it/parser/src/main/resources/case/ddl/create-table.xml
index 1a03dece624..6393a0f7e63 100644
--- a/test/it/parser/src/main/resources/case/ddl/create-table.xml
+++ b/test/it/parser/src/main/resources/case/ddl/create-table.xml
@@ -1842,4 +1842,46 @@
             <column name="status" />
         </column-definition>
     </create-table>
+
+    <create-table sql-case-id="create_table_with_signed_int_cast_function">
+        <table name="t1" start-index="13" stop-index="14" />
+        <column-definition type="json" start-index="16" stop-index="21">
+            <column name="j" />
+        </column-definition>
+        <constraint-definition index-name="mv_idx" start-index="24" stop-index="66" />
+    </create-table>
+
+    <create-table sql-case-id="create_table_with_signed_int">
+        <table name="t_order" start-index="13" stop-index="19" />
+        <column-definition type="INT" start-index="22" stop-index="33">
+            <column name="order_id" />
+        </column-definition>
+        <column-definition type="INT" start-index="36" stop-index="46">
+            <column name="user_id" />
+        </column-definition>
+        <column-definition type="SIGNED INT" start-index="49" stop-index="65">
+            <column name="status" />
+        </column-definition>
+    </create-table>
+
+    <create-table sql-case-id="create_table_with_unsigned_int_cast_function">
+        <table name="t1" start-index="13" stop-index="14" />
+        <column-definition type="json" start-index="16" stop-index="21">
+            <column name="j" />
+        </column-definition>
+        <constraint-definition index-name="mv_idx" start-index="24" stop-index="68" />
+    </create-table>
+
+    <create-table sql-case-id="create_table_with_unsigned_int">
+        <table name="t_order" start-index="13" stop-index="19" />
+        <column-definition type="INT" start-index="22" stop-index="33">
+            <column name="order_id" />
+        </column-definition>
+        <column-definition type="INT" start-index="36" stop-index="46">
+            <column name="user_id" />
+        </column-definition>
+        <column-definition type="UNSIGNED INT" start-index="49" stop-index="67">
+            <column name="status" />
+        </column-definition>
+    </create-table>
 </sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/case/dml/select.xml b/test/it/parser/src/main/resources/case/dml/select.xml
index f15cea7633c..c3b9929a0b8 100644
--- a/test/it/parser/src/main/resources/case/dml/select.xml
+++ b/test/it/parser/src/main/resources/case/dml/select.xml
@@ -3412,7 +3412,7 @@
                             <column name="order_id" start-index="20" stop-index="27" />
                         </parameter>
                         <parameter>
-                            <data-type value="SIGNED" start-index="32" stop-index="41" />
+                            <data-type value="SIGNED INT" start-index="32" stop-index="41" />
                         </parameter>
                     </function>
                 </expr>
@@ -3432,7 +3432,7 @@
                             <column name="order_id" start-index="12" stop-index="19" />
                         </parameter>
                         <parameter>
-                            <data-type value="UNSIGNED" start-index="24" stop-index="35" />
+                            <data-type value="UNSIGNED INT" start-index="24" stop-index="35" />
                         </parameter>
                     </function>
                 </expr>
@@ -3454,7 +3454,7 @@
                             <column name="order_id" start-index="20" stop-index="27" />
                         </parameter>
                         <parameter>
-                            <data-type value="SIGNED" start-index="32" stop-index="45" />
+                            <data-type value="SIGNED INTEGER" start-index="32" stop-index="45" />
                         </parameter>
                     </function>
                 </expr>
@@ -3474,7 +3474,7 @@
                             <column name="order_id" start-index="12" stop-index="19" />
                         </parameter>
                         <parameter>
-                            <data-type value="UNSIGNED" start-index="24" stop-index="39" />
+                            <data-type value="UNSIGNED INTEGER" start-index="24" stop-index="39" />
                         </parameter>
                     </function>
                 </expr>
diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/create-table.xml b/test/it/parser/src/main/resources/sql/supported/ddl/create-table.xml
index e233c189345..ebfbd0d41d4 100644
--- a/test/it/parser/src/main/resources/sql/supported/ddl/create-table.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/create-table.xml
@@ -133,4 +133,8 @@
     <sql-case id="create_table_with_start_transaction" value="CREATE TABLE t_order (order_id INT) START TRANSACTION" db-types="MySQL" />
     <sql-case id="create_table_with_cast_function" value="CREATE TABLE t1(j json, INDEX mv_idx((CAST(j AS UNSIGNED ARRAY))))" db-types="MySQL" />
     <sql-case id="create_table_with_long_char_varying" value="CREATE TABLE t_order (order_id INT, user_id INT, status LONG CHAR VARYING)" db-types="MySQL" />
+    <sql-case id="create_table_with_signed_int_cast_function" value="CREATE TABLE t1(j json, INDEX mv_idx((CAST(j AS SIGNED INT ARRAY))))" db-types="MySQL" />
+    <sql-case id="create_table_with_signed_int" value="CREATE TABLE t_order (order_id INT, user_id INT, status SIGNED INT)" db-types="MySQL" />
+    <sql-case id="create_table_with_unsigned_int_cast_function" value="CREATE TABLE t1(j json, INDEX mv_idx((CAST(j AS UNSIGNED INT ARRAY))))" db-types="MySQL" />
+    <sql-case id="create_table_with_unsigned_int" value="CREATE TABLE t_order (order_id INT, user_id INT, status UNSIGNED INT)" db-types="MySQL" />
 </sql-cases>