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 599aac1bf5d Support mysql intersect combine operation sql parse 
(#29438)
599aac1bf5d is described below

commit 599aac1bf5d20952d36c02653d3a8bcc36589e68
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Mon Dec 18 19:24:42 2023 +0800

    Support mysql intersect combine operation sql parse (#29438)
---
 .../sql/dialect/mysql/src/main/antlr4/imports/mysql/DMLStatement.g4 | 3 ++-
 .../sql/dialect/mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4 | 4 ++++
 .../sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java   | 4 +++-
 .../parser/src/main/resources/sql/supported/dml/select-combine.xml  | 6 +++---
 4 files changed, 12 insertions(+), 5 deletions(-)

diff --git 
a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/DMLStatement.g4 
b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/DMLStatement.g4
index 0b5b173348b..81e81b54b1b 100644
--- a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/DMLStatement.g4
+++ b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/DMLStatement.g4
@@ -143,7 +143,8 @@ queryExpressionBody
     ;
 
 combineClause
-    : UNION combineOption? (queryPrimary | queryExpressionParens)
+    : INTERSECT combineOption? (queryPrimary | queryExpressionParens)
+    | UNION combineOption? (queryPrimary | queryExpressionParens)
     | EXCEPT combineOption? (queryPrimary | queryExpressionParens)
     ;
 
diff --git 
a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4 
b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4
index 956365d61de..323eb018bac 100644
--- a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4
+++ b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4
@@ -1083,6 +1083,10 @@ INTEGER
     : I N T E G E R
     ;
 
+INTERSECT
+    : I N T E R S E C T
+    ;
+
 INTERVAL
     : I N T E R V A L
     ;
diff --git 
a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
 
b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
index df103b18f87..213d64a23e8 100644
--- 
a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
+++ 
b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
@@ -48,8 +48,8 @@ import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.Combine
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CompleteRegularFunctionContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ConstraintNameContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ConvertFunctionContext;
-import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CurrentUserFunctionContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CteClauseContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CurrentUserFunctionContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DataTypeContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DeleteContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DuplicateSpecificationContext;
@@ -786,6 +786,8 @@ public abstract class MySQLStatementVisitor extends 
MySQLStatementBaseVisitor<AS
         CombineType combineType;
         if (null != ctx.EXCEPT()) {
             combineType = CombineType.EXCEPT;
+        } else if (null != ctx.INTERSECT()) {
+            combineType = CombineType.INTERSECT;
         } else {
             combineType = null == ctx.combineOption() || null == 
ctx.combineOption().ALL() ? CombineType.UNION : CombineType.UNION_ALL;
         }
diff --git 
a/test/it/parser/src/main/resources/sql/supported/dml/select-combine.xml 
b/test/it/parser/src/main/resources/sql/supported/dml/select-combine.xml
index 21f2e552739..d1d5d13f34a 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/select-combine.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/select-combine.xml
@@ -22,9 +22,9 @@
     <sql-case id="select_union_all" value="SELECT * FROM table1 UNION ALL 
SELECT * FROM table2" db-types="MySQL,PostgreSQL,openGauss" />
     <sql-case id="select_union_all_order_by" value="SELECT * FROM table1 UNION 
ALL SELECT * FROM table2 ORDER BY id" db-types="MySQL,PostgreSQL,openGauss" />
     <sql-case id="select_union_all_order_by_limit" value="SELECT * FROM table1 
UNION ALL SELECT * FROM table2 ORDER BY id LIMIT 1, 1" 
db-types="MySQL,openGauss" />
-    <sql-case id="select_intersect" value="SELECT * FROM table1 INTERSECT 
SELECT * FROM table2 INTERSECT SELECT * FROM table3" 
db-types="PostgreSQL,openGauss" />
-    <sql-case id="select_intersect_order_by" value="SELECT * FROM table1 
INTERSECT SELECT * FROM table2 INTERSECT SELECT * FROM table3 ORDER BY id" 
db-types="PostgreSQL,openGauss" />
-    <sql-case id="select_intersect_order_by_limit" value="SELECT * FROM table1 
INTERSECT SELECT * FROM table2 INTERSECT SELECT * FROM table3 ORDER BY id LIMIT 
1, 1" db-types="openGauss" />
+    <sql-case id="select_intersect" value="SELECT * FROM table1 INTERSECT 
SELECT * FROM table2 INTERSECT SELECT * FROM table3" 
db-types="MySQL,PostgreSQL,openGauss" />
+    <sql-case id="select_intersect_order_by" value="SELECT * FROM table1 
INTERSECT SELECT * FROM table2 INTERSECT SELECT * FROM table3 ORDER BY id" 
db-types="MySQL,PostgreSQL,openGauss" />
+    <sql-case id="select_intersect_order_by_limit" value="SELECT * FROM table1 
INTERSECT SELECT * FROM table2 INTERSECT SELECT * FROM table3 ORDER BY id LIMIT 
1, 1" db-types="MySQL,openGauss" />
     <sql-case id="select_except" value="SELECT * FROM table1 EXCEPT ALL SELECT 
* FROM table2 EXCEPT ALL SELECT * FROM table3" db-types="PostgreSQL,openGauss" 
/>
     <sql-case id="select_except_order_by" value="SELECT * FROM table1 EXCEPT 
ALL SELECT * FROM table2 EXCEPT ALL SELECT * FROM table3 ORDER BY id" 
db-types="PostgreSQL,openGauss" />
     <sql-case id="select_except_order_by_limit" value="SELECT * FROM table1 
EXCEPT ALL SELECT * FROM table2 EXCEPT ALL SELECT * FROM table3 ORDER BY id 
LIMIT 1, 1" db-types="openGauss" />

Reply via email to