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

panjuan 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 7d06014  fix create table column datatype unsigned parse error
     new 7030777  Merge pull request #7142 from strongduanmu/issue-7134-dev
7d06014 is described below

commit 7d06014c77242f9e5328edd53950f59f6e7d25c6
Author: strongduanmu <[email protected]>
AuthorDate: Fri Aug 28 23:39:08 2020 +0800

    fix create table column datatype unsigned parse error
---
 .../src/main/antlr4/imports/mysql/BaseRule.g4      |  4 ++--
 .../src/main/resources/case/ddl/create-table.xml   | 20 ++++++++++++++++++++
 .../src/main/resources/case/dml/select.xml         | 22 ++++++++++++++++++++++
 .../main/resources/sql/supported/ddl/create.xml    |  3 ++-
 .../main/resources/sql/supported/dml/select.xml    |  1 +
 5 files changed, 47 insertions(+), 3 deletions(-)

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 c71e687..8ab2760 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
@@ -565,11 +565,11 @@ orderByItem
     ;
 
 dataType
-    : dataTypeName dataTypeLength? characterSet_? collateClause_? ZEROFILL? | 
dataTypeName collectionOptions characterSet_? collateClause_?
+    : dataTypeName dataTypeLength? characterSet_? collateClause_? (UNSIGNED | 
SIGNED)? ZEROFILL? | dataTypeName collectionOptions characterSet_? 
collateClause_?
     ;
 
 dataTypeName
-    : (UNSIGNED | SIGNED)? INTEGER | INT | SMALLINT | TINYINT | MEDIUMINT | 
BIGINT | DECIMAL| NUMERIC | FLOAT | DOUBLE | BIT | BOOL | BOOLEAN
+    : INTEGER | INT | SMALLINT | TINYINT | MEDIUMINT | BIGINT | DECIMAL| 
NUMERIC | FLOAT | DOUBLE | BIT | BOOL | BOOLEAN
     | DEC | DATE | DATETIME | TIMESTAMP | TIME | YEAR | CHAR | VARCHAR | 
BINARY | VARBINARY | TINYBLOB | TINYTEXT | BLOB
     | TEXT | MEDIUMBLOB | MEDIUMTEXT | LONGBLOB | LONGTEXT | ENUM | SET | 
GEOMETRY | POINT | LINESTRING | POLYGON
     | MULTIPOINT | MULTILINESTRING | MULTIPOLYGON | GEOMETRYCOLLECTION | JSON 
| UNSIGNED | SIGNED
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/create-table.xml
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/create-table.xml
index 6369f49..d11c74b 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/create-table.xml
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/create-table.xml
@@ -1335,4 +1335,24 @@
             <column name="column3" />
         </column-definition>
     </create-table>
+
+    <create-table sql-case-id="create_table_with_sign_column">
+        <table name="t_order" start-index="13" stop-index="19" />
+        <column-definition type="INT" primary-key="true" start-index="21" 
stop-index="38">
+            <column name="id" />
+        </column-definition>
+        <column-definition type="BIGINT" start-index="41" stop-index="66">
+            <column name="order_id" />
+        </column-definition>
+    </create-table>
+
+    <create-table sql-case-id="create_table_with_unsigned_column">
+        <table name="t_order" start-index="13" stop-index="19" />
+        <column-definition type="INT" primary-key="true" start-index="21" 
stop-index="38">
+            <column name="id" />
+        </column-definition>
+        <column-definition type="BIGINT" start-index="41" stop-index="68">
+            <column name="order_id" />
+        </column-definition>
+    </create-table>
 </sql-parser-test-cases>
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/select.xml
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/select.xml
index 9c61196..8a738c3 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/select.xml
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/select.xml
@@ -1980,4 +1980,26 @@
             </and-predicate>
         </where>
     </select>
+
+    <select sql-case-id="select_with_convert_function">
+        <table-reference>
+            <table-factor>
+                <table name="t_order" start-index="70" stop-index="76" />
+            </table-factor>
+        </table-reference>
+        <projections start-index="7" stop-index="63">
+            <expression-projection alias="signed_content" start-index="7" 
stop-index="63" />
+        </projections>
+        <where start-index="78" stop-index="95">
+            <and-predicate>
+                <predicate start-index="84" stop-index="95">
+                    <column-left-value name="order_id" start-index="84" 
stop-index="91" />
+                    <operator type="=" />
+                    <compare-right-value>
+                        <literal-expression value="1" start-index="95" 
stop-index="95" />
+                    </compare-right-value>
+                </predicate>
+            </and-predicate>
+        </where>
+    </select>
 </sql-parser-test-cases>
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/create.xml
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/create.xml
index 10eb202..13d7c02 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/create.xml
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/create.xml
@@ -112,6 +112,7 @@
     <sql-case id="create_table_with_inline_constraints_sqlserver" 
value="CREATE TABLE t_order (order_id INT PRIMARY KEY UNIQUE CHECK (order_id > 
0), user_id INT, status VARCHAR(10), column1 VARCHAR(10), column2 VARCHAR(10), 
column3 VARCHAR(10))" db-types="SQLServer" />
     <sql-case id="create_table_with_index" value="CREATE TABLE t_order 
(order_id INT INDEX order_index, user_id INT, status VARCHAR(10), column1 
VARCHAR(10), column2 VARCHAR(10), column3 VARCHAR(10))" db-types="SQLServer" />
     <sql-case id="create_index_with_bracket" value="CREATE INDEX [order_index] 
ON [t_order] ([order_id])" db-types="SQLServer" />
-
     <sql-case id="create_index_with_no_default_fill_factor" value="CREATE 
UNIQUE INDEX order_index ON t_order (order_id) WITH (fillfactor = 70)" 
db-types="PostgreSQL"/>
+    <sql-case id="create_table_with_sign_column" value="CREATE TABLE 
t_order(id INT PRIMARY KEY, order_id BIGINT(20) SIGNED)" db-types="MySQL" />
+    <sql-case id="create_table_with_unsigned_column" value="CREATE TABLE 
t_order(id INT PRIMARY KEY, order_id BIGINT(20) UNSIGNED)" db-types="MySQL" />
 </sql-cases>
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select.xml
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select.xml
index 9313654..2813045 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select.xml
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select.xml
@@ -57,4 +57,5 @@
     <sql-case id="select_current_user" value="SELECT CURRENT_USER" 
db-types="PostgreSQL"/>
     <sql-case id="select_with_match_against" value="SELECT * FROM t_order_item 
WHERE MATCH(t_order_item.description) AGAINST (? IN NATURAL LANGUAGE MODE) AND 
user_id = ?" db-types="MySQL" />
     <sql-case id="select_with_json_separator" value="select 
content_json->>'$.nation' as nation,content_json->>'$.title' as title from 
tb_content_json b where b.content_id=1" db-types="MySQL" />
+    <sql-case id="select_with_convert_function" value="SELECT 
CONVERT(SUBSTRING(content, 5) , SIGNED) AS signed_content FROM t_order WHERE 
order_id = 1" db-types="MySQL" />
 </sql-cases>

Reply via email to