You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by lu...@apache.org on 2020/09/29 01:48:15 UTC

[shardingsphere] branch master updated: Add SQLServer output clause test case. (#7654)

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

lujingshang 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 701c08f  Add SQLServer output clause test case. (#7654)
701c08f is described below

commit 701c08f16efcd4d4aaca7af904945ff627c69fa3
Author: Zonglei Dong <do...@apache.org>
AuthorDate: Tue Sep 29 09:47:46 2020 +0800

    Add SQLServer output clause test case. (#7654)
    
    * fixes collection empty condition.
    
    * add test case for SQLServer output clause without output table column.
    
    * add test case for SQLServer output clause without output table.
    
    * add test case for SQLServer output clause column shorthand.
    
    * fixes checkstyle problem.
---
 .../asserts/segment/output/OutputClauseAssert.java |  4 +-
 .../src/main/resources/case/dml/insert.xml         | 92 ++++++++++++++++++++--
 .../main/resources/sql/supported/dml/insert.xml    |  3 +
 3 files changed, 92 insertions(+), 7 deletions(-)

diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/output/OutputClauseAssert.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/output/OutputClauseAssert.java
index 66d2ec2..8018095 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/output/OutputClauseAssert.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/output/OutputClauseAssert.java
@@ -46,13 +46,13 @@ public final class OutputClauseAssert {
      */
     public static void assertIs(final SQLCaseAssertContext assertContext, final OutputSegment actual, final ExpectedOutputClause expected) {
         assertNotNull(assertContext.getText("Output clause should exist."), expected);
-        if (null != actual.getOutputColumns()) {
+        if (!actual.getOutputColumns().isEmpty()) {
             assertOutputColumnsSegment(assertContext, actual, expected);
         }
         if (null != actual.getTableName()) {
             assertOutputTableSegment(assertContext, actual, expected);
         }
-        if (null != actual.getTableColumns()) {
+        if (!actual.getTableColumns().isEmpty()) {
             assertOutputTableColumnSegment(assertContext, actual, expected);
         }
         SQLSegmentAssert.assertIs(assertContext, actual, expected);
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/insert.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/insert.xml
index c8a9f11..664392a 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/insert.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/insert.xml
@@ -1453,7 +1453,7 @@
             </value>
         </values>
     </insert>
-
+    
     <insert sql-case-id="insert_with_default_values">
         <table name="t_order" start-index="12" stop-index="18" />
         <columns start-index="20" stop-index="46">
@@ -1462,12 +1462,12 @@
             <column name="status" start-index="40" stop-index="45" />
         </columns>
     </insert>
-
+    
     <insert sql-case-id="insert_without_columns_with_default_values">
         <table name="t_order" start-index="12" stop-index="18" />
         <columns start-index="19" stop-index="19" />
     </insert>
-
+    
     <insert sql-case-id="insert_with_top">
         <table name="t_order" start-index="15" stop-index="21" />
         <columns start-index="23" stop-index="41">
@@ -1486,7 +1486,7 @@
             </projections>
         </select>
     </insert>
-
+    
     <insert sql-case-id="insert_with_top_percent">
         <table name="t_order" start-index="23" stop-index="29" />
         <columns start-index="31" stop-index="49">
@@ -1505,7 +1505,7 @@
             </projections>
         </select>
     </insert>
-
+    
     <insert sql-case-id="insert_with_output_clause" parameters="1, 1">
         <table name="t_order" start-index="12" stop-index="18" />
         <columns start-index="20" stop-index="38">
@@ -1540,4 +1540,86 @@
             </value>
         </values>
     </insert>
+    
+    <insert sql-case-id="insert_with_output_clause_without_output_table_columns" parameters="1, 1">
+        <table name="t_order" start-index="12" stop-index="18" />
+        <columns start-index="20" stop-index="38">
+            <column name="order_id" start-index="21" stop-index="28" />
+            <column name="user_id" start-index="31" stop-index="37" />
+        </columns>
+        <output start-index="40" stop-index="98">
+            <output-columns start-index="47" stop-index="81">
+                <column-projection name="order_id" start-index="47" stop-index="63">
+                    <owner name="INSERTED" start-index="47" stop-index="54"/>
+                </column-projection>
+                <column-projection name="user_id" start-index="66" stop-index="81">
+                    <owner name="INSERTED" start-index="66" stop-index="73"/>
+                </column-projection>
+            </output-columns>
+            <output-table name="@MyTableVar" start-index="88" stop-index="98"/>
+        </output>
+        <values>
+            <value>
+                <assignment-value>
+                    <parameter-marker-expression value="0" start-index="108" stop-index="108" />
+                    <literal-expression value="1" start-index="108" stop-index="108" />
+                </assignment-value>
+                <assignment-value>
+                    <parameter-marker-expression value="1" start-index="111" stop-index="111" />
+                    <literal-expression value="1" start-index="111" stop-index="111" />
+                </assignment-value>
+            </value>
+        </values>
+    </insert>
+    
+    <insert sql-case-id="insert_with_output_clause_without_output_table" parameters="1, 1">
+        <table name="t_order" start-index="12" stop-index="18" />
+        <columns start-index="20" stop-index="38">
+            <column name="order_id" start-index="21" stop-index="28" />
+            <column name="user_id" start-index="31" stop-index="37" />
+        </columns>
+        <output start-index="40" stop-index="81">
+            <output-columns start-index="47" stop-index="81">
+                <column-projection name="order_id" start-index="47" stop-index="63">
+                    <owner name="INSERTED" start-index="47" stop-index="54"/>
+                </column-projection>
+                <column-projection name="user_id" start-index="66" stop-index="81">
+                    <owner name="INSERTED" start-index="66" stop-index="73"/>
+                </column-projection>
+            </output-columns>
+        </output>
+        <values>
+            <value>
+                <assignment-value>
+                    <parameter-marker-expression value="0" start-index="91" stop-index="91" />
+                    <literal-expression value="1" start-index="91" stop-index="91" />
+                </assignment-value>
+                <assignment-value>
+                    <parameter-marker-expression value="1" start-index="94" stop-index="94" />
+                    <literal-expression value="1" start-index="94" stop-index="94" />
+                </assignment-value>
+            </value>
+        </values>
+    </insert>
+    
+    <insert sql-case-id="insert_with_output_clause_column_shorthand" parameters="1, 1">
+        <table name="t_order" start-index="12" stop-index="18" />
+        <columns start-index="20" stop-index="38">
+            <column name="order_id" start-index="21" stop-index="28" />
+            <column name="user_id" start-index="31" stop-index="37" />
+        </columns>
+        <output start-index="40" stop-index="56"/>
+        <values>
+            <value>
+                <assignment-value>
+                    <parameter-marker-expression value="0" start-index="66" stop-index="66" />
+                    <literal-expression value="1" start-index="66" stop-index="66" />
+                </assignment-value>
+                <assignment-value>
+                    <parameter-marker-expression value="1" start-index="69" stop-index="69" />
+                    <literal-expression value="1" start-index="69" stop-index="69" />
+                </assignment-value>
+            </value>
+        </values>
+    </insert>
 </sql-parser-test-cases>
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/insert.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/insert.xml
index 2adfbe0..2da1526 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/insert.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/insert.xml
@@ -73,4 +73,7 @@
     <sql-case id="insert_with_top_percent" value="INSERT TOP(10) PERCENT t_order (order_id, user_id) SELECT order_id, user_id FROM t_order" db-types="SQLServer" />
     <sql-case id="insert_with_columnname_uuid" value="insert into t_order (id,uuid) values (?, ?)" db-types="PostgreSQL" />
     <sql-case id="insert_with_output_clause" value="INSERT INTO t_order (order_id, user_id) OUTPUT INSERTED.order_id, INSERTED.user_id INTO @MyTableVar (temp_order_id, temp_user_id) VALUES (?, ?)" db-types="SQLServer" />
+    <sql-case id="insert_with_output_clause_without_output_table_columns" value="INSERT INTO t_order (order_id, user_id) OUTPUT INSERTED.order_id, INSERTED.user_id INTO @MyTableVar VALUES (?, ?)" db-types="SQLServer" />
+    <sql-case id="insert_with_output_clause_without_output_table" value="INSERT INTO t_order (order_id, user_id) OUTPUT INSERTED.order_id, INSERTED.user_id VALUES (?, ?)" db-types="SQLServer" />
+    <sql-case id="insert_with_output_clause_column_shorthand" value="INSERT INTO t_order (order_id, user_id) OUTPUT INSERTED.* VALUES (?, ?)" db-types="SQLServer" />
 </sql-cases>