strongduanmu commented on a change in pull request #11445:
URL: https://github.com/apache/shardingsphere/pull/11445#discussion_r674719369



##########
File path: 
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DMLStatement.g4
##########
@@ -138,8 +138,12 @@ queryExpression
 
 queryExpressionBody
     : queryPrimary
-    | queryExpressionParens UNION unionOption? (queryPrimary | 
queryExpressionParens)
-    | queryExpressionBody UNION unionOption? (queryPrimary | 
queryExpressionParens)
+    | queryExpressionParens unionClaus

Review comment:
       `unionClause` is better.

##########
File path: 
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
##########
@@ -605,7 +608,21 @@ public ASTNode visitQueryExpressionBody(final 
QueryExpressionBodyContext ctx) {
         if (1 == ctx.getChildCount() && ctx.getChild(0) instanceof 
QueryPrimaryContext) {
             return visit(ctx.queryPrimary());
         }
-        throw new IllegalStateException("union select is not supported yet.");
+        if (null != ctx.queryExpressionBody()) {
+            MySQLSelectStatement result = (MySQLSelectStatement) 
visit(ctx.queryExpressionBody());
+            result.getUnionSegments().add((UnionSegment) 
visitUnionClaus(ctx.unionClaus()));
+            return result;
+        }
+        MySQLSelectStatement result = (MySQLSelectStatement) 
visit(ctx.queryExpressionParens());
+        result.getUnionSegments().add((UnionSegment) 
visitUnionClaus(ctx.unionClaus()));
+        return result;
+    }
+    
+    @Override
+    public ASTNode visitUnionClaus(final UnionClausContext ctx) {
+        return new UnionSegment((null != ctx.unionOption() && null != 
ctx.unionOption().ALL()) ? UnionType.UNION_ALL : UnionType.UNION_DISTINCT,

Review comment:
       Please extract a variable to avoid the complexity of UnionSegment 
initialization.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to