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 37b9dc7 Add distSQL syntax: 'drop sharding algorithm'. (#11346) 37b9dc7 is described below commit 37b9dc70898e9dd15df076696dce3c950c258aaf Author: Raigor <raigor.ji...@gmail.com> AuthorDate: Fri Jul 16 15:14:14 2021 +0800 Add distSQL syntax: 'drop sharding algorithm'. (#11346) * Add distSQL syntax: 'drop sharding algorithm' * update comment. * Optimize the code. * Optimize param name. * Check 'autoTables' when get algorithms in uesd. Modify method name. --- .../DropShardingAlgorithmStatementUpdater.java | 110 +++++++++++++++++++++ ...here.infra.distsql.update.RuleDefinitionUpdater | 1 + .../DropShardingAlgorithmStatementUpdaterTest.java | 87 ++++++++++++++++ .../src/main/antlr4/imports/sharding/Keyword.g4 | 4 + .../main/antlr4/imports/sharding/RDLStatement.g4 | 4 + .../parser/autogen/ShardingRuleStatement.g4 | 1 + .../core/ShardingRuleSQLStatementVisitor.java | 7 ++ .../statement/DropShardingAlgorithmStatement.java} | 32 +++--- .../exception/rule/AlgorithmInUsedException.java | 30 +++--- .../rule/RequiredAlgorithmMissedException.java | 34 +++---- 10 files changed, 259 insertions(+), 51 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/DropShardingAlgorithmStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmStatementUpdater.java new file mode 100644 index 0000000..2c7f68f --- /dev/null +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmStatementUpdater.java @@ -0,0 +1,110 @@ +/* + * 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.distsql.handler.update; + +import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException; +import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; +import org.apache.shardingsphere.infra.distsql.exception.rule.AlgorithmInUsedException; +import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; +import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; +import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; +import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingAlgorithmStatement; + +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * Drop sharding algorithm statement updater. + */ +public final class DropShardingAlgorithmStatementUpdater implements RuleDefinitionDropUpdater<DropShardingAlgorithmStatement, ShardingRuleConfiguration> { + + @Override + public void checkSQLStatement(final String schemaName, final DropShardingAlgorithmStatement sqlStatement, + final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException { + checkCurrentRuleConfiguration(schemaName, currentRuleConfig); + checkToBeDroppedShardingAlgorithms(schemaName, sqlStatement, currentRuleConfig); + checkShardingAlgorithmsInUsed(schemaName, sqlStatement, currentRuleConfig); + } + + private void checkCurrentRuleConfiguration(final String schemaName, final ShardingRuleConfiguration currentRuleConfig) throws RequiredAlgorithmMissedException { + if (null == currentRuleConfig) { + throw new RequiredAlgorithmMissedException(schemaName); + } + } + + private void checkToBeDroppedShardingAlgorithms(final String schemaName, final DropShardingAlgorithmStatement sqlStatement, + final ShardingRuleConfiguration currentRuleConfig) throws RequiredAlgorithmMissedException { + Collection<String> currentShardingAlgorithms = getCurrentShardingAlgorithms(currentRuleConfig); + Collection<String> notExistedAlgorithms = sqlStatement.getAlgorithmNames().stream().filter(each -> !currentShardingAlgorithms.contains(each)).collect(Collectors.toList()); + if (!notExistedAlgorithms.isEmpty()) { + throw new RequiredAlgorithmMissedException(schemaName, notExistedAlgorithms); + } + } + + private void checkShardingAlgorithmsInUsed(final String schemaName, final DropShardingAlgorithmStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) + throws AlgorithmInUsedException { + Collection<String> allInUsed = getAllOfAlgorithmsInUsed(currentRuleConfig); + Collection<String> usedAlgorithms = sqlStatement.getAlgorithmNames().stream().filter(allInUsed::contains).collect(Collectors.toList()); + if (!usedAlgorithms.isEmpty()) { + throw new AlgorithmInUsedException(schemaName, usedAlgorithms); + } + } + + private Collection<String> getAllOfAlgorithmsInUsed(final ShardingRuleConfiguration shardingRuleConfig) { + Collection<String> result = new LinkedHashSet<>(); + shardingRuleConfig.getTables().stream().forEach(each -> { + if (Objects.nonNull(each.getDatabaseShardingStrategy())) { + result.add(each.getDatabaseShardingStrategy().getShardingAlgorithmName()); + } + if (Objects.nonNull(each.getTableShardingStrategy())) { + result.add(each.getTableShardingStrategy().getShardingAlgorithmName()); + } + }); + shardingRuleConfig.getAutoTables().stream().filter(each -> Objects.nonNull(each.getShardingStrategy())) + .forEach(each -> result.add(each.getShardingStrategy().getShardingAlgorithmName())); + return result; + } + + private Collection<String> getCurrentShardingAlgorithms(final ShardingRuleConfiguration shardingRuleConfig) { + return shardingRuleConfig.getShardingAlgorithms().keySet(); + } + + @Override + public boolean updateCurrentRuleConfiguration(final DropShardingAlgorithmStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) { + for (String each : sqlStatement.getAlgorithmNames()) { + dropShardingAlgorithm(currentRuleConfig, each); + } + return false; + } + + private void dropShardingAlgorithm(final ShardingRuleConfiguration currentRuleConfig, final String algorithmName) { + getCurrentShardingAlgorithms(currentRuleConfig).removeIf(key -> algorithmName.equalsIgnoreCase(key)); + } + + @Override + public Class<ShardingRuleConfiguration> getRuleConfigurationClass() { + return ShardingRuleConfiguration.class; + } + + @Override + public String getType() { + return DropShardingAlgorithmStatement.class.getCanonicalName(); + } +} diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater index a2d5402..8258951 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater @@ -18,6 +18,7 @@ org.apache.shardingsphere.sharding.distsql.handler.update.CreateShardingTableRuleStatementUpdater org.apache.shardingsphere.sharding.distsql.handler.update.AlterShardingTableRuleStatementUpdater org.apache.shardingsphere.sharding.distsql.handler.update.DropShardingTableRuleStatementUpdater +org.apache.shardingsphere.sharding.distsql.handler.update.DropShardingAlgorithmStatementUpdater org.apache.shardingsphere.sharding.distsql.handler.update.CreateShardingBindingTableRuleStatementUpdater org.apache.shardingsphere.sharding.distsql.handler.update.AlterShardingBindingTableRuleStatementUpdater org.apache.shardingsphere.sharding.distsql.handler.update.DropShardingBindingTableRuleStatementUpdater diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingAlgorithmStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingAlgorithmStatementUpdaterTest.java new file mode 100644 index 0000000..6f60be2 --- /dev/null +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingAlgorithmStatementUpdaterTest.java @@ -0,0 +1,87 @@ +/* + * 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.distsql.update; + +import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; +import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; +import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException; +import org.apache.shardingsphere.infra.distsql.exception.rule.AlgorithmInUsedException; +import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; +import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; +import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; +import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration; +import org.apache.shardingsphere.sharding.distsql.handler.update.DropShardingAlgorithmStatementUpdater; +import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingAlgorithmStatement; +import org.junit.Test; + +import java.util.Collections; +import java.util.Properties; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; +import static org.mockito.Mockito.mock; + +public final class DropShardingAlgorithmStatementUpdaterTest { + + private final DropShardingAlgorithmStatementUpdater updater = new DropShardingAlgorithmStatementUpdater(); + + @Test(expected = RequiredAlgorithmMissedException.class) + public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException { + updater.checkSQLStatement("foo", new DropShardingAlgorithmStatement(Collections.emptyList()), null, mock(ShardingSphereResource.class)); + } + + @Test(expected = RequiredAlgorithmMissedException.class) + public void assertCheckSQLStatementWithoutExistedAlgorithm() throws RuleDefinitionViolationException { + updater.checkSQLStatement("foo", createSQLStatement("t_order"), new ShardingRuleConfiguration(), mock(ShardingSphereResource.class)); + } + + @Test(expected = AlgorithmInUsedException.class) + public void assertCheckSQLStatementWithBindingTableRule() throws RuleDefinitionViolationException { + updater.checkSQLStatement("foo", createSQLStatement("t_order_tb_inline"), createCurrentRuleConfiguration(), mock(ShardingSphereResource.class)); + } + + @Test + public void assertUpdateCurrentRuleConfiguration() { + String toBeDroppedAlgorithmName = "t_test"; + ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); + assertThat(currentRuleConfig.getShardingAlgorithms().size(), is(3)); + assertTrue(currentRuleConfig.getShardingAlgorithms().containsKey(toBeDroppedAlgorithmName)); + updater.updateCurrentRuleConfiguration(createSQLStatement(toBeDroppedAlgorithmName), currentRuleConfig); + assertThat(currentRuleConfig.getShardingAlgorithms().size(), is(2)); + assertFalse(currentRuleConfig.getShardingAlgorithms().containsKey(toBeDroppedAlgorithmName)); + assertTrue(currentRuleConfig.getShardingAlgorithms().containsKey("t_order_db_inline")); + } + + private DropShardingAlgorithmStatement createSQLStatement(final String algorithmName) { + return new DropShardingAlgorithmStatement(Collections.singleton(algorithmName)); + } + + private ShardingRuleConfiguration createCurrentRuleConfiguration() { + ShardingRuleConfiguration result = new ShardingRuleConfiguration(); + ShardingTableRuleConfiguration tableRuleConfiguration = new ShardingTableRuleConfiguration("t_order"); + tableRuleConfiguration.setDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("column", "t_order_db_inline")); + tableRuleConfiguration.setTableShardingStrategy(new StandardShardingStrategyConfiguration("column", "t_order_tb_inline")); + result.getTables().add(tableRuleConfiguration); + result.getShardingAlgorithms().put("t_order_db_inline", new ShardingSphereAlgorithmConfiguration("standard", new Properties())); + result.getShardingAlgorithms().put("t_order_tb_inline", new ShardingSphereAlgorithmConfiguration("standard", new Properties())); + result.getShardingAlgorithms().put("t_test", new ShardingSphereAlgorithmConfiguration("standard", new Properties())); + return result; + } +} diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/Keyword.g4 b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/Keyword.g4 index 0f5cc1a..64dcd4a 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/Keyword.g4 +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/Keyword.g4 @@ -102,3 +102,7 @@ RULES COLUMNS : C O L U M N S ; + +ALGORITHM + : A L G O R I T H M + ; diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/RDLStatement.g4 b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/RDLStatement.g4 index 2c3d092..c91eb99 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/RDLStatement.g4 +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/RDLStatement.g4 @@ -54,6 +54,10 @@ dropShardingBindingTableRules dropShardingBroadcastTableRules : DROP SHARDING BROADCAST TABLE RULES ; + +dropShardingAlgorithm + : DROP SHARDING ALGORITHM algorithmName (COMMA algorithmName)* + ; shardingTableRuleDefinition : tableName LP resources (COMMA shardingColumn)? (COMMA algorithmDefinition)? (COMMA keyGenerateStrategy)? RP diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingRuleStatement.g4 b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingRuleStatement.g4 index 5e85e20..6800dcc 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingRuleStatement.g4 +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingRuleStatement.g4 @@ -29,6 +29,7 @@ execute | dropShardingTableRule | dropShardingBindingTableRules | dropShardingBroadcastTableRules + | dropShardingAlgorithm | showShardingTableRules | showShardingBindingTableRules | showShardingBroadcastTableRules diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingRuleSQLStatementVisitor.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingRuleSQLStatementVisitor.java index 3b77b38..3ef40f8 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingRuleSQLStatementVisitor.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingRuleSQLStatementVisitor.java @@ -33,6 +33,7 @@ import org.apache.shardingsphere.distsql.parser.autogen.ShardingRuleStatementPar import org.apache.shardingsphere.distsql.parser.autogen.ShardingRuleStatementParser.DropShardingBindingTableRulesContext; import org.apache.shardingsphere.distsql.parser.autogen.ShardingRuleStatementParser.DropShardingBroadcastTableRulesContext; import org.apache.shardingsphere.distsql.parser.autogen.ShardingRuleStatementParser.DropShardingTableRuleContext; +import org.apache.shardingsphere.distsql.parser.autogen.ShardingRuleStatementParser.DropShardingAlgorithmContext; import org.apache.shardingsphere.distsql.parser.autogen.ShardingRuleStatementParser.SchemaNameContext; import org.apache.shardingsphere.distsql.parser.autogen.ShardingRuleStatementParser.ShardingTableRuleDefinitionContext; import org.apache.shardingsphere.distsql.parser.autogen.ShardingRuleStatementParser.ShowShardingBindingTableRulesContext; @@ -49,6 +50,7 @@ import org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardin import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingBindingTableRulesStatement; import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingBroadcastTableRulesStatement; import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingTableRuleStatement; +import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingAlgorithmStatement; import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingBindingTableRulesStatement; import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingBroadcastTableRulesStatement; import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingTableRulesStatement; @@ -130,6 +132,11 @@ public final class ShardingRuleSQLStatementVisitor extends ShardingRuleStatement } @Override + public ASTNode visitDropShardingAlgorithm(final DropShardingAlgorithmContext ctx) { + return new DropShardingAlgorithmStatement(ctx.algorithmName().stream().map(each -> each.getText()).collect(Collectors.toList())); + } + + @Override public ASTNode visitShowShardingTableRules(final ShowShardingTableRulesContext ctx) { return new ShowShardingTableRulesStatement(null == ctx.tableRule() ? null : ctx.tableRule().tableName().getText(), null == ctx.schemaName() ? null : (SchemaSegment) visit(ctx.schemaName())); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingRuleStatement.g4 b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/statement/DropShardingAlgorithmStatement.java similarity index 60% copy from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingRuleStatement.g4 copy to shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/statement/DropShardingAlgorithmStatement.java index 5e85e20..db4d4ec 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingRuleStatement.g4 +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/statement/DropShardingAlgorithmStatement.java @@ -15,22 +15,20 @@ * limitations under the License. */ -grammar ShardingRuleStatement; +package org.apache.shardingsphere.sharding.distsql.parser.statement; -import Symbol, RDLStatement, RQLStatement; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.apache.shardingsphere.distsql.parser.statement.rdl.drop.DropRuleStatement; -execute - : (createShardingTableRule - | createShardingBindingTableRules - | createShardingBroadcastTableRules - | alterShardingTableRule - | alterShardingBindingTableRules - | alterShardingBroadcastTableRules - | dropShardingTableRule - | dropShardingBindingTableRules - | dropShardingBroadcastTableRules - | showShardingTableRules - | showShardingBindingTableRules - | showShardingBroadcastTableRules - ) SEMI? - ; +import java.util.Collection; + +/** + * Drop sharding algorithm statement. + */ +@RequiredArgsConstructor +@Getter +public final class DropShardingAlgorithmStatement extends DropRuleStatement { + + private final Collection<String> algorithmNames; +} diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingRuleStatement.g4 b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/AlgorithmInUsedException.java similarity index 59% copy from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingRuleStatement.g4 copy to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/AlgorithmInUsedException.java index 5e85e20..7387dfc 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingRuleStatement.g4 +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/AlgorithmInUsedException.java @@ -15,22 +15,18 @@ * limitations under the License. */ -grammar ShardingRuleStatement; +package org.apache.shardingsphere.infra.distsql.exception.rule; -import Symbol, RDLStatement, RQLStatement; +import java.util.Collection; -execute - : (createShardingTableRule - | createShardingBindingTableRules - | createShardingBroadcastTableRules - | alterShardingTableRule - | alterShardingBindingTableRules - | alterShardingBroadcastTableRules - | dropShardingTableRule - | dropShardingBindingTableRules - | dropShardingBroadcastTableRules - | showShardingTableRules - | showShardingBindingTableRules - | showShardingBroadcastTableRules - ) SEMI? - ; +/** + * Algorithm in used exception. + */ +public final class AlgorithmInUsedException extends RuleDefinitionViolationException { + + private static final long serialVersionUID = -5748228542420285726L; + + public AlgorithmInUsedException(final String schemaName, final Collection<String> algorithmNames) { + super(1116, String.format("Sharding algorithms `%s` in schema `%s` are still in used.", algorithmNames, schemaName)); + } +} diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingRuleStatement.g4 b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/RequiredAlgorithmMissedException.java similarity index 52% copy from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingRuleStatement.g4 copy to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/RequiredAlgorithmMissedException.java index 5e85e20..716a232 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingRuleStatement.g4 +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/RequiredAlgorithmMissedException.java @@ -15,22 +15,22 @@ * limitations under the License. */ -grammar ShardingRuleStatement; +package org.apache.shardingsphere.infra.distsql.exception.rule; -import Symbol, RDLStatement, RQLStatement; +import java.util.Collection; -execute - : (createShardingTableRule - | createShardingBindingTableRules - | createShardingBroadcastTableRules - | alterShardingTableRule - | alterShardingBindingTableRules - | alterShardingBroadcastTableRules - | dropShardingTableRule - | dropShardingBindingTableRules - | dropShardingBroadcastTableRules - | showShardingTableRules - | showShardingBindingTableRules - | showShardingBroadcastTableRules - ) SEMI? - ; +/** + * Required algorithm missed exception. + */ +public final class RequiredAlgorithmMissedException extends RuleDefinitionViolationException { + + private static final long serialVersionUID = -1952698375135777585L; + + public RequiredAlgorithmMissedException(final String schemaName) { + super(1115, String.format("Sharding algorithm does not exist in schema `%s`.", schemaName)); + } + + public RequiredAlgorithmMissedException(final String schemaName, final Collection<String> algorithmNames) { + super(1115, String.format("Sharding algorithms `%s` do not exist in schema `%s`.", algorithmNames, schemaName)); + } +}