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 1f7d777  fix current_date & current_time function parse error (#11726)
1f7d777 is described below

commit 1f7d7777b4f77e9a6188facced04c6d4e655d44d
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Mon Aug 9 18:27:32 2021 +0800

    fix current_date & current_time function parse error (#11726)
---
 .../src/main/antlr4/imports/mysql/BaseRule.g4      |  3 +-
 .../src/main/resources/case/dml/select.xml         | 88 ++++++++++++++++++++++
 .../main/resources/sql/supported/dml/select.xml    |  4 +
 3 files changed, 94 insertions(+), 1 deletion(-)

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 2904bc1..d33be93 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
@@ -1037,7 +1037,8 @@ regularFunctionName
     : IF | LOCALTIME | LOCALTIMESTAMP | REPLACE | INTERVAL | MOD
     | DATABASE | SCHEMA | LEFT | RIGHT | DATE | DAY | GEOMETRYCOLLECTION
     | LINESTRING | MULTILINESTRING | MULTIPOINT | MULTIPOLYGON | POINT | 
POLYGON
-    | TIME | TIMESTAMP | TIMESTAMP_ADD | TIMESTAMP_DIFF | DATE | 
CURRENT_TIMESTAMP | identifier
+    | TIME | TIMESTAMP | TIMESTAMP_ADD | TIMESTAMP_DIFF | DATE | 
CURRENT_TIMESTAMP 
+    | CURRENT_DATE | CURRENT_TIME | identifier
     ;
     
 matchExpression
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 d7e30b2..390fdf7 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
@@ -3196,5 +3196,93 @@
             </select>
         </union>
     </select>
+
+    <select 
sql-case-id="select_current_date_function_with_shorthand_regular_function">
+        <projections start-index="7" stop-index="7">
+            <shorthand-projection start-index="7" stop-index="7" />
+        </projections>
+        <from>
+            <simple-table name="t_order" start-index="14" stop-index="20" />
+        </from>
+        <where start-index="22" stop-index="46">
+            <expr>
+                <binary-operation-expression start-index="28" stop-index="46">
+                    <left>
+                        <column name="date" start-index="28" stop-index="31"/>
+                    </left>
+                    <right>
+                        <expression-projection text="CURRENT_DATE" 
start-index="35" stop-index="46" />
+                    </right>
+                    <operator>=</operator>
+                </binary-operation-expression>
+            </expr>
+        </where>
+    </select>
+
+    <select 
sql-case-id="select_current_date_function_with_complete_regular_function">
+        <projections start-index="7" stop-index="7">
+            <shorthand-projection start-index="7" stop-index="7" />
+        </projections>
+        <from>
+            <simple-table name="t_order" start-index="14" stop-index="20" />
+        </from>
+        <where start-index="22" stop-index="48">
+            <expr>
+                <binary-operation-expression start-index="28" stop-index="48">
+                    <left>
+                        <column name="date" start-index="28" stop-index="31"/>
+                    </left>
+                    <right>
+                        <expression-projection text="CURRENT_DATE()" 
start-index="35" stop-index="48" />
+                    </right>
+                    <operator>=</operator>
+                </binary-operation-expression>
+            </expr>
+        </where>
+    </select>
+
+    <select 
sql-case-id="select_current_time_function_with_shorthand_regular_function">
+        <projections start-index="7" stop-index="7">
+            <shorthand-projection start-index="7" stop-index="7" />
+        </projections>
+        <from>
+            <simple-table name="t_order" start-index="14" stop-index="20" />
+        </from>
+        <where start-index="22" stop-index="46">
+            <expr>
+                <binary-operation-expression start-index="28" stop-index="46">
+                    <left>
+                        <column name="time" start-index="28" stop-index="31"/>
+                    </left>
+                    <right>
+                        <expression-projection text="CURRENT_TIME" 
start-index="35" stop-index="46" />
+                    </right>
+                    <operator>=</operator>
+                </binary-operation-expression>
+            </expr>
+        </where>
+    </select>
+
+    <select 
sql-case-id="select_current_time_function_with_complete_regular_function">
+        <projections start-index="7" stop-index="7">
+            <shorthand-projection start-index="7" stop-index="7" />
+        </projections>
+        <from>
+            <simple-table name="t_order" start-index="14" stop-index="20" />
+        </from>
+        <where start-index="22" stop-index="48">
+            <expr>
+                <binary-operation-expression start-index="28" stop-index="48">
+                    <left>
+                        <column name="time" start-index="28" stop-index="31"/>
+                    </left>
+                    <right>
+                        <expression-projection text="CURRENT_TIME()" 
start-index="35" stop-index="48" />
+                    </right>
+                    <operator>=</operator>
+                </binary-operation-expression>
+            </expr>
+        </where>
+    </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 b17e443..cb31cff 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
@@ -92,4 +92,8 @@
     <sql-case id="select_with_containers" value="SELECT * FROM 
CONTAINERS(employees)" db-types="Oracle" />
     <sql-case id="select_with_hierarchical_connect_by" value="SELECT 
last_name, employee_id, manager_id FROM employees CONNECT BY employee_id = 
manager_id ORDER BY last_name" db-types="Oracle" />
     <sql-case id="select_union" value="SELECT order_id FROM t_order UNION 
SELECT order_id FROM t_order_item" db-types="MySQL" />
+    <sql-case 
id="select_current_date_function_with_shorthand_regular_function" value="SELECT 
* FROM t_order WHERE date = CURRENT_DATE" db-types="MySQL"/>
+    <sql-case id="select_current_date_function_with_complete_regular_function" 
value="SELECT * FROM t_order WHERE date = CURRENT_DATE()" db-types="MySQL"/>
+    <sql-case 
id="select_current_time_function_with_shorthand_regular_function" value="SELECT 
* FROM t_order WHERE time = CURRENT_TIME" db-types="MySQL"/>
+    <sql-case id="select_current_time_function_with_complete_regular_function" 
value="SELECT * FROM t_order WHERE time = CURRENT_TIME()" db-types="MySQL"/>
 </sql-cases>

Reply via email to