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

zhonghongsheng 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 616f7c53564 Revise MissingRequiredTargetDatabaseException and check 
target database is exists (#30395)
616f7c53564 is described below

commit 616f7c5356464b6749dd0ff719ebaa9b38da1316
Author: Xinze Guo <[email protected]>
AuthorDate: Wed Mar 6 09:53:16 2024 +0800

    Revise MissingRequiredTargetDatabaseException and check target database is 
exists (#30395)
    
    * Check targetDatabaseName is valid
    
    * Revise MissingRequiredTargetDatabaseException
---
 docs/document/content/user-manual/error-code/sql-error-code.cn.md | 2 +-
 docs/document/content/user-manual/error-code/sql-error-code.en.md | 2 +-
 .../exception/job/MissingRequiredTargetDatabaseException.java     | 4 ++--
 .../migration/distsql/handler/update/MigrateTableExecutor.java    | 8 ++------
 4 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md 
b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index 31b94c7c38c..59bbbefa6aa 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -114,7 +114,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 
|-----------|-------------|------------------------------------------------------------------------------------|
 | 42S02     | 18002       | There is no rule in database \`%s\`.               
                                |
 | 44000     | 18003       | Mode configuration does not exist.                 
                                |
-| 44000     | 18004       | Target database name is null. You could define it 
in DistSQL or select a database. |
+| 44000     | 18004       | Target database \`%s\` isn't exist.                
                                |
 | 22023     | 18005       | There is invalid parameter value: `%s`.            
                                |
 | HY000     | 18020       | Failed to get DDL for table \`%s\`.                
                                |
 | 42S01     | 18030       | Duplicate storage unit names \`%s\`.               
                                |
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md 
b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index 75a77c5e0d4..6bf3929ffca 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -114,7 +114,7 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 
|-----------|-------------|------------------------------------------------------------------------------------|
 | 42S02     | 18002       | There is no rule in database \`%s\`.               
                                |
 | 44000     | 18003       | Mode configuration does not exist.                 
                                |
-| 44000     | 18004       | Target database name is null. You could define it 
in DistSQL or select a database. |
+| 44000     | 18004       | Target database \`%s\` isn't exist.                
                                |
 | 22023     | 18005       | There is invalid parameter value: `%s`.            
                                |
 | HY000     | 18020       | Failed to get DDL for table \`%s\`.                
                                |
 | 42S01     | 18030       | Duplicate storage unit names \`%s\`.               
                                |
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/MissingRequiredTargetDatabaseException.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/MissingRequiredTargetDatabaseException.java
index f0556b64dcd..ea04b5962fa 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/MissingRequiredTargetDatabaseException.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/MissingRequiredTargetDatabaseException.java
@@ -27,7 +27,7 @@ public final class MissingRequiredTargetDatabaseException 
extends PipelineSQLExc
     
     private static final long serialVersionUID = -1557471818392592482L;
     
-    public MissingRequiredTargetDatabaseException() {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 4, "Target database name 
is null. You could define it in DistSQL or select a database.");
+    public MissingRequiredTargetDatabaseException(final String databaseName) {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 4, String.format("Target 
database `%s` isn't exist.", databaseName));
     }
 }
diff --git 
a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/migration/distsql/handler/update/MigrateTableExecutor.java
 
b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/migration/distsql/handler/update/MigrateTableExecutor.java
index 78bc1f23677..e1a9d302135 100644
--- 
a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/migration/distsql/handler/update/MigrateTableExecutor.java
+++ 
b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/migration/distsql/handler/update/MigrateTableExecutor.java
@@ -46,17 +46,13 @@ public final class MigrateTableExecutor implements 
DistSQLUpdateExecutor<Migrate
         InstanceContext instanceContext = contextManager.getInstanceContext();
         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();
+        
ShardingSpherePreconditions.checkState(contextManager.getMetaDataContexts().getMetaData().containsDatabase(targetDatabaseName),
+                () -> new 
MissingRequiredTargetDatabaseException(sqlStatement.getTargetDatabaseName()));
         MigrationJobAPI jobAPI = (MigrationJobAPI) 
TypedSPILoader.getService(TransmissionJobAPI.class, "MIGRATION");
         jobAPI.start(new PipelineContextKey(InstanceType.PROXY), new 
MigrateTableStatement(sqlStatement.getSourceTargetEntries(), 
targetDatabaseName));
     }
     
-    private void checkTargetDatabase(final MigrateTableStatement sqlStatement) 
{
-        String targetDatabaseName = null == 
sqlStatement.getTargetDatabaseName() ? database.getName() : 
sqlStatement.getTargetDatabaseName();
-        ShardingSpherePreconditions.checkNotNull(targetDatabaseName, 
MissingRequiredTargetDatabaseException::new);
-    }
-    
     @Override
     public Class<MigrateTableStatement> getType() {
         return MigrateTableStatement.class;

Reply via email to