azexcy commented on code in PR #30395:
URL: https://github.com/apache/shardingsphere/pull/30395#discussion_r1512224144


##########
kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/migration/distsql/handler/update/MigrateTableExecutor.java:
##########
@@ -47,7 +49,15 @@ public void executeUpdate(final MigrateTableStatement 
sqlStatement, final Contex
         ShardingSpherePreconditions.checkState(instanceContext.isCluster(),
                 () -> new 
PipelineInvalidParameterException(String.format("Only `Cluster` is supported 
now, but current mode type is `%s`", 
instanceContext.getModeConfiguration().getType())));
         checkTargetDatabase(sqlStatement);
-        String targetDatabaseName = null == 
sqlStatement.getTargetDatabaseName() ? database.getName() : 
sqlStatement.getTargetDatabaseName();
+        String targetDatabaseName;
+        if (Strings.isNullOrEmpty(sqlStatement.getTargetDatabaseName())) {
+            targetDatabaseName = database.getName();
+        } else {
+            ShardingSphereDatabase targetDatabase = 
PipelineContextManager.getProxyContext().getContextManager().getDatabase(sqlStatement.getTargetDatabaseName());
+            ShardingSpherePreconditions.checkNotNull(targetDatabase, () -> new 
PipelineInvalidParameterException(String.format("Target database `%s` is not 
exists",
+                    sqlStatement.getTargetDatabaseName())));
+            targetDatabaseName = targetDatabase.getName();

Review Comment:
   Improved, I find `MIGRATE TABLE` DistSQL now must select database, just like 
   
   ```
   mysql> MIGRATE TABLE ds_0.t_order_copy INTO sharding_DB2.t_order;
   ERROR 1046 (3D000): No database selected
   mysql> use sharding_db
   Database changed
   ``` 
   So I improve the exception message and check the target database is really 
exists
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to