You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/08/08 02:54:14 UTC
[shardingsphere] branch master updated: Fix #11612 Incorrect
DistSQL prompt not friendly enough (#11684)
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 c948749 Fix #11612 Incorrect DistSQL prompt not friendly enough (#11684)
c948749 is described below
commit c948749c1cf34abdaa53a91a039be2100707ed64
Author: lanchengx <52...@users.noreply.github.com>
AuthorDate: Sun Aug 8 10:53:31 2021 +0800
Fix #11612 Incorrect DistSQL prompt not friendly enough (#11684)
* Fix issue #11612, add check for sql statement
* Fix issue #11612, add check for sql statement
* recovery space
* modify the exception type
* Delete a blank line
* Fix issue #11612, Combination judgment condition
---
.../handler/update/CreateShardingTableRuleStatementUpdater.java | 9 +++++++++
.../update/CreateShardingTableRuleStatementUpdaterTest.java | 8 +++++++-
.../exception/rule/InvalidAlgorithmConfigurationException.java | 6 +++++-
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableRuleStatementUpdater.java
index 44cf26c..4fca678 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableRuleStatementUpdater.java
@@ -65,10 +65,19 @@ public final class CreateShardingTableRuleStatementUpdater implements RuleDefini
Collection<String> extraResources = getResourcesFromDataSourceContainedRules(shardingSphereMetaData.getRuleMetaData().getRules());
checkToBeCreatedResource(schemaName, sqlStatement, shardingSphereMetaData.getResource(), extraResources);
checkDuplicateTables(schemaName, sqlStatement, currentRuleConfig);
+ checkShardingAlgorithmsCompleteness(sqlStatement);
checkToBeCreatedShardingAlgorithms(sqlStatement);
checkToBeCreatedKeyGenerators(sqlStatement);
}
+ private void checkShardingAlgorithmsCompleteness(final CreateShardingTableRuleStatement sqlStatement) throws InvalidAlgorithmConfigurationException {
+ for (TableRuleSegment each : sqlStatement.getRules()) {
+ if (null == each.getTableStrategy() || null == each.getTableStrategyColumn()) {
+ throw new InvalidAlgorithmConfigurationException("sharding");
+ }
+ }
+ }
+
private Collection<String> getResourcesFromDataSourceContainedRules(final Collection<ShardingSphereRule> rules) {
if (rules.isEmpty()) {
return Collections.emptySet();
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
index b4050d1..dc91c36 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
@@ -75,8 +75,14 @@ public final class CreateShardingTableRuleStatementUpdaterTest {
}
@Test(expected = InvalidAlgorithmConfigurationException.class)
+ public void assertCheckWithShardingAlgorithmsIncomplete() throws DistSQLException {
+ TableRuleSegment ruleSegment = new TableRuleSegment("t_order", Collections.emptyList(), null, null, null, null);
+ updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(ruleSegment), null);
+ }
+
+ @Test(expected = InvalidAlgorithmConfigurationException.class)
public void assertCheckSQLStatementWithoutToBeCreatedShardingAlgorithms() throws DistSQLException {
- TableRuleSegment ruleSegment = new TableRuleSegment("t_order", Collections.emptyList(), null, new AlgorithmSegment("INVALID_TYPE", new Properties()), null, null);
+ TableRuleSegment ruleSegment = new TableRuleSegment("t_order", Collections.emptyList(), "order_id", new AlgorithmSegment("INVALID_TYPE", new Properties()), null, null);
updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(ruleSegment), null);
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/InvalidAlgorithmConfigurationException.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/InvalidAlgorithmConfigurationException.java
index 95eb57a..8c1568a 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/InvalidAlgorithmConfigurationException.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/InvalidAlgorithmConfigurationException.java
@@ -27,6 +27,10 @@ public final class InvalidAlgorithmConfigurationException extends RuleDefinition
private static final long serialVersionUID = 9076740384552385180L;
public InvalidAlgorithmConfigurationException(final String algorithmType, final Collection<String> algorithms) {
- super(1114, String.format("Invalid %s algorithms %s", algorithmType, algorithms));
+ super(1114, String.format("Invalid %s algorithms %s.", algorithmType, algorithms));
+ }
+
+ public InvalidAlgorithmConfigurationException(final String algorithmType) {
+ super(1114, String.format("Invalid %s algorithms configuration.", algorithmType));
}
}