This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 ee0fadea52a Add
MismatchedInlineShardingAlgorithmExpressionAndColumnException (#20505)
ee0fadea52a is described below
commit ee0fadea52ae2f5c983e9eafe96ee7fb84b4426e
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Aug 25 14:18:40 2022 +0800
Add MismatchedInlineShardingAlgorithmExpressionAndColumnException (#20505)
* Add MismatchedInlineShardingAlgorithmExpressionAndColumnException
* Add MismatchedInlineShardingAlgorithmExpressionAndColumnException
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 1 +
.../sharding/inline/InlineShardingAlgorithm.java | 4 +--
...rdingAlgorithmExpressionAndColumnException.java | 33 ++++++++++++++++++++++
.../inline/InlineShardingAlgorithmTest.java | 4 +--
5 files changed, 39 insertions(+), 4 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 c7477a9b4ce..06d9958b656 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
@@ -34,6 +34,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| HY000 | 16000 | Can not find pipeline job \`%s\` |
| HY000 | 16001 | Failed to get DDL for table \`%s\` |
| HY000 | 20000 | Sharding algorithm class \`%s\` should be
implement \`%s\` |
+| 44000 | 20012 | Inline sharding algorithms expression \`%s\` and
sharding column \`%s\` are not match |
| 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/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 f76ef256c8b..87e5a673c61 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
@@ -34,6 +34,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| HY000 | 16000 | Can not find pipeline job \`%s\` |
| HY000 | 16001 | Failed to get DDL for table \`%s\` |
| HY000 | 20000 | Sharding algorithm class \`%s\` should be
implement \`%s\` |
+| 44000 | 20012 | Inline sharding algorithms expression \`%s\` and
sharding column \`%s\` are not match |
| 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/algorithm/sharding/inline/InlineShardingAlgorithm.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java
index ca9095911bf..2d0cb4929ea 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java
@@ -22,11 +22,11 @@ import groovy.lang.Closure;
import groovy.lang.MissingMethodException;
import groovy.util.Expando;
import lombok.Getter;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.util.expr.InlineExpressionParser;
import
org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import
org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import
org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
+import
org.apache.shardingsphere.sharding.exception.MismatchedInlineShardingAlgorithmExpressionAndColumnException;
import java.util.Collection;
import java.util.Properties;
@@ -93,7 +93,7 @@ public final class InlineShardingAlgorithm implements
StandardShardingAlgorithm<
try {
return closure.call().toString();
} catch (final MissingMethodException | NullPointerException ex) {
- throw new ShardingSphereException("Inline sharding algorithms
expression `%s` and sharding column `%s` not match.", algorithmExpression,
columnName);
+ throw new
MismatchedInlineShardingAlgorithmExpressionAndColumnException(algorithmExpression,
columnName);
}
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/MismatchedInlineShardingAlgorithmExpressionAndColumnException.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/MismatchedInlineShardingAlgorithmExpressionAndColumnException.java
new file mode 100644
index 00000000000..edad0ed7d60
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/MismatchedInlineShardingAlgorithmExpressionAndColumnException.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;
+
+/**
+ * Mismatched inline sharding algorithm's expression and column exception.
+ */
+public final class
MismatchedInlineShardingAlgorithmExpressionAndColumnException extends
ShardingSphereSQLException {
+
+ private static final long serialVersionUID = 1306301016127278233L;
+
+ public MismatchedInlineShardingAlgorithmExpressionAndColumnException(final
String algorithmExpression, final String columnName) {
+ super(XOpenSQLState.CHECK_OPTION_VIOLATION, 20012, "Inline sharding
algorithms expression `%s` and sharding column `%s` are not match",
algorithmExpression, columnName);
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
index ba3a05bf381..94342b0fb24 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
@@ -21,9 +21,9 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Range;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import
org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import
org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
+import
org.apache.shardingsphere.sharding.exception.MismatchedInlineShardingAlgorithmExpressionAndColumnException;
import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
import org.junit.Before;
import org.junit.Test;
@@ -66,7 +66,7 @@ public final class InlineShardingAlgorithmTest {
return result;
}
- @Test(expected = ShardingSphereException.class)
+ @Test(expected =
MismatchedInlineShardingAlgorithmExpressionAndColumnException.class)
public void assertDoSharding() {
List<String> availableTargetNames = Arrays.asList("t_order_0",
"t_order_1", "t_order_2", "t_order_3");
assertThat(inlineShardingAlgorithm.doSharding(availableTargetNames,
new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, 0)),
is("t_order_0"));