This is an automated email from the ASF dual-hosted git repository.
yx9o 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 f371be147b8 Add DataNodeGenerateException (#20580)
f371be147b8 is described below
commit f371be147b8282a93bc9edca143f9db1969a1340
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Aug 27 00:11:12 2022 +0800
Add DataNodeGenerateException (#20580)
* Add DataNodeGenerateException
* Add DataNodeGenerateException
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 1 +
.../exception/DataNodeGenerateException.java | 33 ++++++++++++++++++++++
.../shardingsphere/sharding/rule/TableRule.java | 4 +--
4 files changed, 37 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 eeb5988bc0a..09519348845 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
@@ -50,6 +50,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 44000 | 20012 | Inline sharding algorithms expression \`%s\` and
sharding column \`%s\` are not match |
| HY004 | 20013 | Found different types for sharding value \`%s\` |
| 44000 | 20014 | Actual tables \`%s\` are in use |
+| 42S02 | 20015 | Can not find data source in sharding rule, invalid
actual data node `%s` |
| HY004 | 24000 | Encrypt algorithm \`%s\` initialize failed, reason
is: %s |
| 0A000 | 24001 | The SQL clause \`%s\` is unsupported in encrypt
rule |
| 44000 | 24002 | Altered column \`%s\` must use same encrypt
algorithm with previous column \`%s\` in table \`%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 fa1a9e3ccdf..2914dc5afc2 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
@@ -50,6 +50,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| 44000 | 20012 | Inline sharding algorithms expression \`%s\` and
sharding column \`%s\` are not match |
| HY004 | 20013 | Found different types for sharding value \`%s\` |
| 44000 | 20014 | Actual tables \`%s\` are in use |
+| 42S02 | 20015 | Can not find data source in sharding rule, invalid
actual data node `%s` |
| HY004 | 24000 | Encrypt algorithm \`%s\` initialize failed, reason
is: %s |
| HY004 | 24001 | The SQL clause \`%s\` is unsupported in encrypt
rule |
| 44000 | 24002 | Altered column \`%s\` must use same encrypt
algorithm with previous column \`%s\` in table \`%s\` |
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/DataNodeGenerateException.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/DataNodeGenerateException.java
new file mode 100644
index 00000000000..4b9a9202d60
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/DataNodeGenerateException.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;
+
+/**
+ * Data node generate exception.
+ */
+public final class DataNodeGenerateException extends
ShardingSphereSQLException {
+
+ private static final long serialVersionUID = -1000865538051567910L;
+
+ public DataNodeGenerateException(final String dataNode) {
+ super(XOpenSQLState.NOT_FOUND, 20015, "Can not find data source in
sharding rule, invalid actual data node `%s`", dataNode);
+ }
+}
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 107574a280d..89e7a942b38 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
@@ -25,7 +25,6 @@ import
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurat
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.exception.ShardingSphereException;
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;
@@ -34,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.DataNodeGenerateException;
import java.util.Collection;
import java.util.Collections;
@@ -191,7 +191,7 @@ public final class TableRule {
for (String each : actualDataNodes) {
DataNode dataNode = new DataNode(each);
if (!dataSourceNames.contains(dataNode.getDataSourceName())) {
- throw new ShardingSphereException("Cannot find data source in
sharding rule, invalid actual data node is: '%s'", each);
+ throw new DataNodeGenerateException(each);
}
result.add(dataNode);
dataNodeIndexMap.put(dataNode, index);