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 669ef5bae4f Add EmptyShardingRouteResultException (#20567)
669ef5bae4f is described below

commit 669ef5bae4f1e27156d27dde361d4a312adbce02
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Aug 26 18:20:50 2022 +0800

    Add EmptyShardingRouteResultException (#20567)
---
 .../user-manual/error-code/sql-error-code.cn.md    |  1 +
 .../user-manual/error-code/sql-error-code.en.md    |  1 +
 .../EmptyShardingRouteResultException.java         | 33 ++++++++++++++++++++++
 .../impl/ShardingPrepareStatementValidator.java    |  3 +-
 .../ddl/ShardingPrepareStatementValidatorTest.java |  3 +-
 5 files changed, 39 insertions(+), 2 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 827f88c5b37..f7077214c04 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
@@ -43,6 +43,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 42S01     | 20005       | Index \`%s\` already exists |
 | 42S02     | 20006       | Index \`%s\` does not exist |
 | HY000     | 20007       | \`%s %s\` can not route correctly for %s \`%s\` |
+| 42S02     | 20008       | Can not get route result, please check your 
sharding rule configuration |
 | 44000     | 20012       | Inline sharding algorithms expression \`%s\` and 
sharding column \`%s\` are not match |
 | HY004     | 20013       | Found different types for sharding value \`%s\` |
 | HY004     | 24000       | Encrypt algorithm \`%s\` initialize failed, reason 
is: %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 31586d98911..3dc8e858a98 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
@@ -43,6 +43,7 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | 42S01     | 20005       | Index \`%s\` already exists |
 | 42S02     | 20006       | Index \`%s\` does not exist |
 | HY000     | 20007       | \`%s %s\` can not route correctly for %s \`%s\` |
+| 42S02     | 20008       | Can not get route result, please check your 
sharding rule configuration |
 | 44000     | 20012       | Inline sharding algorithms expression \`%s\` and 
sharding column \`%s\` are not match |
 | HY004     | 20013       | Found different types for sharding value \`%s\` |
 | HY004     | 24000       | Encrypt algorithm \`%s\` initialize failed, reason 
is: %s |
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/EmptyShardingRouteResultException.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/EmptyShardingRouteResultException.java
new file mode 100644
index 00000000000..3a47d6e2bee
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/EmptyShardingRouteResultException.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.exception;
+
+import 
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLException;
+import 
org.apache.shardingsphere.infra.util.exception.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Empty sharding route result exception.
+ */
+public final class EmptyShardingRouteResultException extends 
ShardingSphereSQLException {
+    
+    private static final long serialVersionUID = -6548076668933945656L;
+    
+    public EmptyShardingRouteResultException() {
+        super(XOpenSQLState.NOT_FOUND, 20008, "Can not get route result, 
please check your sharding rule configuration");
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingPrepareStatementValidator.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingPrepareStatementValidator.java
index 395bd81b995..51a59b2b4a4 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingPrepareStatementValidator.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingPrepareStatementValidator.java
@@ -23,6 +23,7 @@ import 
org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.route.context.RouteContext;
 import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import 
org.apache.shardingsphere.sharding.exception.EmptyShardingRouteResultException;
 import 
org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.PrepareStatement;
@@ -44,7 +45,7 @@ public final class ShardingPrepareStatementValidator extends 
ShardingDDLStatemen
     public void postValidate(final ShardingRule shardingRule, final 
SQLStatementContext<PrepareStatement> sqlStatementContext, final List<Object> 
parameters,
                              final ShardingSphereDatabase database, final 
ConfigurationProperties props, final RouteContext routeContext) {
         if (routeContext.getRouteUnits().isEmpty()) {
-            throw new ShardingSphereException("Can not get route result, 
please check your sharding table config.");
+            throw new EmptyShardingRouteResultException();
         }
         if 
(routeContext.getRouteUnits().stream().collect(Collectors.groupingBy(RouteUnit::getDataSourceMapper)).entrySet().stream().anyMatch(each
 -> each.getValue().size() > 1)) {
             throw new ShardingSphereException("Prepare ... statement can not 
support sharding tables route to same data sources.");
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingPrepareStatementValidatorTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingPrepareStatementValidatorTest.java
index e58389427ed..a337157cb31 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingPrepareStatementValidatorTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingPrepareStatementValidatorTest.java
@@ -24,6 +24,7 @@ import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.route.context.RouteContext;
 import org.apache.shardingsphere.infra.route.context.RouteMapper;
 import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import 
org.apache.shardingsphere.sharding.exception.EmptyShardingRouteResultException;
 import 
org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingPrepareStatementValidator;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.PrepareStatement;
@@ -53,7 +54,7 @@ public final class ShardingPrepareStatementValidatorTest {
     @Mock
     private RouteContext routeContext;
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = EmptyShardingRouteResultException.class)
     public void assertPostValidatePrepareWithEmptyRouteResultForPostgreSQL() {
         PrepareStatement sqlStatement = new PostgreSQLPrepareStatement();
         when(routeContext.getRouteUnits()).thenReturn(Collections.emptyList());

Reply via email to