You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ch...@apache.org on 2024/04/10 10:33:21 UTC

(shardingsphere) branch master updated: Refactor SQLTranslationException (#30833)

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

chengzhang 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 cd163feae5e Refactor SQLTranslationException (#30833)
cd163feae5e is described below

commit cd163feae5eed9a5f5371d736dffe0ddf93d4917
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Apr 10 18:33:14 2024 +0800

    Refactor SQLTranslationException (#30833)
    
    * Refactor UnsupportedTranslatedDatabaseException
    
    * Remove UnsupportedTranslatedDatabaseException
    
    * Remove UnsupportedTranslatedDatabaseException
    
    * Refactor SQLTranslationException
---
 .../content/user-manual/error-code/sql-error-code.cn.md     | 11 +++++------
 .../content/user-manual/error-code/sql-error-code.en.md     | 11 +++++------
 .../algorithm/core/exception/AlgorithmExecuteException.java |  2 +-
 .../UnsupportedAlgorithmOnDatabaseTypeException.java        | 13 ++++++-------
 .../calculator/CRC32SingleTableInventoryCalculator.java     |  6 +++---
 .../exception/UnsupportedTranslatedDatabaseException.java   |  2 +-
 6 files changed, 21 insertions(+), 24 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 979242955b6..d9a1c0798c6 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
@@ -38,7 +38,8 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 10402       | 42S02     | '%s' algorithm '%s' on %s is unregistered.                                          |
 | 10403       | 44000     | %s algorithms '%s' in database '%s' are still in used.                              |
 | 10404       | 44000     | Invalid %s algorithm configuration '%s'.                                            |
-| 10450       | HY000     | Algorithm '%s.%s' execute failed, reason is: %s.                                    |
+| 10410       | 0A000     | Unsupported %s.%s with database type '%s'.                                          |
+| 10440       | HY000     | Algorithm '%s.%s' execute failed, reason is: %s.                                    |
 | 10500       | 44000     | Invalid single rule configuration, reason is: %s.                                   |
 | 10501       | 42S02     | Single table '%s' does not exist.                                                   |
 | 10502       | HY000     | Can not load table with database name '%s' and data source name '%s', reason is: %s |
@@ -127,7 +128,6 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 18200       | HY000     | Before data record is '%s', after data record is '%s'.                         |
 | 18201       | 08000     | Data check table '%s' failed.                                                  |
 | 18202       | 0A000     | Unsupported pipeline database type '%s'.                                       |
-| 18210       | 0A000     | Unsupported '%s' data consistency calculate algorithm with database type '%s'. |
 | 18400       | 42S02     | Can not find stream data source table.                                         |
 | 18401       | 42S02     | Database '%s' does not exist.                                                  |
 | 18410       | 42S02     | CDC Login request body is empty.                                               |
@@ -204,10 +204,9 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 
 ### SQL 方言转换
 
-| Vendor Code | SQL State | 错误信息                                                |
-|-------------|-----------|-----------------------------------------------------|
-| 20440       | 42000     | Can not support database \`%s\` in SQL translation. |
-| 20441       | 42000     | Translation error, SQL is: %s                       |
+| Vendor Code | SQL State | 错误信息                                              |
+|-------------|-----------|---------------------------------------------------|
+| 20400       | 0A000     | Can not support database '%s' in SQL translation. |
 
 ### 流量治理
 
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 040515881a9..4a6ffb5776e 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
@@ -38,7 +38,8 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
 | 10402       | 42S02     | '%s' algorithm '%s' on %s is unregistered.                                          |
 | 10403       | 44000     | %s algorithms '%s' in database '%s' are still in used.                              |
 | 10404       | 44000     | Invalid %s algorithm configuration '%s'.                                            |
-| 10450       | HY000     | Algorithm '%s.%s' execute failed, reason is: %s.                                    |
+| 10410       | 0A000     | Unsupported %s.%s with database type '%s'.                                          |
+| 10440       | HY000     | Algorithm '%s.%s' execute failed, reason is: %s.                                    |
 | 10500       | 44000     | Invalid single rule configuration, reason is: %s.                                   |
 | 10501       | 42S02     | Single table '%s' does not exist.                                                   |
 | 10502       | HY000     | Can not load table with database name '%s' and data source name '%s', reason is: %s |
@@ -128,7 +129,6 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
 | 18200       | HY000     | Before data record is '%s', after data record is '%s'.                         |
 | 18201       | 08000     | Data check table '%s' failed.                                                  |
 | 18202       | 0A000     | Unsupported pipeline database type '%s'.                                       |
-| 18210       | 0A000     | Unsupported '%s' data consistency calculate algorithm with database type '%s'. |
 | 18400       | 42S02     | Can not find stream data source table.                                         |
 | 18401       | 42S02     | Database '%s' does not exist.                                                  |
 | 18410       | 42S02     | CDC Login request body is empty.                                               |
@@ -205,10 +205,9 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
 
 ### SQL Dialect Translator
 
-| Vendor Code | SQL State | Reason                                              |
-|-------------|-----------|-----------------------------------------------------|
-| 20440       | 42000     | Can not support database \`%s\` in SQL translation. |
-| 20441       | 42000     | Translation error, SQL is: %s                       |
+| Vendor Code | SQL State | Reason                                            |
+|-------------|-----------|---------------------------------------------------|
+| 20400       | 0A000     | Can not support database '%s' in SQL translation. |
 
 ### Traffic Management
 
diff --git a/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/AlgorithmExecuteException.java b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/AlgorithmExecuteException.java
index 4d1fe524dbf..7e55c978411 100644
--- a/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/AlgorithmExecuteException.java
+++ b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/AlgorithmExecuteException.java
@@ -29,7 +29,7 @@ public final class AlgorithmExecuteException extends AlgorithmDefinitionExceptio
     private static final long serialVersionUID = -9099514178650043282L;
     
     public AlgorithmExecuteException(final ShardingSphereAlgorithm algorithm, final String reason, final Object... args) {
-        super(XOpenSQLState.GENERAL_ERROR, 50, "Algorithm '%s.%s' execute failed, reason is: %s.",
+        super(XOpenSQLState.GENERAL_ERROR, 40, "Algorithm '%s.%s' execute failed, reason is: %s.",
                 algorithm.getClass().getSuperclass().getSimpleName(), algorithm.getType(), String.format(reason, args));
     }
 }
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/UnsupportedDataConsistencyCalculateAlgorithmException.java b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/UnsupportedAlgorithmOnDatabaseTypeException.java
similarity index 60%
rename from kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/UnsupportedDataConsistencyCalculateAlgorithmException.java
rename to infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/UnsupportedAlgorithmOnDatabaseTypeException.java
index 38af7fbf778..91ddeb71b7a 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/UnsupportedDataConsistencyCalculateAlgorithmException.java
+++ b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/UnsupportedAlgorithmOnDatabaseTypeException.java
@@ -15,20 +15,19 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.data.pipeline.core.exception.data;
+package org.apache.shardingsphere.infra.algorithm.core.exception;
 
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
 
 /**
- * Unsupported data consistency calculate algorithm exception.
+ * Unsupported algorithm on database type exception.
  */
-public final class UnsupportedDataConsistencyCalculateAlgorithmException extends PipelineDataException {
+public final class UnsupportedAlgorithmOnDatabaseTypeException extends AlgorithmDefinitionException {
     
-    private static final long serialVersionUID = 580323508713524816L;
+    private static final long serialVersionUID = 9046024072116200648L;
     
-    public UnsupportedDataConsistencyCalculateAlgorithmException(final String dataConsistencyCalculateAlgorithmType, final DatabaseType databaseType) {
-        super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 10,
-                "Unsupported '%s' data consistency calculate algorithm with database type '%s'.", dataConsistencyCalculateAlgorithmType, databaseType.getType());
+    public UnsupportedAlgorithmOnDatabaseTypeException(final String algorithmType, final String algorithmDetailType, final DatabaseType databaseType) {
+        super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 10, "Unsupported %s.%s with database type '%s'.", algorithmType, algorithmDetailType, databaseType.getType());
     }
 }
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/calculator/CRC32SingleTableInventoryCalculator.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/calculator/CRC32SingleTableInventoryCalculator.java
index 2c34eda2879..6f4e997aa75 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/calculator/CRC32SingleTableInventoryCalculator.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/calculator/CRC32SingleTableInventoryCalculator.java
@@ -20,10 +20,10 @@ package org.apache.shardingsphere.data.pipeline.core.consistencycheck.table.calc
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.data.pipeline.core.sqlbuilder.sql.PipelineDataConsistencyCalculateSQLBuilder;
 import org.apache.shardingsphere.data.pipeline.core.consistencycheck.result.SingleTableInventoryCalculatedResult;
 import org.apache.shardingsphere.data.pipeline.core.exception.data.PipelineTableDataConsistencyCheckLoadingFailedException;
-import org.apache.shardingsphere.data.pipeline.core.exception.data.UnsupportedDataConsistencyCalculateAlgorithmException;
+import org.apache.shardingsphere.data.pipeline.core.sqlbuilder.sql.PipelineDataConsistencyCalculateSQLBuilder;
+import org.apache.shardingsphere.infra.algorithm.core.exception.UnsupportedAlgorithmOnDatabaseTypeException;
 import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 
 import java.sql.Connection;
@@ -51,7 +51,7 @@ public final class CRC32SingleTableInventoryCalculator extends AbstractSingleTab
     
     private CalculatedItem calculateCRC32(final PipelineDataConsistencyCalculateSQLBuilder pipelineSQLBuilder, final SingleTableInventoryCalculateParameter param, final String columnName) {
         Optional<String> sql = pipelineSQLBuilder.buildCRC32SQL(param.getSchemaName(), param.getLogicTableName(), columnName);
-        ShardingSpherePreconditions.checkState(sql.isPresent(), () -> new UnsupportedDataConsistencyCalculateAlgorithmException("CRC32", param.getDatabaseType()));
+        ShardingSpherePreconditions.checkState(sql.isPresent(), () -> new UnsupportedAlgorithmOnDatabaseTypeException("DataConsistencyCalculate", "CRC32", param.getDatabaseType()));
         try (
                 Connection connection = param.getDataSource().getConnection();
                 PreparedStatement preparedStatement = connection.prepareStatement(sql.get());
diff --git a/kernel/sql-translator/api/src/main/java/org/apache/shardingsphere/sqltranslator/exception/UnsupportedTranslatedDatabaseException.java b/kernel/sql-translator/api/src/main/java/org/apache/shardingsphere/sqltranslator/exception/UnsupportedTranslatedDatabaseException.java
index 975ddc56503..74434c43d0d 100644
--- a/kernel/sql-translator/api/src/main/java/org/apache/shardingsphere/sqltranslator/exception/UnsupportedTranslatedDatabaseException.java
+++ b/kernel/sql-translator/api/src/main/java/org/apache/shardingsphere/sqltranslator/exception/UnsupportedTranslatedDatabaseException.java
@@ -28,6 +28,6 @@ public final class UnsupportedTranslatedDatabaseException extends SQLTranslation
     private static final long serialVersionUID = -8311552562051028033L;
     
     public UnsupportedTranslatedDatabaseException(final DatabaseType databaseType) {
-        super(XOpenSQLState.SYNTAX_ERROR, 40, "Can not support database `%s` in SQL translation.", databaseType.getType());
+        super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 0, "Can not support database '%s' in SQL translation.", databaseType.getType());
     }
 }