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

zhangliang 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 bff566d  fix select from dual parse error (#11175)
bff566d is described below

commit bff566db866115d04e9ce5828d63dfc8be42dc5f
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Tue Jul 6 20:14:13 2021 +0800

    fix select from dual parse error (#11175)
---
 .../mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java      | 2 +-
 .../src/main/resources/case/dml/select.xml                          | 6 ++++++
 .../src/main/resources/sql/supported/dml/select.xml                 | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

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 e2d6f8d..306c976 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
@@ -614,7 +614,7 @@ public abstract class MySQLStatementSQLVisitor extends 
MySQLStatementBaseVisitor
         if (null != ctx.selectSpecification()) {
             result.getProjections().setDistinctRow(isDistinct(ctx));
         }
-        if (null != ctx.fromClause()) {
+        if (null != ctx.fromClause() && null != 
ctx.fromClause().tableReferences()) {
             TableSegment tableSource = (TableSegment) 
visit(ctx.fromClause().tableReferences());
             result.setFrom(tableSource);
         }
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
index f11da60..6950720 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
@@ -2915,5 +2915,11 @@
             <simple-table name="t_order" start-index="38" stop-index="44" />
         </from>
     </select>
+
+    <select sql-case-id="select_from_dual" >
+        <projections start-index="7" stop-index="7">
+            <expression-projection text="1" start-index="7" stop-index="7" />
+        </projections>
+    </select>
 </sql-parser-test-cases>
 
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select.xml
index 9677647..dd73b76 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select.xml
@@ -80,4 +80,5 @@
     <sql-case id="select_with_jsonb_path_contain_any_value" value="SELECT 
content_json::jsonb @?'$.keyword[*]?(@==&quot;ss&quot;)' FROM tb_content_json" 
db-types="PostgreSQL" />
     <sql-case id="select_with_jsonb_path_predicate_check" value="SELECT 
content_json::jsonb@@'$.keyword[*]==&quot;ss&quot;' FROM tb_content_json" 
db-types="PostgreSQL" />
     <sql-case id="select_with_assignment_operator" value="SELECT @rn := 1, 
@now_code := '' FROM t_order" db-types="MySQL" />
+    <sql-case id="select_from_dual" value="SELECT 1 FROM DUAL" 
db-types="MySQL" />
 </sql-cases>

Reply via email to