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 2022/01/13 15:32:46 UTC

[shardingsphere] branch master updated: Optimize the parsing rules of some MySQL DAL. (#14750)

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 2439e2e  Optimize the parsing rules of some MySQL DAL. (#14750)
2439e2e is described below

commit 2439e2e08a74b5f3721f42320aa1d9fa409b3e4b
Author: Guocheng Tang <to...@qq.com>
AuthorDate: Thu Jan 13 23:31:51 2022 +0800

    Optimize the parsing rules of some MySQL DAL. (#14750)
    
    * Optimize the parsing rules of some MySQL DAL.
    
    * Fix wrong module name.
---
 .../pom.xml                                                           | 2 +-
 .../validator/ddl/impl/ShardingRenameTableStatementValidator.java     | 2 +-
 .../src/main/antlr4/imports/mysql/DALStatement.g4                     | 4 +++-
 .../mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java     | 2 +-
 .../sql/dialect/statement/mysql/dal/MySQLCacheIndexStatement.java     | 2 +-
 .../parser/sql/dialect/statement/mysql/dal/MySQLKillStatement.java    | 2 +-
 .../sql/dialect/statement/mysql/dal/MySQLLoadIndexInfoStatement.java  | 2 +-
 .../sql/dialect/statement/mysql/segment/LoadTableIndexSegment.java    | 4 ++--
 .../parameterized/asserts/statement/dal/impl/KillStatementAssert.java | 2 +-
 .../jaxb/cases/domain/statement/dal/KillStatementTestCase.java        | 4 ++--
 .../shardingsphere-parser-test/src/main/resources/case/dal/kill.xml   | 2 +-
 .../shardingsphere-parser-test/src/main/resources/case/dal/reset.xml  | 2 ++
 .../src/main/resources/sql/supported/dal/kill.xml                     | 2 +-
 .../src/main/resources/sql/supported/dal/reset.xml                    | 2 ++
 14 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/pom.xml b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mix [...]
index 432f4c2..1c7216d 100644
--- a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/pom.xml
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/pom.xml
@@ -25,7 +25,7 @@
         <version>${revision}</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-    <artifactId>shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-example</artifactId>
+    <artifactId>shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example</artifactId>
     <name>${project.artifactId}</name>
     
     <dependencies>
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingRenameTableStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingRenameTableStatementValidator.java
index 30855fe..fb57607 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingRenameTableStatementValidator.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingRenameTableStatementValidator.java
@@ -34,7 +34,7 @@ import java.util.List;
 import java.util.stream.Collectors;
 
 /**
- * Sharding alter table statement validator.
+ * Sharding rename table statement validator.
  */
 public final class ShardingRenameTableStatementValidator extends ShardingDDLStatementValidator<RenameTableStatement> {
     
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DALStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DALStatement.g4
index 4e4be9f..a1e1c54 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DALStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DALStatement.g4
@@ -372,7 +372,7 @@ tablesOption
     ;
 
 kill
-    : KILL (CONNECTION | QUERY)? NUMBER_+
+    : KILL (CONNECTION | QUERY)? NUMBER_
     ;
 
 loadIndexInfo
@@ -391,6 +391,8 @@ resetStatement
 resetOption
     : MASTER (TO binaryLogFileIndexNumber)?
     | SLAVE ALL? channelOption?
+    | REPLICA
+    | QUERY CACHE
     ;
 
 resetPersist
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/MySQLDALStatementSQLVisitor.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/MySQLDALStatementSQLVisitor.java
index 2d54060..3fe4281 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/MySQLDALStatementSQLVisitor.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/MySQLDALStatementSQLVisitor.java
@@ -445,7 +445,7 @@ public final class MySQLDALStatementSQLVisitor extends MySQLStatementSQLVisitor
     @Override
     public ASTNode visitKill(final KillContext ctx) {
         MySQLKillStatement result = new MySQLKillStatement();
-        result.setThreadId(ctx.NUMBER_().get(0).getText());
+        result.setProcesslistId(ctx.getText());
         return result;
     }
     
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLCacheIndexStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLCacheIndexStatement.java
index 8163b6f..5f89dbe 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLCacheIndexStatement.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLCacheIndexStatement.java
@@ -37,7 +37,7 @@ import java.util.LinkedList;
 @ToString
 public final class MySQLCacheIndexStatement extends AbstractSQLStatement implements DALStatement, MySQLStatement {
 
-    private Collection<CacheTableIndexSegment> tableIndexes = new LinkedList<>();
+    private final Collection<CacheTableIndexSegment> tableIndexes = new LinkedList<>();
     
     @Setter
     private PartitionDefinitionSegment partitionDefinition;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLKillStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLKillStatement.java
index eb48683..11b1d624 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLKillStatement.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLKillStatement.java
@@ -32,5 +32,5 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLSta
 @ToString
 public final class MySQLKillStatement extends AbstractSQLStatement implements DALStatement, MySQLStatement {
 
-    private String threadId;
+    private String processlistId;
 }
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLLoadIndexInfoStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLLoadIndexInfoStatement.java
index b5f4cd9..89231df 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLLoadIndexInfoStatement.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLLoadIndexInfoStatement.java
@@ -34,5 +34,5 @@ import java.util.LinkedList;
 @ToString
 public final class MySQLLoadIndexInfoStatement extends AbstractSQLStatement implements DALStatement, MySQLStatement {
     
-    private Collection<LoadTableIndexSegment> tableIndexes = new LinkedList<>();
+    private final Collection<LoadTableIndexSegment> tableIndexes = new LinkedList<>();
 }
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/segment/LoadTableIndexSegment.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/segment/LoadTableIndexSegment.java
index 157408c..d63f317 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/segment/LoadTableIndexSegment.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/segment/LoadTableIndexSegment.java
@@ -30,9 +30,9 @@ import java.util.LinkedList;
 @Getter
 public final class LoadTableIndexSegment extends TableIndexSegment {
     
-    private Collection<IndexSegment> indexes = new LinkedList<>();
+    private final Collection<IndexSegment> indexes = new LinkedList<>();
     
-    private Collection<PartitionSegment> partitions = new LinkedList<>();
+    private final Collection<PartitionSegment> partitions = new LinkedList<>();
     
     public LoadTableIndexSegment(final int startIndex, final int stopIndex, final SimpleTableSegment table) {
         super(startIndex, stopIndex, table);
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/KillStatementAssert.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/KillStatementAssert.java
index 9600c29..cc347e8 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/KillStatementAssert.java
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/KillStatementAssert.java
@@ -40,6 +40,6 @@ public final class KillStatementAssert {
      * @param expected expected kill statement test case
      */
     public static void assertIs(final SQLCaseAssertContext assertContext, final MySQLKillStatement actual, final KillStatementTestCase expected) {
-        assertThat(assertContext.getText("Kill statement context does not match: "), actual.getThreadId(), is(expected.getThreadId()));
+        assertThat(assertContext.getText("Kill statement context does not match: "), actual.getProcesslistId(), is(expected.getProcesslistId()));
     }
 }
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/KillStatementTestCase.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/KillStatementTestCase.java
index 8f77f7d..9bab14d 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/KillStatementTestCase.java
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/KillStatementTestCase.java
@@ -28,6 +28,6 @@ import javax.xml.bind.annotation.XmlAttribute;
 @Getter
 public final class KillStatementTestCase extends SQLParserTestCase {
 
-    @XmlAttribute(name = "thread-id")
-    private String threadId;
+    @XmlAttribute(name = "processlist-id")
+    private String processlistId;
 }
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/kill.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/kill.xml
index c15ac99..1b73543 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/kill.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/kill.xml
@@ -17,5 +17,5 @@
   -->
 
 <sql-parser-test-cases>
-    <kill sql-case-id="kill_thread_id" thread-id="2"/>
+    <kill sql-case-id="kill_processlist_id" processlist-id="2"/>
 </sql-parser-test-cases>
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/reset.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/reset.xml
index e9c7b3c..8265e9d 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/reset.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/reset.xml
@@ -41,6 +41,8 @@
     <reset sql-case-id="reset_slave_with_all_channel">
         <option master="false" all="true" channel="TEST_CHANNEL" start-index="6" stop-index="41"/>
     </reset>
+    <reset sql-case-id="reset_query_cache" />
+    <reset sql-case-id="reset_replica" />
     <reset-persist sql-case-id="reset_persist"/>
     <reset-persist sql-case-id="reset_persist_identifier" identifier="TEST_ID"/>
     <reset-persist sql-case-id="reset_persist_exist_identifier" exist-clause="true" identifier="TEST_ID"/>
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/kill.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/kill.xml
index 107ce25..4572393 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/kill.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/kill.xml
@@ -17,5 +17,5 @@
   -->
 
 <sql-cases>
-    <sql-case id="kill_thread_id" value="KILL 2" db-types="MySQL" />
+    <sql-case id="kill_processlist_id" value="KILL 2" db-types="MySQL" />
 </sql-cases>
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/reset.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/reset.xml
index f8bbf88..e4d13e1 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/reset.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/reset.xml
@@ -26,6 +26,8 @@
     <sql-case id="reset_slave_with_all" value="RESET SLAVE ALL" db-types="MySQL"/>
     <sql-case id="reset_slave_with_channel" value="RESET SLAVE FOR CHANNEL 'TEST_CHANNEL'" db-types="MySQL"/>
     <sql-case id="reset_slave_with_all_channel" value="RESET SLAVE ALL FOR CHANNEL 'TEST_CHANNEL'" db-types="MySQL"/>
+    <sql-case id="reset_query_cache" value="RESET QUERY CACHE" db-types="MySQL"/>
+    <sql-case id="reset_replica" value="RESET REPLICA" db-types="MySQL"/>
     <sql-case id="reset_persist" value="RESET PERSIST" db-types="MySQL"/>
     <sql-case id="reset_persist_identifier" value="RESET PERSIST TEST_ID" db-types="MySQL"/>
     <sql-case id="reset_persist_exist_identifier" value="RESET PERSIST IF EXISTS TEST_ID" db-types="MySQL"/>