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 6d0c11775fa Add UnsupportedShardingOperationException (#20549)
6d0c11775fa is described below
commit 6d0c11775fa5a7ae45c8a456c0e60a1ab90a59cc
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Aug 26 14:23:32 2022 +0800
Add UnsupportedShardingOperationException (#20549)
---
.../user-manual/error-code/sql-error-code.cn.md | 5 ++--
.../user-manual/error-code/sql-error-code.en.md | 3 +-
.../UnsupportedShardingOperationException.java | 33 ++++++++++++++++++++++
.../ddl/ShardingDDLStatementValidator.java | 11 ++++----
.../impl/ShardingAlterViewStatementValidator.java | 2 +-
.../ShardingCreateFunctionStatementValidator.java | 2 +-
.../ShardingCreateProcedureStatementValidator.java | 2 +-
.../ShardingAlterViewStatementValidatorTest.java | 4 +--
8 files changed, 49 insertions(+), 13 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 2739255411a..7e752521ade 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
@@ -41,11 +41,12 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 44000 | 20003 | Can not find table rule with logic tables \`%s\` |
| 44000 | 20012 | Inline sharding algorithms expression \`%s\` and
sharding column \`%s\` are not match |
| HY004 | 20013 | Found different types for sharding value \`%s\` |
+| HY004 | 20014 | Found different types for sharding value \`%s\` |
| HY004 | 24000 | Encrypt algorithm \`%s\` initialize failed, reason
is: %s |
-| HY004 | 24001 | The SQL clause \`%s\` is unsupported in encrypt
rule |
+| 0A000 | 24001 | Can not support operation \`%s\` with sharding
table \`%s\` |
| 44000 | 24002 | Altered column \`%s\` must use same encrypt
algorithm with previous column \`%s\` in table \`%s\` |
| 42000 | 24003 | Insert value of index \`%s\` can not support for
encrypt |
| 44000 | 24004 | Can not find logic encrypt column by \`%s\` |
| HY004 | 25000 | Shadow column \`%s\` of table \`%s\` does not
support \`%s\` type |
-| 42000 | 25003 | Insert value of index `%s` can not support for
shadow |
+| 42000 | 25003 | Insert value of index \`%s\` can not support for
shadow |
| 42000 | 30000 | Unknown exception: %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 8d30bbf62a4..331086a7467 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
@@ -42,10 +42,11 @@ 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\` |
| HY004 | 24000 | Encrypt algorithm \`%s\` initialize failed, reason
is: %s |
+| 0A000 | 24001 | Can not support operation \`%s\` with sharding
table \`%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\` |
| 42000 | 24003 | Insert value of index \`%s\` can not support for
encrypt |
| 44000 | 24004 | Can not find logic encrypt column by \`%s\` |
| HY004 | 25000 | Shadow column \`%s\` of table \`%s\` does not
support \`%s\` type |
-| 42000 | 25003 | Insert value of index `%s` can not support for
shadow |
+| 42000 | 25003 | Insert value of index \`%s\` can not support for
shadow |
| 42000 | 30000 | Unknown exception: %s |
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/UnsupportedShardingOperationException.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/UnsupportedShardingOperationException.java
new file mode 100644
index 00000000000..d6f45eb7a95
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/UnsupportedShardingOperationException.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;
+
+/**
+ * Unsupported sharding operation exception.
+ */
+public final class UnsupportedShardingOperationException extends
ShardingSphereSQLException {
+
+ private static final long serialVersionUID = 1009938372927671322L;
+
+ public UnsupportedShardingOperationException(final String operation, final
String tableName) {
+ super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 10200, "Can not support
operation `%s` with sharding table `%s`", operation, tableName);
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
index 2976424cf08..5d50b7a6ad8 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
@@ -17,11 +17,11 @@
package org.apache.shardingsphere.sharding.route.engine.validator.ddl;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
-import
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.route.context.RouteContext;
import
org.apache.shardingsphere.dialect.exception.syntax.table.NoSuchTableException;
import
org.apache.shardingsphere.dialect.exception.syntax.table.TableExistsException;
+import
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.route.context.RouteContext;
+import
org.apache.shardingsphere.sharding.exception.UnsupportedShardingOperationException;
import
org.apache.shardingsphere.sharding.route.engine.validator.ShardingStatementValidator;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
@@ -39,13 +39,14 @@ public abstract class ShardingDDLStatementValidator<T
extends DDLStatement> impl
* Validate sharding table.
*
* @param shardingRule sharding rule
+ * @param operation operation
* @param tables tables
*/
- protected void validateShardingTable(final ShardingRule shardingRule,
final Collection<SimpleTableSegment> tables) {
+ protected void validateShardingTable(final ShardingRule shardingRule,
final String operation, final Collection<SimpleTableSegment> tables) {
for (SimpleTableSegment each : tables) {
String tableName = each.getTableName().getIdentifier().getValue();
if (shardingRule.isShardingTable(tableName)) {
- throw new ShardingSphereException("Can not support sharding
table '%s'.", tableName);
+ throw new UnsupportedShardingOperationException(operation,
tableName);
}
}
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterViewStatementValidator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterViewStatementValidator.java
index 4ebb843796c..8f0796834b0 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterViewStatementValidator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterViewStatementValidator.java
@@ -43,7 +43,7 @@ public final class ShardingAlterViewStatementValidator
extends ShardingDDLStatem
if (selectStatement.isPresent()) {
TableExtractor extractor = new TableExtractor();
extractor.extractTablesFromSelect(selectStatement.get());
- validateShardingTable(shardingRule, extractor.getRewriteTables());
+ validateShardingTable(shardingRule, "ALTER VIEW",
extractor.getRewriteTables());
}
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateFunctionStatementValidator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateFunctionStatementValidator.java
index 4a4ff200142..3ab7ee8b8e2 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateFunctionStatementValidator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateFunctionStatementValidator.java
@@ -49,7 +49,7 @@ public final class ShardingCreateFunctionStatementValidator
extends ShardingDDLS
}
TableExtractor extractor = new TableExtractor();
Collection<SimpleTableSegment> existTables =
extractor.extractExistTableFromRoutineBody(routineBodySegment.get());
- validateShardingTable(shardingRule, existTables);
+ validateShardingTable(shardingRule, "CREATE FUNCTION", existTables);
String defaultSchemaName =
DatabaseTypeEngine.getDefaultSchemaName(sqlStatementContext.getDatabaseType(),
database.getName());
ShardingSphereSchema schema =
sqlStatementContext.getSqlStatement().getFunctionName().flatMap(optional ->
optional.getOwner()
.map(owner ->
database.getSchema(owner.getIdentifier().getValue()))).orElseGet(() ->
database.getSchema(defaultSchemaName));
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateProcedureStatementValidator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateProcedureStatementValidator.java
index cf20b9e8f3f..6e535955fbd 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateProcedureStatementValidator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateProcedureStatementValidator.java
@@ -52,7 +52,7 @@ public final class ShardingCreateProcedureStatementValidator
extends ShardingDDL
ShardingSphereSchema schema =
sqlStatementContext.getSqlStatement().getProcedureName().flatMap(optional ->
optional.getOwner()
.map(owner ->
database.getSchema(owner.getIdentifier().getValue()))).orElseGet(() ->
database.getSchema(defaultSchemaName));
Collection<SimpleTableSegment> existTables =
extractor.extractExistTableFromRoutineBody(routineBodySegment.get());
- validateShardingTable(shardingRule, existTables);
+ validateShardingTable(shardingRule, "CREATE PROCEDURE", existTables);
validateTableExist(schema, existTables);
Collection<SimpleTableSegment> notExistTables =
extractor.extractNotExistTableFromRoutineBody(routineBodySegment.get());
validateTableNotExist(schema, notExistTables);
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterViewStatementValidatorTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterViewStatementValidatorTest.java
index c87978646f7..bc13d3ef5ed 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterViewStatementValidatorTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterViewStatementValidatorTest.java
@@ -19,8 +19,8 @@ package
org.apache.shardingsphere.sharding.route.engine.validator.ddl;
import
org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.sharding.exception.UnsupportedShardingOperationException;
import
org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingAlterViewStatementValidator;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
@@ -57,7 +57,7 @@ public final class ShardingAlterViewStatementValidatorTest {
new ShardingAlterViewStatementValidator().preValidate(shardingRule,
sqlStatementContext, Collections.emptyList(), database);
}
- @Test(expected = ShardingSphereException.class)
+ @Test(expected = UnsupportedShardingOperationException.class)
public void assertPreValidateAlterViewWithShardingTableForMySQL() {
MySQLSelectStatement selectStatement = new MySQLSelectStatement();
selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0,
0, new IdentifierValue("t_order"))));