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 5d289c732a0 Refactor MetaDataSQLException (#30730)
5d289c732a0 is described below
commit 5d289c732a0328d30b7a80907faa5ce340d7a8f0
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Apr 1 17:45:23 2024 +0800
Refactor MetaDataSQLException (#30730)
* Refactor MetaDataSQLException
* Refactor LoadSingleTableExecutor
* Refactor LoadSingleTableExecutor
* Remove MissingRequiredSingleTableException
* Remove MissingRequiredSingleTableException
* Rename ColumnNotFoundException
* Refactor MetaDataSQLException
* Refactor MetaDataSQLException
---
.../user-manual/error-code/sql-error-code.cn.md | 61 ++++++++++---------
.../user-manual/error-code/sql-error-code.en.md | 61 ++++++++++---------
.../expression/impl/ColumnSegmentBinder.java | 6 +-
...Exception.java => ColumnNotFoundException.java} | 8 +--
.../exception/InvalidDataNodeFormatException.java | 4 +-
.../infra/exception/SchemaNotFoundException.java | 2 +-
.../infra/exception/TableNotFoundException.java | 6 +-
...nsupportedActualDataNodeStructureException.java | 2 +-
.../SingleRuleConfigurationDecorator.java | 4 +-
.../exception/DropNotEmptySchemaException.java | 2 +-
.../exception/SingleTableNotFoundException.java | 2 +-
.../exception/SingleTablesLoadingException.java | 2 +-
.../MissingRequiredSingleTableException.java | 33 -----------
.../handler/update/LoadSingleTableExecutor.java | 69 ++++++++++------------
.../update/LoadSingleTableExecutorTest.java | 6 +-
.../statement/ShardingPreparedStatementTest.java | 4 +-
16 files changed, 117 insertions(+), 155 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 0f518cbf04b..9a37cd0b7cc 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
@@ -12,37 +12,36 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
### 元数据
-| SQL State | Vendor Code | 错误信息
|
-|-----------|-------------|--------------------------------------------------------------------------------|
-| HY000 | 10000 | Can not support 3-tier structure for actual data
node \`%s\` with JDBC \`%s\`. |
-| HY004 | 10001 | Invalid format for actual data node \`%s\`.
|
-| HY000 | 10005 | Column '%s' in %s is ambiguous.
|
-| 42S02 | 10006 | Unknown column '%s' in '%s'.
|
-| 42S02 | 10007 | Table or view \`%s\` does not exist.
|
-| 42S02 | 10008 | Missing required table '%s' in storage unit '%s'.
|
-| 42S02 | 10020 | Schema \`%s\` does not exist.
|
-| 42S02 | 10021 | Single table \`%s\` does not exist.
|
-| HY000 | 10022 | Can not load table with database name \`%s\` and
data source name \`%s\`. |
-| 0A000 | 10030 | Can not drop schema \`%s\` because of contains
tables. |
-| HY000 | 10100 | Can not %s storage units '%s'.
|
-| 42S02 | 10101 | There is no storage unit in database '%s'.
|
-| 44000 | 10102 | Storage units '%s' do not exist in database '%s'.
|
-| 44000 | 10103 | Storage unit '%s' still used by '%s'.
|
-| 42S01 | 10104 | Duplicate storage unit names '%s'.
|
-| 08000 | 10110 | Storage units can not connect, error messages are:
%s. |
-| 0A000 | 10111 | Can not alter connection info in storage units:
'%s'. |
-| 44000 | 10120 | Invalid storage unit status, error message is: %s.
|
-| 44000 | 10200 | Invalid '%s' rule '%s', error message is: %s
|
-| 42S02 | 10201 | There is no rule in database '%s'.
|
-| 42S02 | 10202 | %s rules '%s' do not exist in database '%s'.
|
-| 44000 | 10203 | %s rules '%s' in database '%s' are still in used.
|
-| 42S01 | 10204 | Duplicate %s rule names '%s' in database '%s'.
|
-| 44000 | 10300 | Algorithm '%s.'%s' initialization failed, reason
is: %s. |
-| 44000 | 10301 | '%s' algorithm on %s is required.
|
-| 42S02 | 10302 | '%s' algorithm '%s' on %s is unregistered.
|
-| 44000 | 10303 | %s algorithms '%s' in database '%s' are still in
used. |
-| 44000 | 10304 | Invalid %s algorithm configuration '%s'.
|
-| HY000 | 10350 | Algorithm '%s.%s' execute failed, reason is: %s.
|
+| SQL State | Vendor Code | 错误信息
|
+|-----------|-------------|----------------------------------------------------------------------------|
+| HY000 | 10000 | Can not support 3-tier structure for actual data
node '%s' with JDBC '%s'. |
+| HY004 | 10001 | Invalid format for actual data node '%s'.
|
+| 42S02 | 10002 | Schema '%s' does not exist.
|
+| 42S02 | 10003 | Table or view '%s' does not exist.
|
+| 42S02 | 10004 | Unknown column '%s' in '%s'.
|
+| HY000 | 10005 | Column '%s' in %s is ambiguous.
|
+| 42S02 | 10021 | Single table '%s' does not exist.
|
+| HY000 | 10022 | Can not load table with database name '%s' and
data source name '%s'. |
+| 0A000 | 10030 | Can not drop schema '%s' because of contains
tables. |
+| HY000 | 10100 | Can not %s storage units '%s'.
|
+| 42S02 | 10101 | There is no storage unit in database '%s'.
|
+| 44000 | 10102 | Storage units '%s' do not exist in database '%s'.
|
+| 44000 | 10103 | Storage unit '%s' still used by '%s'.
|
+| 42S01 | 10104 | Duplicate storage unit names '%s'.
|
+| 08000 | 10110 | Storage units can not connect, error messages are:
%s. |
+| 0A000 | 10111 | Can not alter connection info in storage units:
'%s'. |
+| 44000 | 10120 | Invalid storage unit status, error message is: %s.
|
+| 44000 | 10200 | Invalid '%s' rule '%s', error message is: %s
|
+| 42S02 | 10201 | There is no rule in database '%s'.
|
+| 42S02 | 10202 | %s rules '%s' do not exist in database '%s'.
|
+| 44000 | 10203 | %s rules '%s' in database '%s' are still in used.
|
+| 42S01 | 10204 | Duplicate %s rule names '%s' in database '%s'.
|
+| 44000 | 10300 | Algorithm '%s.'%s' initialization failed, reason
is: %s. |
+| 44000 | 10301 | '%s' algorithm on %s is required.
|
+| 42S02 | 10302 | '%s' algorithm '%s' on %s is unregistered.
|
+| 44000 | 10303 | %s algorithms '%s' in database '%s' are still in
used. |
+| 44000 | 10304 | Invalid %s algorithm configuration '%s'.
|
+| HY000 | 10350 | Algorithm '%s.%s' execute 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 31325b5571b..ee149fb367d 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
@@ -12,37 +12,36 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
### Meta data
-| SQL State | Vendor Code | Reason
|
-|-----------|-------------|--------------------------------------------------------------------------------|
-| HY000 | 10000 | Can not support 3-tier structure for actual data
node \`%s\` with JDBC \`%s\`. |
-| HY004 | 10001 | Invalid format for actual data node \`%s\`.
|
-| HY000 | 10005 | Column '%s' in %s is ambiguous.
|
-| 42S02 | 10006 | Unknown column '%s' in '%s'.
|
-| 42S02 | 10007 | Table or view \`%s\` does not exist.
|
-| 42S02 | 10008 | Missing required table '%s' in storage unit '%s'.
|
-| 42S02 | 10020 | Schema \`%s\` does not exist.
|
-| 42S02 | 10021 | Single table \`%s\` does not exist.
|
-| HY000 | 10022 | Can not load table with database name \`%s\` and
data source name \`%s\`. |
-| 0A000 | 10030 | Can not drop schema \`%s\` because of contains
tables. |
-| HY000 | 10100 | Can not %s storage units '%s'.
|
-| 42S02 | 10101 | There is no storage unit in database '%s'.
|
-| 44000 | 10102 | Storage units '%s' do not exist in database '%s'.
|
-| 44000 | 10103 | Storage unit '%s' still used by '%s'.
|
-| 42S01 | 10104 | Duplicate storage unit names '%s'.
|
-| 08000 | 10110 | Storage units can not connect, error messages are:
%s. |
-| 0A000 | 10111 | Can not alter connection info in storage units:
'%s'. |
-| 44000 | 10120 | Invalid storage unit status, error message is: %s.
|
-| 44000 | 10200 | Invalid '%s' rule '%s', error message is: %s
|
-| 42S02 | 10201 | There is no rule in database '%s'.
|
-| 42S02 | 10202 | %s rules '%s' do not exist in database '%s'.
|
-| 44000 | 10203 | %s rules '%s' in database '%s' are still in used.
|
-| 42S01 | 10204 | Duplicate %s rule names '%s' in database '%s'.
|
-| 44000 | 10300 | Algorithm '%s.'%s' initialization failed, reason
is: %s. |
-| 44000 | 10301 | '%s' algorithm on %s is required.
|
-| 42S02 | 10302 | '%s' algorithm '%s' on %s is unregistered.
|
-| 44000 | 10303 | %s algorithms '%s' in database '%s' are still in
used. |
-| 44000 | 10304 | Invalid %s algorithm configuration '%s'.
|
-| HY000 | 10350 | Algorithm '%s.%s' execute failed, reason is: %s.
|
+| SQL State | Vendor Code | Reason
|
+|-----------|-------------|----------------------------------------------------------------------------|
+| HY000 | 10000 | Can not support 3-tier structure for actual data
node '%s' with JDBC '%s'. |
+| HY004 | 10001 | Invalid format for actual data node '%s'.
|
+| 42S02 | 10002 | Schema '%s' does not exist.
|
+| 42S02 | 10003 | Table or view '%s' does not exist.
|
+| 42S02 | 10004 | Unknown column '%s' in '%s'.
|
+| HY000 | 10005 | Column '%s' in %s is ambiguous.
|
+| 42S02 | 10021 | Single table '%s' does not exist.
|
+| HY000 | 10022 | Can not load table with database name '%s' and
data source name '%s'. |
+| 0A000 | 10030 | Can not drop schema '%s' because of contains
tables. |
+| HY000 | 10100 | Can not %s storage units '%s'.
|
+| 42S02 | 10101 | There is no storage unit in database '%s'.
|
+| 44000 | 10102 | Storage units '%s' do not exist in database '%s'.
|
+| 44000 | 10103 | Storage unit '%s' still used by '%s'.
|
+| 42S01 | 10104 | Duplicate storage unit names '%s'.
|
+| 08000 | 10110 | Storage units can not connect, error messages are:
%s. |
+| 0A000 | 10111 | Can not alter connection info in storage units:
'%s'. |
+| 44000 | 10120 | Invalid storage unit status, error message is: %s.
|
+| 44000 | 10200 | Invalid '%s' rule '%s', error message is: %s
|
+| 42S02 | 10201 | There is no rule in database '%s'.
|
+| 42S02 | 10202 | %s rules '%s' do not exist in database '%s'.
|
+| 44000 | 10203 | %s rules '%s' in database '%s' are still in used.
|
+| 42S01 | 10204 | Duplicate %s rule names '%s' in database '%s'.
|
+| 44000 | 10300 | Algorithm '%s.'%s' initialization failed, reason
is: %s. |
+| 44000 | 10301 | '%s' algorithm on %s is required.
|
+| 42S02 | 10302 | '%s' algorithm '%s' on %s is unregistered.
|
+| 44000 | 10303 | %s algorithms '%s' in database '%s' are still in
used. |
+| 44000 | 10304 | Invalid %s algorithm configuration '%s'.
|
+| HY000 | 10350 | Algorithm '%s.%s' execute failed, reason is: %s.
|
### Data
diff --git
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/ColumnSegmentBinder.java
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/ColumnSegmentBinder.java
index 1e2188dd146..fefc5819bfa 100644
---
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/ColumnSegmentBinder.java
+++
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/ColumnSegmentBinder.java
@@ -27,7 +27,7 @@ import
org.apache.shardingsphere.infra.binder.segment.from.SimpleTableSegmentBin
import
org.apache.shardingsphere.infra.binder.segment.from.TableSegmentBinderContext;
import
org.apache.shardingsphere.infra.binder.statement.SQLStatementBinderContext;
import org.apache.shardingsphere.infra.exception.AmbiguousColumnException;
-import org.apache.shardingsphere.infra.exception.UnknownColumnException;
+import org.apache.shardingsphere.infra.exception.ColumnNotFoundException;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment;
@@ -158,7 +158,7 @@ public final class ColumnSegmentBinder {
isFindInputColumn = result != null;
}
ShardingSpherePreconditions.checkState(isFindInputColumn ||
containsFunctionTable(tableBinderContexts, outerTableBinderContexts.values()),
- () -> new UnknownColumnException(segment.getExpression(),
SEGMENT_TYPE_MESSAGES.getOrDefault(parentSegmentType,
UNKNOWN_SEGMENT_TYPE_MESSAGE)));
+ () -> new ColumnNotFoundException(segment.getExpression(),
SEGMENT_TYPE_MESSAGES.getOrDefault(parentSegmentType,
UNKNOWN_SEGMENT_TYPE_MESSAGE)));
return Optional.ofNullable(result);
}
@@ -246,7 +246,7 @@ public final class ColumnSegmentBinder {
Collection<TableSegmentBinderContext> tableBinderContextValues =
tableBinderContexts.values();
Collection<ColumnSegment> usingInputColumnSegments =
findUsingInputColumnSegments(segment.getIdentifier().getValue(),
tableBinderContextValues);
ShardingSpherePreconditions.checkState(usingInputColumnSegments.size()
>= 2,
- () -> new UnknownColumnException(segment.getExpression(),
SEGMENT_TYPE_MESSAGES.getOrDefault(parentSegmentType,
UNKNOWN_SEGMENT_TYPE_MESSAGE)));
+ () -> new ColumnNotFoundException(segment.getExpression(),
SEGMENT_TYPE_MESSAGES.getOrDefault(parentSegmentType,
UNKNOWN_SEGMENT_TYPE_MESSAGE)));
Iterator<ColumnSegment> iterator = usingInputColumnSegments.iterator();
result.setColumnBoundedInfo(createColumnSegmentBoundedInfo(segment,
iterator.next()));
result.setOtherUsingColumnBoundedInfo(createColumnSegmentBoundedInfo(segment,
iterator.next()));
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/UnknownColumnException.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/ColumnNotFoundException.java
similarity index 81%
rename from
infra/common/src/main/java/org/apache/shardingsphere/infra/exception/UnknownColumnException.java
rename to
infra/common/src/main/java/org/apache/shardingsphere/infra/exception/ColumnNotFoundException.java
index 6df57bfa84a..104b9b11653 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/UnknownColumnException.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/ColumnNotFoundException.java
@@ -21,13 +21,13 @@ import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpe
import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.MetaDataSQLException;
/**
- * Unknown column exception.
+ * Column not found exception.
*/
-public final class UnknownColumnException extends MetaDataSQLException {
+public final class ColumnNotFoundException extends MetaDataSQLException {
private static final long serialVersionUID = -1305402273592303335L;
- public UnknownColumnException(final String columnExpression, final String
segmentTypeMessage) {
- super(XOpenSQLState.NOT_FOUND, 6, "Unknown column '%s' in '%s'.",
columnExpression, segmentTypeMessage);
+ public ColumnNotFoundException(final String columnExpression, final String
segmentTypeMessage) {
+ super(XOpenSQLState.NOT_FOUND, 4, "Unknown column '%s' in '%s'.",
columnExpression, segmentTypeMessage);
}
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/InvalidDataNodeFormatException.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/InvalidDataNodeFormatException.java
index dd1ec46c24a..ddd09102e20 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/InvalidDataNodeFormatException.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/InvalidDataNodeFormatException.java
@@ -28,10 +28,10 @@ public final class InvalidDataNodeFormatException extends
MetaDataSQLException {
private static final long serialVersionUID = 192279170808654743L;
public InvalidDataNodeFormatException(final String dataNode) {
- super(XOpenSQLState.GENERAL_ERROR, 1, "Invalid format for actual data
node `%s`.", dataNode);
+ super(XOpenSQLState.GENERAL_ERROR, 1, "Invalid format for actual data
node '%s'.", dataNode);
}
public InvalidDataNodeFormatException(final String dataNode, final String
reason) {
- super(XOpenSQLState.GENERAL_ERROR, 1, "Invalid format for data node
`%s`, reason is: %s.", dataNode, reason);
+ super(XOpenSQLState.GENERAL_ERROR, 1, "Invalid format for data node
'%s', reason is: %s.", dataNode, reason);
}
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/SchemaNotFoundException.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/SchemaNotFoundException.java
index ece75f4d59a..654c295bd09 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/SchemaNotFoundException.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/SchemaNotFoundException.java
@@ -28,6 +28,6 @@ public final class SchemaNotFoundException extends
MetaDataSQLException {
private static final long serialVersionUID = 2722045034640737328L;
public SchemaNotFoundException(final String schemaName) {
- super(XOpenSQLState.NOT_FOUND, 20, "Schema `%s` does not exist.",
schemaName);
+ super(XOpenSQLState.NOT_FOUND, 2, "Schema '%s' does not exist.",
schemaName);
}
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/TableNotFoundException.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/TableNotFoundException.java
index 1bb9df61951..f797803a236 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/TableNotFoundException.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/TableNotFoundException.java
@@ -28,6 +28,10 @@ public final class TableNotFoundException extends
MetaDataSQLException {
private static final long serialVersionUID = -2507596759730534895L;
public TableNotFoundException(final String tableName) {
- super(XOpenSQLState.NOT_FOUND, 7, "Table or view `%s` does not
exist.", tableName);
+ super(XOpenSQLState.NOT_FOUND, 3, "Table or view '%s' does not
exist.", tableName);
+ }
+
+ public TableNotFoundException(final String tableName, final String
storageUnitName) {
+ super(XOpenSQLState.NOT_FOUND, 3, "Table or view '%s' does not exist
in storage unit '%s'.", tableName, storageUnitName);
}
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/exception/UnsupportedActualDataNodeStructureException.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/exception/UnsupportedActualDataNodeStructureException.java
index a36646b8f42..5f9e361c435 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/exception/UnsupportedActualDataNodeStructureException.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/exception/UnsupportedActualDataNodeStructureException.java
@@ -31,6 +31,6 @@ public final class
UnsupportedActualDataNodeStructureException extends MetaDataS
private static final long serialVersionUID = -8921823916974492519L;
public UnsupportedActualDataNodeStructureException(final DataNode
dataNode, final Collection<String> jdbcUrlPrefixes) {
- super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 0, "Can not support 3-tier
structure for actual data node `%s` with JDBC `%s`.", dataNode.format(),
jdbcUrlPrefixes.toString());
+ super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 0, "Can not support 3-tier
structure for actual data node '%s' with JDBC '%s'.", dataNode.format(),
jdbcUrlPrefixes.toString());
}
}
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
index f7a9fb05a99..fd82bbcc35b 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
@@ -127,11 +127,11 @@ public final class SingleRuleConfigurationDecorator
implements RuleConfiguration
Collection<String> result = new LinkedHashSet<>();
for (DataNode each : configuredDataNodes) {
ShardingSpherePreconditions.checkState(actualDataNodes.containsKey(each.getTableName()),
- () -> new
InvalidSingleRuleConfigurationException(String.format("Single table `%s` does
not exist", getTableNodeString(isSchemaSupportedDatabaseType, each))));
+ () -> new
InvalidSingleRuleConfigurationException(String.format("Single table '%s' does
not exist", getTableNodeString(isSchemaSupportedDatabaseType, each))));
DataNode actualDataNode =
actualDataNodes.get(each.getTableName()).iterator().next();
String tableNodeStr =
getTableNodeString(isSchemaSupportedDatabaseType, actualDataNode);
ShardingSpherePreconditions.checkState(actualDataNode.equals(each),
- () -> new
InvalidSingleRuleConfigurationException(String.format("Single table `%s` is
found that does not match %s", tableNodeStr,
+ () -> new
InvalidSingleRuleConfigurationException(String.format("Single table '%s' is
found that does not match %s", tableNodeStr,
getTableNodeString(isSchemaSupportedDatabaseType,
each))));
result.add(tableNodeStr);
}
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/exception/DropNotEmptySchemaException.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/exception/DropNotEmptySchemaException.java
index 70a854b6f23..c8d74d8b6cc 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/exception/DropNotEmptySchemaException.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/exception/DropNotEmptySchemaException.java
@@ -28,6 +28,6 @@ public final class DropNotEmptySchemaException extends
MetaDataSQLException {
private static final long serialVersionUID = 5285619119572894557L;
public DropNotEmptySchemaException(final String schemaName) {
- super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 30, "Can not drop schema
`%s` because of contains tables.", schemaName);
+ super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 30, "Can not drop schema
'%s' because of contains tables.", schemaName);
}
}
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/exception/SingleTableNotFoundException.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/exception/SingleTableNotFoundException.java
index ee2fd6a2910..a302f0baedc 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/exception/SingleTableNotFoundException.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/exception/SingleTableNotFoundException.java
@@ -28,6 +28,6 @@ public final class SingleTableNotFoundException extends
MetaDataSQLException {
private static final long serialVersionUID = 3498790429190415298L;
public SingleTableNotFoundException(final String tableName) {
- super(XOpenSQLState.NOT_FOUND, 21, "Single table `%s` does not
exist.", tableName);
+ super(XOpenSQLState.NOT_FOUND, 21, "Single table '%s' does not
exist.", tableName);
}
}
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/exception/SingleTablesLoadingException.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/exception/SingleTablesLoadingException.java
index 76ac8f3a4c8..662d5911950 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/exception/SingleTablesLoadingException.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/exception/SingleTablesLoadingException.java
@@ -30,6 +30,6 @@ public final class SingleTablesLoadingException extends
MetaDataSQLException {
private static final long serialVersionUID = 698261896187918188L;
public SingleTablesLoadingException(final String databaseName, final
String dataSourceName, final SQLException cause) {
- super(XOpenSQLState.GENERAL_ERROR, 22, "Can not load table with
database name `%s` and data source name `%s`, reason is: %s", databaseName,
dataSourceName, cause.getMessage());
+ super(XOpenSQLState.GENERAL_ERROR, 22, "Can not load table with
database name '%s' and data source name '%s', reason is: %s", databaseName,
dataSourceName, cause.getMessage());
}
}
diff --git
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/exception/MissingRequiredSingleTableException.java
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/exception/MissingRequiredSingleTableException.java
deleted file mode 100644
index 425e8bd6686..00000000000
---
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/exception/MissingRequiredSingleTableException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.single.distsql.handler.exception;
-
-import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
-import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.MetaDataSQLException;
-
-/**
- * Missing required single table exception.
- */
-public final class MissingRequiredSingleTableException extends
MetaDataSQLException {
-
- private static final long serialVersionUID = 3155006580453893122L;
-
- public MissingRequiredSingleTableException(final String storageUnitName,
final String tableName) {
- super(XOpenSQLState.NOT_FOUND, 8, "Missing required table '%s' in
storage unit '%s'.", tableName, storageUnitName);
- }
-}
diff --git
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
index ce04e3b71b6..0c4718c80c8 100644
---
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
+++
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
@@ -19,13 +19,14 @@ package
org.apache.shardingsphere.single.distsql.handler.update;
import lombok.Setter;
import
org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.database.DatabaseRuleCreateExecutor;
-import
org.apache.shardingsphere.infra.exception.resource.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.infra.database.DatabaseTypeEngine;
import
org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import
org.apache.shardingsphere.infra.exception.InvalidDataNodeFormatException;
+import org.apache.shardingsphere.infra.exception.TableNotFoundException;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.TableExistsException;
+import
org.apache.shardingsphere.infra.exception.resource.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -33,7 +34,6 @@ import
org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMappe
import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration;
import org.apache.shardingsphere.single.api.constant.SingleTableConstants;
import org.apache.shardingsphere.single.datanode.SingleTableDataNodeLoader;
-import
org.apache.shardingsphere.single.distsql.handler.exception.MissingRequiredSingleTableException;
import org.apache.shardingsphere.single.distsql.segment.SingleTableSegment;
import
org.apache.shardingsphere.single.distsql.statement.rdl.LoadSingleTableStatement;
import org.apache.shardingsphere.single.rule.SingleRule;
@@ -42,8 +42,6 @@ import
org.apache.shardingsphere.single.util.SingleTableLoadUtils;
import javax.sql.DataSource;
import java.util.Collection;
import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
@@ -93,25 +91,14 @@ public final class LoadSingleTableExecutor implements
DatabaseRuleCreateExecutor
}
}
- private Collection<String> getRequiredTables(final
LoadSingleTableStatement sqlStatement) {
- if (null != rule) {
- return
sqlStatement.getTables().stream().map(SingleTableSegment::toString).filter(each
->
!rule.getConfiguration().getTables().contains(each)).collect(Collectors.toSet());
- }
- return
sqlStatement.getTables().stream().map(SingleTableSegment::toString).collect(Collectors.toSet());
- }
-
- private Collection<String> getRequiredDataSources(final
LoadSingleTableStatement sqlStatement) {
- return
sqlStatement.getTables().stream().map(SingleTableSegment::getStorageUnitName)
- .filter(each ->
!SingleTableConstants.ASTERISK.equals(each)).collect(Collectors.toSet());
- }
-
private void checkStorageUnits(final LoadSingleTableStatement
sqlStatement) {
Collection<String> requiredDataSources =
getRequiredDataSources(sqlStatement);
if (requiredDataSources.isEmpty()) {
return;
}
Collection<String> notExistedDataSources =
database.getResourceMetaData().getNotExistedDataSources(requiredDataSources);
- Collection<String> logicDataSources = getLogicDataSources(database);
+ Collection<String> logicDataSources =
database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class).stream()
+ .flatMap(each ->
each.getDataSourceMapper().keySet().stream()).collect(Collectors.toSet());
notExistedDataSources.removeIf(logicDataSources::contains);
ShardingSpherePreconditions.checkState(notExistedDataSources.isEmpty(), () ->
new MissingRequiredStorageUnitsException(database.getName(),
notExistedDataSources));
}
@@ -123,33 +110,30 @@ public final class LoadSingleTableExecutor implements
DatabaseRuleCreateExecutor
}
ResourceMetaData resourceMetaData = database.getResourceMetaData();
Map<String, DataSource> aggregateDataSourceMap =
SingleTableLoadUtils.getAggregatedDataSourceMap(
- resourceMetaData.getStorageUnits().entrySet().stream()
- .collect(Collectors.toMap(Entry::getKey, entry ->
entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue,
LinkedHashMap::new)),
- database.getRuleMetaData().getRules());
- Map<String, Map<String, Collection<String>>> actualTableNodes = new
LinkedHashMap<>();
- for (String each : requiredDataSources) {
- DataSource dataSource = aggregateDataSourceMap.get(each);
- Map<String, Collection<String>> schemaTableNames =
SingleTableDataNodeLoader.loadSchemaTableNames(database.getName(),
DatabaseTypeEngine.getStorageType(dataSource), dataSource, each);
- if (!schemaTableNames.isEmpty()) {
- actualTableNodes.put(each, schemaTableNames);
- }
- }
+
resourceMetaData.getStorageUnits().entrySet().stream().collect(Collectors.toMap(Entry::getKey,
entry -> entry.getValue().getDataSource())),
database.getRuleMetaData().getRules());
+ Map<String, Map<String, Collection<String>>> actualTableNodes =
getActualTableNodes(requiredDataSources, aggregateDataSourceMap);
for (SingleTableSegment each : sqlStatement.getTables()) {
- if (SingleTableConstants.ASTERISK.equals(each.getTableName())) {
- continue;
+ String tableName = each.getTableName();
+ if (!SingleTableConstants.ASTERISK.equals(tableName)) {
+ String storageUnitName = each.getStorageUnitName();
+
ShardingSpherePreconditions.checkState(actualTableNodes.containsKey(storageUnitName)
&&
actualTableNodes.get(storageUnitName).get(defaultSchemaName).contains(tableName),
+ () -> new TableNotFoundException(storageUnitName,
tableName));
}
- Map<String, Collection<String>> schemaTableMap =
actualTableNodes.getOrDefault(each.getStorageUnitName(), new LinkedHashMap<>());
- ShardingSpherePreconditions.checkState(!schemaTableMap.isEmpty(),
() -> new MissingRequiredSingleTableException(each.getStorageUnitName(),
each.getTableName()));
- Collection<String> schemaTables =
schemaTableMap.getOrDefault(defaultSchemaName, new LinkedList<>());
- ShardingSpherePreconditions.checkState(!schemaTables.isEmpty() &&
schemaTables.contains(each.getTableName()),
- () -> new
MissingRequiredSingleTableException(each.getStorageUnitName(),
each.getTableName()));
}
}
- private Collection<String> getLogicDataSources(final
ShardingSphereDatabase database) {
- Collection<String> result = new LinkedHashSet<>();
- for (DataSourceMapperRuleAttribute each :
database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)) {
- result.addAll(each.getDataSourceMapper().keySet());
+ private Collection<String> getRequiredDataSources(final
LoadSingleTableStatement sqlStatement) {
+ return
sqlStatement.getTables().stream().map(SingleTableSegment::getStorageUnitName).filter(each
-> !SingleTableConstants.ASTERISK.equals(each)).collect(Collectors.toSet());
+ }
+
+ private Map<String, Map<String, Collection<String>>>
getActualTableNodes(final Collection<String> requiredDataSources, final
Map<String, DataSource> aggregateDataSourceMap) {
+ Map<String, Map<String, Collection<String>>> result = new
LinkedHashMap<>();
+ for (String each : requiredDataSources) {
+ DataSource dataSource = aggregateDataSourceMap.get(each);
+ Map<String, Collection<String>> schemaTableNames =
SingleTableDataNodeLoader.loadSchemaTableNames(database.getName(),
DatabaseTypeEngine.getStorageType(dataSource), dataSource, each);
+ if (!schemaTableNames.isEmpty()) {
+ result.put(each, schemaTableNames);
+ }
}
return result;
}
@@ -164,6 +148,13 @@ public final class LoadSingleTableExecutor implements
DatabaseRuleCreateExecutor
return result;
}
+ private Collection<String> getRequiredTables(final
LoadSingleTableStatement sqlStatement) {
+ if (null != rule) {
+ return
sqlStatement.getTables().stream().map(SingleTableSegment::toString).filter(each
->
!rule.getConfiguration().getTables().contains(each)).collect(Collectors.toSet());
+ }
+ return
sqlStatement.getTables().stream().map(SingleTableSegment::toString).collect(Collectors.toSet());
+ }
+
@Override
public Class<SingleRule> getRuleClass() {
return SingleRule.class;
diff --git
a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
index a848adab9b4..cc95186cdb5 100644
---
a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
+++
b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
@@ -17,11 +17,12 @@
package org.apache.shardingsphere.single.distsql.handler.update;
-import
org.apache.shardingsphere.infra.exception.resource.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.TableExistsException;
+import
org.apache.shardingsphere.infra.exception.resource.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import
org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration;
import org.apache.shardingsphere.single.distsql.segment.SingleTableSegment;
@@ -73,9 +74,10 @@ class LoadSingleTableExecutorTest {
@Test
void assertCheckWithInvalidStorageUnit() {
- LoadSingleTableStatement sqlStatement = new
LoadSingleTableStatement(Collections.singletonList(new
SingleTableSegment("ds_0", null, "foo")));
when(database.getName()).thenReturn("foo_db");
+
when(database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)).thenReturn(Collections.emptyList());
executor.setDatabase(database);
+ LoadSingleTableStatement sqlStatement = new
LoadSingleTableStatement(Collections.singletonList(new
SingleTableSegment("ds_0", null, "foo")));
assertThrows(MissingRequiredStorageUnitsException.class, () ->
executor.checkBeforeUpdate(sqlStatement));
}
diff --git
a/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/statement/ShardingPreparedStatementTest.java
b/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/statement/ShardingPreparedStatementTest.java
index 5dc4c76db16..f64aa982aa5 100644
---
a/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/statement/ShardingPreparedStatementTest.java
+++
b/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/statement/ShardingPreparedStatementTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.test.e2e.driver.statement;
-import org.apache.shardingsphere.infra.exception.UnknownColumnException;
+import org.apache.shardingsphere.infra.exception.ColumnNotFoundException;
import org.apache.shardingsphere.test.e2e.driver.AbstractShardingDriverTest;
import
org.apache.shardingsphere.test.e2e.driver.fixture.keygen.ResetIncrementKeyGenerateAlgorithmFixture;
import org.junit.jupiter.api.Test;
@@ -668,6 +668,6 @@ class ShardingPreparedStatementTest extends
AbstractShardingDriverTest {
@Test
void assertColumnNotFoundException() {
- assertThrows(UnknownColumnException.class, () ->
getShardingSphereDataSource().getConnection().prepareStatement(UPDATE_WITH_ERROR_COLUMN));
+ assertThrows(ColumnNotFoundException.class, () ->
getShardingSphereDataSource().getConnection().prepareStatement(UPDATE_WITH_ERROR_COLUMN));
}
}