You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/05/27 04:08:49 UTC

[shardingsphere] branch master updated: fix exist projection subquery visit error (#10496)

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

menghaoran 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 d6f897a  fix exist projection subquery visit error (#10496)
d6f897a is described below

commit d6f897a827f8976f314ec1b0891760f4977b72b0
Author: Zhengqiang Duan <st...@gmail.com>
AuthorDate: Thu May 27 12:08:09 2021 +0800

    fix exist projection subquery visit error (#10496)
---
 .../statement/impl/MySQLStatementSQLVisitor.java        |  5 +++++
 .../src/main/resources/case/dml/select-sub-query.xml    | 17 +++++++++++++++++
 .../resources/sql/supported/dml/select-sub-query.xml    |  7 ++++---
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/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 b/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
index f6acf26..e5ea5c5 100644
--- a/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
+++ b/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
@@ -1189,6 +1189,11 @@ public abstract class MySQLStatementSQLVisitor extends MySQLStatementBaseVisitor
             result.setAlias(alias);
             return result;
         }
+        if (exprProjection instanceof ExistsSubqueryExpression) {
+            SubqueryProjectionSegment result = new SubqueryProjectionSegment(((ExistsSubqueryExpression) exprProjection).getSubquery());
+            result.setAlias(alias);
+            return result;
+        }
         return createProjection(ctx, alias, exprProjection);
     }
     
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/select-sub-query.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/select-sub-query.xml
index 05ff450..90cce5c 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/select-sub-query.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/select-sub-query.xml
@@ -221,4 +221,21 @@
             </expr>
         </where>
     </select>
+    
+    <select sql-case-id="select_with_exists_sub_query_with_project">
+        <projections start-index="7" stop-index="36">
+            <subquery-projection start-index="14" stop-index="36">
+                <subquery start-index="15" stop-index="35">
+                    <select>
+                        <from>
+                            <simple-table name="t_order" start-index="29" stop-index="35" />
+                        </from>
+                        <projections start-index="43" stop-index="43">
+                            <expression-projection start-index="43" stop-index="43" text="1"/>
+                        </projections>
+                    </select>
+                </subquery>
+            </subquery-projection>
+        </projections>
+    </select>
 </sql-parser-test-cases>
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select-sub-query.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select-sub-query.xml
index 962de5d..a189834 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select-sub-query.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select-sub-query.xml
@@ -17,9 +17,10 @@
   -->
 
 <sql-cases>
-    <sql-case id="select_sub_query_with_project" value="SELECT order_id, (select 1) as num FROM t_order" />
+    <sql-case id="select_sub_query_with_project" value="SELECT order_id, (SELECT 1) AS num FROM t_order" />
     <sql-case id="select_sub_query_with_table" value="SELECT t.* FROM (SELECT * FROM t_order WHERE order_id IN (?, ?)) t" />
     <sql-case id="select_with_equal_subquery" value="SELECT * FROM t_order WHERE user_id = (SELECT user_id FROM t_order_item WHERE id = 10)" db-types="MySQL" />
-    <sql-case id="select_with_in_subquery" value="SELECT * FROM t_order WHERE user_id in (SELECT user_id FROM t_order_item WHERE id in (10, 11))" db-types="MySQL" />
-    <sql-case id="select_with_between_subquery" value="SELECT * FROM t_order WHERE user_id between (select user_id from t_order_item where order_id = 10) and ?" db-types="MySQL" />
+    <sql-case id="select_with_in_subquery" value="SELECT * FROM t_order WHERE user_id IN (SELECT user_id FROM t_order_item WHERE id IN (10, 11))" db-types="MySQL" />
+    <sql-case id="select_with_between_subquery" value="SELECT * FROM t_order WHERE user_id BETWEEN (SELECT user_id FROM t_order_item WHERE order_id = 10) AND ?" db-types="MySQL" />
+    <sql-case id="select_with_exists_sub_query_with_project" value="SELECT EXISTS (SELECT 1 FROM t_order)" db-types="MySQL,PostgreSQL" />
 </sql-cases>