You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/12/24 06:19:53 UTC

[shardingsphere] branch master updated: SQL parser to support empty SQL parsing (#8744)

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 58e2308  SQL parser to support empty SQL parsing (#8744)
58e2308 is described below

commit 58e2308b3633595416f34878148bcba0d4f3b8b8
Author: JingShang Lu <lu...@apache.org>
AuthorDate: Thu Dec 24 14:19:31 2020 +0800

    SQL parser to support empty SQL parsing (#8744)
    
    * fix #8697
---
 .../org/apache/shardingsphere/sql/parser/autogen/MySQLStatement.g4     | 1 +
 .../sql/parser/mysql/visitor/format/impl/MySQLFormatSQLVisitor.java    | 3 +++
 .../org/apache/shardingsphere/sql/parser/mysql/MySQLFormatTest.java    | 1 +
 3 files changed, 5 insertions(+)

diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/MySQLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/MySQLStatement.g4
index 225361f..4733f7b 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/MySQLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/MySQLStatement.g4
@@ -118,4 +118,5 @@ execute
     | unlock
     | xa
     ) (SEMI_ EOF? | EOF)
+    | EOF
     ;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/format/impl/MySQLFormatSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/format/impl/MySQLFormatSQLVisitor.java
index 172ae58..a495fd6 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/format/impl/MySQLFormatSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/format/impl/MySQLFormatSQLVisitor.java
@@ -695,6 +695,9 @@ public abstract class MySQLFormatSQLVisitor extends MySQLStatementBaseVisitor<St
     
     @Override
     public String visitTerminal(final TerminalNode node) {
+        if ("<EOF>".equals(node.getText())) {
+            return result.toString();
+        }
         if (upperCase) {
             formatPrint(node.getText().toUpperCase());
         } else {
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLFormatTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLFormatTest.java
index ccf6941..b53c4af 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLFormatTest.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLFormatTest.java
@@ -117,6 +117,7 @@ public final class MySQLFormatTest {
                 + "FROM t_order\n"
                 + "WHERE \n"
                 + "\torder_id = 1;"});
+        testUnits.add(new String[]{"only_comment", "/* c_zz_xdba_test_4 login */", ""});
     }
 
     private final String caseId;