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 2020/10/30 06:16:41 UTC

[shardingsphere] branch master updated: fix PostgreSQL union syntax definition (#7959)

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 7de0b93  fix PostgreSQL union syntax definition (#7959)
7de0b93 is described below

commit 7de0b9367ab5e227e2a0873bb441bfa0e64bf111
Author: JingShang Lu <lu...@apache.org>
AuthorDate: Fri Oct 30 14:16:20 2020 +0800

    fix PostgreSQL union syntax definition (#7959)
    
    * fix #7948
    
    * fix
---
 .../src/main/antlr4/imports/postgresql/DMLStatement.g4              | 6 +++---
 .../asserts/statement/dml/impl/SelectStatementAssert.java           | 3 +++
 .../src/main/resources/case/dml/select.xml                          | 3 +++
 .../src/main/resources/sql/supported/dml/select.xml                 | 1 +
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
index d5cfcfe..3fc7114 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
@@ -122,9 +122,9 @@ selectNoParens
 selectClauseN
     : simpleSelect
     | selectWithParens
-    | selectClauseN UNION allOrDistinct selectClauseN
-    | selectClauseN INTERSECT allOrDistinct selectClauseN
-    | selectClauseN EXCEPT allOrDistinct selectClauseN
+    | selectClauseN UNION allOrDistinct? selectClauseN
+    | selectClauseN INTERSECT allOrDistinct? selectClauseN
+    | selectClauseN EXCEPT allOrDistinct? selectClauseN
 	;
 
 simpleSelect
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dml/impl/SelectStatementAssert.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dml/impl/SelectStatementAssert.java
index fb75b8e..ac8ff2c 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dml/impl/SelectStatementAssert.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dml/impl/SelectStatementAssert.java
@@ -61,6 +61,9 @@ public final class SelectStatementAssert {
     }
     
     private static void assertProjection(final SQLCaseAssertContext assertContext, final SelectStatement actual, final SelectStatementTestCase expected) {
+        if (null == actual.getProjections() && 0 == expected.getProjections().getSize()) {
+            return;
+        }
         ProjectionAssert.assertIs(assertContext, actual.getProjections(), expected.getProjections());
     }
 
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 d777eeb..a47938a 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
@@ -22,6 +22,9 @@
             <expression-projection alias="a" start-index="7" stop-index="12" />
         </projections>
     </select>
+
+    <select sql-case-id="select_with_union">
+    </select>
     
     <select sql-case-id="select_with_function_name" >
         <projections start-index="7" stop-index="23">
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 0028f64..a7798a3 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
@@ -18,6 +18,7 @@
 
 <sql-cases>
     <sql-case id="select_constant_without_table" value="SELECT 1 as a" />
+    <sql-case id="select_with_union" value="SELECT * from table1 union select * from table2" db-types="PostgreSQL"/>
     <sql-case id="select_with_function_name" value="SELECT current_timestamp" db-types="MySQL"/>
     <sql-case id="select_with_same_table_name_and_alias" value="SELECT t_order.* FROM t_order t_order WHERE user_id = ? AND order_id = ?" />
     <sql-case id="select_with_same_table_name_and_alias_column_with_owner" value="SELECT t_order.order_id,t_order.user_id,status FROM t_order t_order WHERE t_order.user_id = ? AND order_id = ?" db-types="MySQL,H2"/>