You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/02/16 13:27:48 UTC

[shardingsphere] branch master updated: add SQLServer query hint clause for update statement. (#9418)

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 3fb26e4  add SQLServer query hint clause for update statement. (#9418)
3fb26e4 is described below

commit 3fb26e4ecd93900e835617b75438b8a4fee7e373
Author: Zonglei Dong <do...@apache.org>
AuthorDate: Tue Feb 16 21:27:12 2021 +0800

    add SQLServer query hint clause for update statement. (#9418)
    
    * add SQLServer query hint clause for update statement.
    
    * add SQLServer test case for update query hint clause.
    
    Co-authored-by: Zonglei Dong <dz...@613.com>
---
 .../main/antlr4/imports/sqlserver/DMLStatement.g4  |  2 +-
 .../src/main/resources/case/dml/update.xml         | 29 ++++++++++++++++++++++
 .../main/resources/sql/supported/dml/update.xml    |  1 +
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4
index ca73773..9cced46 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4
@@ -36,7 +36,7 @@ insertSelectClause
     ;
 
 update
-    : withClause? UPDATE top? tableReferences setAssignmentsClause whereClause?
+    : withClause? UPDATE top? tableReferences setAssignmentsClause whereClause? (OPTION queryHint)?
     ;
 
 assignment
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/update.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/update.xml
index d7877c5..c999e36 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/update.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/update.xml
@@ -834,4 +834,33 @@
             </expr>
         </where>
     </update>
+
+    <update sql-case-id="update_with_query_hint" parameters="'update', 1">
+        <table start-index="7" stop-index="13">
+            <simple-table name="t_order" start-index="7" stop-index="13"/>
+        </table>
+        <set start-index="15" stop-index="28" literal-stop-index="35">
+            <assignment start-index="19" stop-index="28" literal-stop-index="35">
+                <column name="status" start-index="19" stop-index="24" />
+                <assignment-value>
+                    <parameter-marker-expression value="0" start-index="28" stop-index="28" />
+                    <literal-expression value="update" start-index="28" stop-index="35" />
+                </assignment-value>
+            </assignment>
+        </set>
+        <where start-index="30" stop-index="47" literal-start-index="37" literal-stop-index="54">
+            <expr>
+                <binary-operation-expression start-index="36" stop-index="47" literal-start-index="43" literal-stop-index="54">
+                    <left>
+                        <column name="order_id" start-index="36" stop-index="43" literal-start-index="43" literal-stop-index="50" />
+                    </left>
+                    <operator>=</operator>
+                    <right>
+                        <literal-expression value="1" start-index="54" stop-index="54" />
+                        <parameter-marker-expression value="1" start-index="47" stop-index="47" />
+                    </right>
+                </binary-operation-expression>
+            </expr>
+        </where>
+    </update>
 </sql-parser-test-cases>
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/update.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/update.xml
index a494dd7..0c21f57 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/update.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/update.xml
@@ -36,4 +36,5 @@
     <sql-case id="update_with_with_clause" value="WITH cte (order_id, user_id, status) AS (SELECT order_id, user_id, status FROM t_order) UPDATE t_order SET status = ? FROM t_order AS t JOIN cte AS c ON t.order_id = c.order_id WHERE c.order_id = ?" db-types="SQLServer" />
     <sql-case id="update_with_top" value="UPDATE TOP(10) t_order SET order_id = ? WHERE user_id = ?" db-types="SQLServer" />
     <sql-case id="update_with_top_percent" value="UPDATE TOP(10) PERCENT t_order SET order_id = ? WHERE user_id = ?" db-types="SQLServer" />
+    <sql-case id="update_with_query_hint" value="UPDATE t_order SET status = ? WHERE order_id = ? HASH GROUP" db-types="SQLServer" />
 </sql-cases>