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

panjuan 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 6c42d2b987a MIGRATE TABLE DistSQL support define schema name (#20406)
6c42d2b987a is described below

commit 6c42d2b987a1430c03ff8fefd6d253dab29d6e23
Author: Hongsheng Zhong <[email protected]>
AuthorDate: Mon Aug 22 19:17:59 2022 +0800

    MIGRATE TABLE DistSQL support define schema name (#20406)
    
    * Add schema support for MIGRATE TABLE DistSQL
    
    * Rename sourceDatabaseName to sourceResourceName
---
 .../distsql/handler/update/MigrateTableUpdater.java |  4 ++--
 .../main/antlr4/imports/migration/RALStatement.g4   |  6 +++++-
 .../core/MigrationDistSQLStatementVisitor.java      |  7 ++++++-
 .../distsql/statement/MigrateTableStatement.java    |  4 +++-
 .../api/pojo/CreateMigrationJobParameter.java       |  2 ++
 .../update/MigrateTableStatementAssert.java         |  3 ++-
 .../migration/MigrateTableStatementTestCase.java    |  7 +++++--
 .../src/main/resources/case/ral/migration.xml       | 21 ++++++++++++++++++---
 .../main/resources/sql/supported/ral/migration.xml  |  4 +++-
 9 files changed, 46 insertions(+), 12 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/MigrateTableUpdater.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/MigrateTableUpdater.java
index 45771d65713..78ac15136bb 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/MigrateTableUpdater.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/MigrateTableUpdater.java
@@ -40,8 +40,8 @@ public final class MigrateTableUpdater implements 
RALUpdater<MigrateTableStateme
     public void executeUpdate(final String databaseName, final 
MigrateTableStatement sqlStatement) {
         log.info("start migrate job by {}", sqlStatement);
         String targetDatabaseName = 
ObjectUtils.defaultIfNull(sqlStatement.getTargetDatabaseName(), databaseName);
-        CreateMigrationJobParameter createMigrationJobParameter = new 
CreateMigrationJobParameter(sqlStatement.getSourceDatabaseName(), 
sqlStatement.getSourceTableName(),
-                targetDatabaseName, sqlStatement.getTargetTableName());
+        CreateMigrationJobParameter createMigrationJobParameter = new 
CreateMigrationJobParameter(sqlStatement.getSourceResourceName(), 
sqlStatement.getSourceSchemaName(),
+                sqlStatement.getSourceTableName(), targetDatabaseName, 
sqlStatement.getTargetTableName());
         JOB_API.createJobAndStart(createMigrationJobParameter);
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/migration/RALStatement.g4
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/migration/RALStatement.g4
index 86db414cc83..762b1b3c0c7 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/migration/RALStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/migration/RALStatement.g4
@@ -72,7 +72,7 @@ jobId
     ;
 
 sourceTableName
-    : (owner DOT)? name
+    : owner DOT (schema DOT)? name
     ;
 
 targetTableName
@@ -83,6 +83,10 @@ owner
     : identifier
     ;
 
+schema
+    : identifier
+    ;
+
 name
     : identifier
     ;
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/migration/distsql/parser/core/MigrationDistSQLStatementVisitor.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/migration/distsql/parser/core/MigrationDistSQLStatementVisitor.java
index d9bb3669848..6ee7f7b3b35 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/migration/distsql/parser/core/MigrationDistSQLStatementVisitor.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/migration/distsql/parser/core/MigrationDistSQLStatementVisitor.java
@@ -100,7 +100,12 @@ public final class MigrationDistSQLStatementVisitor 
extends MigrationDistSQLStat
     public ASTNode visitMigrateTable(final MigrateTableContext ctx) {
         List<String> source = 
Splitter.on('.').splitToList(getIdentifierValue(ctx.sourceTableName()));
         List<String> target = 
Splitter.on('.').splitToList(getIdentifierValue(ctx.targetTableName()));
-        return new MigrateTableStatement(source.size() > 1 ? source.get(0) : 
null, source.get(source.size() - 1), target.size() > 1 ? target.get(0) : null, 
target.get(target.size() - 1));
+        String sourceResourceName = source.get(0);
+        String sourceSchemaName = 3 == source.size() ? source.get(1) : null;
+        String sourceTableName = source.get(source.size() - 1);
+        String targetDatabaseName = target.size() > 1 ? target.get(0) : null;
+        String targetTableName = target.get(target.size() - 1);
+        return new MigrateTableStatement(sourceResourceName, sourceSchemaName, 
sourceTableName, targetDatabaseName, targetTableName);
     }
     
     @Override
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/migration/distsql/statement/MigrateTableStatement.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/migration/distsql/statement/MigrateTableStatement.java
index c03314798e1..20413b33b77 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/migration/distsql/statement/MigrateTableStatement.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/migration/distsql/statement/MigrateTableStatement.java
@@ -30,7 +30,9 @@ import 
org.apache.shardingsphere.distsql.parser.statement.ral.scaling.UpdatableS
 @ToString
 public final class MigrateTableStatement extends UpdatableScalingRALStatement {
     
-    private final String sourceDatabaseName;
+    private final String sourceResourceName;
+    
+    private final String sourceSchemaName;
     
     private final String sourceTableName;
     
diff --git 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/pojo/CreateMigrationJobParameter.java
 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/pojo/CreateMigrationJobParameter.java
index b7183d87668..f4a55d5811e 100644
--- 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/pojo/CreateMigrationJobParameter.java
+++ 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/pojo/CreateMigrationJobParameter.java
@@ -26,6 +26,8 @@ public final class CreateMigrationJobParameter {
     
     private final String sourceResourceName;
     
+    private final String sourceSchemaName;
+    
     private final String sourceTableName;
     
     private final String targetDatabaseName;
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/migration/update/MigrateTableStatementAssert.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/migration/update/MigrateTableStatementAssert.java
index 37e194fe20a..9a07d0e891b 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/migration/update/MigrateTableStatementAssert.java
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/migration/update/MigrateTableStatementAssert.java
@@ -37,7 +37,8 @@ public final class MigrateTableStatementAssert {
      * @param expected expected migrate table statement test case
      */
     public static void assertIs(final SQLCaseAssertContext assertContext, 
final MigrateTableStatement actual, final MigrateTableStatementTestCase 
expected) {
-        assertThat(assertContext.getText("source database name does not 
match"), actual.getSourceDatabaseName(), is(expected.getSourceDatabaseName()));
+        assertThat(assertContext.getText("source database name does not 
match"), actual.getSourceResourceName(), is(expected.getSourceResourceName()));
+        assertThat(assertContext.getText("source schema name does not match"), 
actual.getSourceSchemaName(), is(expected.getSourceSchemaName()));
         assertThat(assertContext.getText("source table name does not match"), 
actual.getSourceTableName(), is(expected.getSourceTableName()));
         assertThat(assertContext.getText("target database name does not 
match"), actual.getTargetDatabaseName(), is(expected.getTargetDatabaseName()));
         assertThat(assertContext.getText("target table name does not match"), 
actual.getTargetTableName(), is(expected.getTargetTableName()));
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/migration/MigrateTableStatementTestCase.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/migration/MigrateTableStatementTestCase.java
index 1a5efeb317e..f4e4cbeeaef 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/migration/MigrateTableStatementTestCase.java
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/migration/MigrateTableStatementTestCase.java
@@ -30,12 +30,15 @@ import javax.xml.bind.annotation.XmlElement;
 @Setter
 public final class MigrateTableStatementTestCase extends SQLParserTestCase {
     
-    @XmlElement(name = "source-database-name")
-    private String sourceDatabaseName;
+    @XmlElement(name = "source-resource-name")
+    private String sourceResourceName;
     
     @XmlElement(name = "source-table-name")
     private String sourceTableName;
     
+    @XmlElement(name = "source-schema-name")
+    private String sourceSchemaName;
+    
     @XmlElement(name = "target-database-name")
     private String targetDatabaseName;
     
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/migration.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/migration.xml
index 764da08403d..58a472ff860 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/migration.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/migration.xml
@@ -37,14 +37,29 @@
         <job-id>123</job-id>
     </show-migration-status>
     
-    <migrate-table sql-case-id="migrate-table-without-target-db">
-        <source-database-name>ds_0</source-database-name>
+    <migrate-table sql-case-id="migrate-table-without-schema-target-db">
+        <source-resource-name>ds_0</source-resource-name>
+        <source-table-name>t_order</source-table-name>
+        <target-table-name>t_order</target-table-name>
+    </migrate-table>
+    
+    <migrate-table sql-case-id="migrate-table-with-schema">
+        <source-resource-name>ds_0</source-resource-name>
+        <source-schema-name>public</source-schema-name>
         <source-table-name>t_order</source-table-name>
         <target-table-name>t_order</target-table-name>
     </migrate-table>
     
     <migrate-table sql-case-id="migrate-table-with-target-db">
-        <source-database-name>ds_0</source-database-name>
+        <source-resource-name>ds_0</source-resource-name>
+        <source-table-name>t_order</source-table-name>
+        <target-database-name>sharding_db</target-database-name>
+        <target-table-name>t_order</target-table-name>
+    </migrate-table>
+    
+    <migrate-table sql-case-id="migrate-table-with-schema-target-db">
+        <source-resource-name>ds_0</source-resource-name>
+        <source-schema-name>public</source-schema-name>
         <source-table-name>t_order</source-table-name>
         <target-database-name>sharding_db</target-database-name>
         <target-table-name>t_order</target-table-name>
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/migration.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/migration.xml
index 879b78502f2..8800b67c993 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/migration.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/migration.xml
@@ -23,8 +23,10 @@
     <distsql-case id="show-migration-status" value="SHOW MIGRATION STATUS 
123;" />
     <distsql-case id="check-migration-with-type" value="CHECK MIGRATION 123 by 
TYPE(name='DEFAULT', PROPERTIES('test-property'='4'));" />
     
-    <distsql-case id="migrate-table-without-target-db" value="MIGRATE TABLE 
ds_0.t_order INTO t_order;" />
+    <distsql-case id="migrate-table-without-schema-target-db" value="MIGRATE 
TABLE ds_0.t_order INTO t_order;" />
+    <distsql-case id="migrate-table-with-schema" value="MIGRATE TABLE 
ds_0.public.t_order INTO t_order;" />
     <distsql-case id="migrate-table-with-target-db" value="MIGRATE TABLE 
ds_0.t_order INTO sharding_db.t_order;" />
+    <distsql-case id="migrate-table-with-schema-target-db" value="MIGRATE 
TABLE ds_0.public.t_order INTO sharding_db.t_order;" />
     <distsql-case id="stop-migration-source-writing" value="STOP MIGRATION 
SOURCE WRITING 123;" />
     <distsql-case id="restore-migration-source-writing" value="RESTORE 
MIGRATION SOURCE WRITING 123;" />
     <distsql-case id="apply-migration" value="APPLY MIGRATION 123;" />

Reply via email to