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

menghaoran 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 fabe8b81c4a Add ActualDataNodesMissedWithShardingTableException 
(#20757)
fabe8b81c4a is described below

commit fabe8b81c4a98656d1d8c144fa6b7aa85b553be4
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Sep 4 06:27:02 2022 +0800

    Add ActualDataNodesMissedWithShardingTableException (#20757)
---
 .../user-manual/error-code/sql-error-code.cn.md    |  1 +
 .../user-manual/error-code/sql-error-code.en.md    |  1 +
 ...lDataNodesMissedWithShardingTableException.java | 33 ++++++++++++++++++++++
 .../shardingsphere/sharding/rule/TableRule.java    |  8 +++---
 .../sharding/rule/TableRuleTest.java               |  4 +--
 5 files changed, 41 insertions(+), 6 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 1d9c599aed4..1d64f34a1de 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
@@ -61,6 +61,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 42000     | 20018       | INSERT INTO ... SELECT can not support applying 
key generator with absent generate key column |
 | 44000     | 20019       | The table inserted and the table selected must be 
the same or bind tables |
 | 44000     | 20020       | Inline sharding algorithms expression \`%s\` and 
sharding column \`%s\` do not match |
+| 44000     | 20021       | Actual data nodes must be configured for sharding 
table \`%s\` |
 | 42S01     | 20030       | Index \`%s\` already exists |
 | 42S02     | 20031       | Index \`%s\` does not exist |
 | 44000     | 20032       | Actual tables \`%s\` are in use |
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 5bfb37d6309..9681abc7d7b 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
@@ -61,6 +61,7 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | 42000     | 20018       | INSERT INTO ... SELECT can not support applying 
key generator with absent generate key column |
 | 44000     | 20019       | The table inserted and the table selected must be 
the same or bind tables |
 | 44000     | 20020       | Inline sharding algorithms expression \`%s\` and 
sharding column \`%s\` do not match |
+| 44000     | 20021       | Actual data nodes must be configured for sharding 
table \`%s\` |
 | 42S01     | 20030       | Index \`%s\` already exists |
 | 42S02     | 20031       | Index \`%s\` does not exist |
 | 44000     | 20032       | Actual tables \`%s\` are in use |
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/ActualDataNodesMissedWithShardingTableException.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/ActualDataNodesMissedWithShardingTableException.java
new file mode 100644
index 00000000000..e06837a00e8
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/ActualDataNodesMissedWithShardingTableException.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.external.sql.ShardingSphereSQLException;
+import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Actual data nodes missed with sharding table exception.
+ */
+public final class ActualDataNodesMissedWithShardingTableException extends 
ShardingSphereSQLException {
+    
+    private static final long serialVersionUID = 1691113459377955727L;
+    
+    public ActualDataNodesMissedWithShardingTableException(final String 
tableName) {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 20021, "Actual data nodes 
must be configured for sharding table `%s`", tableName);
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
index 89e7a942b38..0543d871099 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
@@ -21,10 +21,10 @@ import com.google.common.base.Strings;
 import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.ToString;
-import 
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
 import org.apache.shardingsphere.infra.datanode.DataNode;
 import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
 import org.apache.shardingsphere.infra.datanode.DataNodeUtil;
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import org.apache.shardingsphere.infra.util.expr.InlineExpressionParser;
 import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -33,6 +33,7 @@ import 
org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerate
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShardingStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.sharding.ShardingAutoTableAlgorithm;
+import 
org.apache.shardingsphere.sharding.exception.ActualDataNodesMissedWithShardingTableException;
 import org.apache.shardingsphere.sharding.exception.DataNodeGenerateException;
 
 import java.util.Collection;
@@ -239,9 +240,8 @@ public final class TableRule {
     }
     
     private void checkRule(final List<String> dataNodes) {
-        if (isEmptyDataNodes(dataNodes) && null != tableShardingStrategyConfig 
&& !(tableShardingStrategyConfig instanceof NoneShardingStrategyConfiguration)) 
{
-            throw new ShardingSphereConfigurationException("ActualDataNodes 
must be configured if want to shard tables for logicTable [%s]", logicTable);
-        }
+        ShardingSpherePreconditions.checkState(!isEmptyDataNodes(dataNodes) || 
null == tableShardingStrategyConfig || tableShardingStrategyConfig instanceof 
NoneShardingStrategyConfiguration,
+                new 
ActualDataNodesMissedWithShardingTableException(logicTable));
     }
     
     /**
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
index a37979a6599..2479a9e8fc1 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
@@ -18,7 +18,6 @@
 package org.apache.shardingsphere.sharding.rule;
 
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import 
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
 import org.apache.shardingsphere.infra.datanode.DataNode;
 import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
 import 
org.apache.shardingsphere.sharding.algorithm.sharding.mod.ModShardingAlgorithm;
@@ -27,6 +26,7 @@ import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfi
 import 
org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShardingStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
+import 
org.apache.shardingsphere.sharding.exception.ActualDataNodesMissedWithShardingTableException;
 import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
 import org.junit.Test;
 
@@ -148,7 +148,7 @@ public final class TableRuleTest {
         assertFalse(actual.isExisted("table_3"));
     }
     
-    @Test(expected = ShardingSphereConfigurationException.class)
+    @Test(expected = ActualDataNodesMissedWithShardingTableException.class)
     public void assertActualDataNodesNotConfigured() {
         ShardingTableRuleConfiguration shardingTableRuleConfig = new 
ShardingTableRuleConfiguration("LOGIC_TABLE", "");
         shardingTableRuleConfig.setTableShardingStrategy(new 
StandardShardingStrategyConfiguration("shardingColumn", "INLINE"));

Reply via email to