You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by lu...@apache.org on 2022/06/01 10:30:30 UTC

[shardingsphere] branch master updated: optimize for MySQLFormat (#18120)

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

lujingshang 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 e0d3a29943c optimize for MySQLFormat (#18120)
e0d3a29943c is described below

commit e0d3a29943c415fe6240a92fbdf17496411b716f
Author: cheese8 <yi...@163.com>
AuthorDate: Wed Jun 1 18:30:24 2022 +0800

    optimize for MySQLFormat (#18120)
    
    * optimize for MySQL Format
    
    * Update MySQLParameterizedTest.java
---
 .../mysql/visitor/format/impl/MySQLFormatSQLVisitor.java  |  3 ++-
 .../sql/parser/mysql/MySQLParameterizedTest.java          | 15 +++++++++++++++
 2 files changed, 17 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/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 129b86e8c21..94f0fe40264 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
@@ -854,7 +854,8 @@ public abstract class MySQLFormatSQLVisitor extends MySQLStatementBaseVisitor<St
         String result = defaultResult();
         int childCount = node.getChildCount();
         for (int i = 0; i < childCount; i++) {
-            if (i != 0 && !"(".equals(node.getChild(i - 1).getText()) && !")".equals(node.getChild(i).getText()) && !"(".equals(node.getChild(i).getText())) {
+            if (i != 0 && !"(".equals(node.getChild(i - 1).getText()) && !".".equals(node.getChild(i - 1).getText())
+                    && !")".equals(node.getChild(i).getText()) && !"(".equals(node.getChild(i).getText()) && !".".equals(node.getChild(i).getText())) {
                 formatPrint(" ");
             }
             if (!shouldVisitNextChild(node, result)) {
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParameterizedTest.java
index 8bbf0191c02..16622e288b8 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParameterizedTest.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParameterizedTest.java
@@ -104,6 +104,21 @@ public final class MySQLParameterizedTest {
                         + "\t`submission_date` DATE,\n"
                         + "\tPRIMARY KEY (`runoob_id`)\n"
                         + ") ENGINE = InnoDB DEFAULT CHARSET = utf8"});
+        testUnits.add(new String[]{"select_with_column", 
+                "select id, name, age, count(table1.id) as n, (select id, name, age, sex from table2 where id=2) as sid, yyyy from table1 where id=1",        
+                "SELECT id ," 
+                        + " name , age , \n"
+                        + "\tCOUNT(table1.id) AS n, \n"
+                        + "\t(\n"
+                        + "\t\tSELECT id , name , age , \n"
+                        + "\t\t\tsex \n"
+                        + "\t\tFROM table2\n"
+                        + "\t\tWHERE \n"
+                        + "\t\t\tid = ?\n"
+                        + "\t) AS sid, yyyy \n"
+                        + "FROM table1\n"
+                        + "WHERE \n"
+                        + "\tid = ?;"});
     }
     
     private final String caseId;