This is an automated email from the ASF dual-hosted git repository.
lanchengxiang 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 70168af Add IF EXISTS keyword to DROP SHARDING ALGORITHM; (#15640)
70168af is described below
commit 70168af65edd50c9b46f401a87ac25ecb6808a1f
Author: liguoping <[email protected]>
AuthorDate: Thu Mar 3 11:09:32 2022 +0800
Add IF EXISTS keyword to DROP SHARDING ALGORITHM; (#15640)
* define if exits
* update mock test
* add new test case for it
* fix ci error
* DropRuleStatement changed
* implementing hasAnyOneToBeDropped
* judge containsExistClause and currentRuleConfig is null
---
.../DropShardingAlgorithmStatementUpdater.java | 15 ++++++-
.../DropShardingAlgorithmStatementUpdaterTest.java | 39 ++++++++++++++++-
.../src/main/antlr4/imports/sharding/BaseRule.g4 | 4 ++
.../src/main/antlr4/imports/sharding/Keyword.g4 | 8 ++++
.../main/antlr4/imports/sharding/RDLStatement.g4 | 2 +-
.../core/ShardingDistSQLStatementVisitor.java | 6 ++-
.../distsql/rdl/drop/DropRuleStatementAssert.java | 5 +++
.../impl/DropShardingAlgorithmStatementAssert.java | 51 ++++++++++++++++++++++
.../jaxb/cases/domain/SQLParserTestCases.java | 5 +++
.../DropShardingAlgorithmStatementTestCase.java | 33 +++++++++-----
.../src/main/resources/case/rdl/drop.xml | 4 ++
.../src/main/resources/sql/supported/rdl/drop.xml | 1 +
12 files changed, 154 insertions(+), 19 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
index ad862f8..bff98a5 100644
---
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
@@ -17,9 +17,9 @@
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.exception.rule.RequiredAlgorithmMissedException;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException;
import
org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -39,6 +39,9 @@ public final class DropShardingAlgorithmStatementUpdater
implements RuleDefiniti
@Override
public void checkSQLStatement(final ShardingSphereMetaData
shardingSphereMetaData, final DropShardingAlgorithmStatement sqlStatement,
final ShardingRuleConfiguration
currentRuleConfig) throws RuleDefinitionViolationException {
+ if (null == currentRuleConfig && sqlStatement.isContainsExistClause())
{
+ return;
+ }
String schemaName = shardingSphereMetaData.getName();
checkCurrentRuleConfiguration(schemaName, currentRuleConfig);
checkToBeDroppedShardingAlgorithms(schemaName, sqlStatement,
currentRuleConfig);
@@ -53,6 +56,9 @@ public final class DropShardingAlgorithmStatementUpdater
implements RuleDefiniti
private void checkToBeDroppedShardingAlgorithms(final String schemaName,
final DropShardingAlgorithmStatement sqlStatement,
final
ShardingRuleConfiguration currentRuleConfig) throws
RequiredAlgorithmMissedException {
+ if (sqlStatement.isContainsExistClause()) {
+ return;
+ }
Collection<String> currentShardingAlgorithms =
getCurrentShardingAlgorithms(currentRuleConfig);
Collection<String> notExistedAlgorithms =
sqlStatement.getAlgorithmNames().stream().filter(each ->
!currentShardingAlgorithms.contains(each)).collect(Collectors.toList());
if (!notExistedAlgorithms.isEmpty()) {
@@ -103,6 +109,11 @@ public final class DropShardingAlgorithmStatementUpdater
implements RuleDefiniti
return false;
}
+ @Override
+ public boolean hasAnyOneToBeDropped(final DropShardingAlgorithmStatement
sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ return null != currentRuleConfig &&
!getIdenticalData(getCurrentShardingAlgorithms(currentRuleConfig),
sqlStatement.getAlgorithmNames()).isEmpty();
+ }
+
private void dropShardingAlgorithm(final ShardingRuleConfiguration
currentRuleConfig, final String algorithmName) {
getCurrentShardingAlgorithms(currentRuleConfig).removeIf(algorithmName::equalsIgnoreCase);
}
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
index d898ed0..4c7ae54 100644
---
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
@@ -18,9 +18,9 @@
package org.apache.shardingsphere.sharding.distsql.update;
import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.AlgorithmInUsedException;
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.ShardingSphereMetaData;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -36,9 +36,9 @@ import java.util.Collections;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
@RunWith(MockitoJUnitRunner.class)
public final class DropShardingAlgorithmStatementUpdaterTest {
@@ -53,16 +53,33 @@ public final class
DropShardingAlgorithmStatementUpdaterTest {
updater.checkSQLStatement(shardingSphereMetaData, new
DropShardingAlgorithmStatement(Collections.emptyList()), null);
}
+ @Test
+ public void assertCheckSQLStatementWithoutCurrentRuleWithIfExists() throws
RuleDefinitionViolationException {
+ DropShardingAlgorithmStatement dropShardingAlgorithmStatement = new
DropShardingAlgorithmStatement(Collections.emptyList());
+ dropShardingAlgorithmStatement.setContainsExistClause(true);
+ updater.checkSQLStatement(shardingSphereMetaData,
dropShardingAlgorithmStatement, null);
+ }
+
@Test(expected = RequiredAlgorithmMissedException.class)
public void assertCheckSQLStatementWithoutExistedAlgorithm() throws
RuleDefinitionViolationException {
updater.checkSQLStatement(shardingSphereMetaData,
createSQLStatement("t_order"), new ShardingRuleConfiguration());
}
+ @Test
+ public void assertCheckSQLStatementWithoutExistedAlgorithmWithIfExists()
throws RuleDefinitionViolationException {
+ updater.checkSQLStatement(shardingSphereMetaData,
createSQLStatementWithIfExists("t_order"), new ShardingRuleConfiguration());
+ }
+
@Test(expected = AlgorithmInUsedException.class)
public void assertCheckSQLStatementWithBindingTableRule() throws
RuleDefinitionViolationException {
updater.checkSQLStatement(shardingSphereMetaData,
createSQLStatement("t_order_tb_inline"), createCurrentRuleConfiguration());
}
+ @Test(expected = AlgorithmInUsedException.class)
+ public void assertCheckSQLStatementWithBindingTableRuleWithIfExists()
throws RuleDefinitionViolationException {
+ updater.checkSQLStatement(shardingSphereMetaData,
createSQLStatementWithIfExists("t_order_tb_inline"),
createCurrentRuleConfiguration());
+ }
+
@Test
public void assertUpdateCurrentRuleConfiguration() {
String toBeDroppedAlgorithmName = "t_test";
@@ -75,10 +92,28 @@ public final class
DropShardingAlgorithmStatementUpdaterTest {
assertTrue(currentRuleConfig.getShardingAlgorithms().containsKey("t_order_db_inline"));
}
+ @Test
+ public void assertUpdateCurrentRuleConfigurationWithIfExists() {
+ String toBeDroppedAlgorithmName = "t_test";
+ ShardingRuleConfiguration currentRuleConfig =
createCurrentRuleConfiguration();
+ assertThat(currentRuleConfig.getShardingAlgorithms().size(), is(3));
+
assertTrue(currentRuleConfig.getShardingAlgorithms().containsKey(toBeDroppedAlgorithmName));
+
updater.updateCurrentRuleConfiguration(createSQLStatementWithIfExists(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 DropShardingAlgorithmStatement
createSQLStatementWithIfExists(final String algorithmName) {
+ DropShardingAlgorithmStatement result = new
DropShardingAlgorithmStatement(Collections.singleton(algorithmName));
+ result.setContainsExistClause(true);
+ return result;
+ }
+
private ShardingRuleConfiguration createCurrentRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
ShardingTableRuleConfiguration tableRuleConfiguration = new
ShardingTableRuleConfiguration("t_order");
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/BaseRule.g4
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/BaseRule.g4
index aaef281..e3abe78 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/BaseRule.g4
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/BaseRule.g4
@@ -30,3 +30,7 @@ algorithmName
keyGeneratorName
: IDENTIFIER
;
+
+existsClause
+ : IF EXISTS
+ ;
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 4fa0209..daffc1c 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
@@ -198,3 +198,11 @@ UNUSED
USED
: U S E D
;
+
+IF
+ : I F
+ ;
+
+EXISTS
+ : E X I S T S
+ ;
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 3512aa2..a5e63f8 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
@@ -84,7 +84,7 @@ dropShardingBroadcastTableRules
;
dropShardingAlgorithm
- : DROP SHARDING ALGORITHM algorithmName (COMMA algorithmName)*
+ : DROP SHARDING ALGORITHM existsClause? algorithmName (COMMA
algorithmName)*
;
dropShardingKeyGenerator
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
index c44a287..595595b 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
@@ -272,13 +272,15 @@ public final class ShardingDistSQLStatementVisitor
extends ShardingDistSQLStatem
@Override
public ASTNode visitDropShardingBroadcastTableRules(final
DropShardingBroadcastTableRulesContext ctx) {
Collection<String> tableNames = null == ctx.tableName() ?
Collections.emptyList()
- : ctx.tableName().stream().map(each ->
getIdentifierValue(each)).collect(Collectors.toCollection(LinkedList::new));
+ :
ctx.tableName().stream().map(this::getIdentifierValue).collect(Collectors.toCollection(LinkedList::new));
return new DropShardingBroadcastTableRulesStatement(tableNames);
}
@Override
public ASTNode visitDropShardingAlgorithm(final
DropShardingAlgorithmContext ctx) {
- return new
DropShardingAlgorithmStatement(ctx.algorithmName().stream().map(each ->
getIdentifierValue(each)).collect(Collectors.toList()));
+ DropShardingAlgorithmStatement result = new
DropShardingAlgorithmStatement(ctx.algorithmName().stream().map(this::getIdentifierValue).collect(Collectors.toList()));
+ result.setContainsExistClause(null != ctx.existsClause());
+ return result;
}
@Override
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/drop/DropRuleStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/drop/DropRuleStatementAssert.java
index de2303e..66847a5 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/drop/DropRuleStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/drop/DropRuleStatementAssert.java
@@ -29,6 +29,7 @@ import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.Dro
import
org.apache.shardingsphere.scaling.distsql.statement.DropShardingScalingRuleStatement;
import
org.apache.shardingsphere.shadow.distsql.parser.statement.DropShadowRuleStatement;
import
org.apache.shardingsphere.sharding.distsql.parser.statement.DropDefaultShardingStrategyStatement;
+import
org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingAlgorithmStatement;
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;
@@ -41,6 +42,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.drop.impl.DropEncryptRuleStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.drop.impl.DropReadwriteSplittingRuleStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.drop.impl.DropShadowRuleStatementAssert;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.drop.impl.DropShardingAlgorithmStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.drop.impl.DropShardingBindingTableRulesStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.drop.impl.DropShardingBroadcastTableRulesStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.drop.impl.DropShardingScalingRuleStatementAssert;
@@ -54,6 +56,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropEncryptRuleStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropReadwriteSplittingRuleStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShadowRuleStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShardingAlgorithmStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShardingBindingTableRulesStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShardingBroadcastTableRulesStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShardingScalingRuleStatementTestCase;
@@ -97,6 +100,8 @@ public final class DropRuleStatementAssert {
DropDefaultSingleTableRuleAssert.assertIs(assertContext,
(DropDefaultSingleTableRuleStatement) actual,
(DropDefaultSingleTableRuleStatementTestCase) expected);
} else if (actual instanceof DropShardingScalingRuleStatement) {
DropShardingScalingRuleStatementAssert.assertIs(assertContext,
(DropShardingScalingRuleStatement) actual,
(DropShardingScalingRuleStatementTestCase) expected);
+ } else if (actual instanceof DropShardingAlgorithmStatement) {
+ DropShardingAlgorithmStatementAssert.assertIs(assertContext,
(DropShardingAlgorithmStatement) actual,
(DropShardingAlgorithmStatementTestCase) expected);
}
}
}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/drop/impl/DropShardingAlgorithmStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/drop/impl/DropShardingAlgorithmStatementAssert.java
new file mode 100644
index 0000000..c2f2165
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/drop/impl/DropShardingAlgorithmStatementAssert.java
@@ -0,0 +1,51 @@
+/*
+ * 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.test.sql.parser.parameterized.asserts.statement.distsql.rdl.drop.impl;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingAlgorithmStatement;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShardingAlgorithmStatementTestCase;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Drop sharding algorithm statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DropShardingAlgorithmStatementAssert {
+
+ /**
+ * Assert drop sharding algorithm statement is correct with expected
parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual drop sharding algorithm statement
+ * @param expected expected drop sharding algorithm statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext,
final DropShardingAlgorithmStatement actual, final
DropShardingAlgorithmStatementTestCase expected) {
+ if (null == expected.getAlgorithms()) {
+ assertNull(assertContext.getText("Actual algorithm should not
exist."), actual);
+ } else {
+ assertThat(assertContext.getText("Algorithm names assertion error:
"), actual.getAlgorithmNames(), is(expected.getAlgorithms()));
+ assertThat(assertContext.getText("Contains exist clause assertion
error: "), actual.isContainsExistClause(),
is(expected.isContainsExistsClause()));
+ }
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
index fca255b..31869ba 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
@@ -252,6 +252,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropResourceStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShadowAlgorithmStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShadowRuleStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShardingAlgorithmStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShardingBindingTableRulesStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShardingBroadcastTableRulesStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShardingKeyGeneratorStatementTestCase;
@@ -1144,6 +1145,9 @@ public final class SQLParserTestCases {
@XmlElement(name = "set-user")
private final List<SetUserStatementTestCase> setUserStatementTestCases =
new LinkedList<>();
+ @XmlElement(name = "drop-sharding-algorithm")
+ private final List<DropShardingAlgorithmStatementTestCase>
dropShardingAlgorithmStatementTestCases = new LinkedList<>();
+
/**
* Get all SQL parser test cases.
*
@@ -1429,6 +1433,7 @@ public final class SQLParserTestCases {
putAll(showShardingTableRulesUsedAlgorithmStatementTestCases, result);
putAll(showShardingTableRulesUsedKeyGeneratorStatementTestCases,
result);
putAll(setUserStatementTestCases, result);
+ putAll(dropShardingAlgorithmStatementTestCases, result);
return result;
}
// CHECKSTYLE:ON
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/BaseRule.g4
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/drop/DropShardingAlgorithmStatementTestCase.java
similarity index 51%
copy from
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/BaseRule.g4
copy to
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/drop/DropShardingAlgorithmStatementTestCase.java
index aaef281..531390e 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/BaseRule.g4
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/drop/DropShardingAlgorithmStatementTestCase.java
@@ -14,19 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-grammar BaseRule;
-import Symbol, Keyword, Literals;
+package
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop;
-tableName
- : IDENTIFIER
- ;
+import lombok.Getter;
+import lombok.Setter;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
-algorithmName
- : IDENTIFIER
- ;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import java.util.LinkedList;
+import java.util.List;
-keyGeneratorName
- : IDENTIFIER
- ;
+/**
+ * Drop sharding algorithm statement test case.
+ */
+@Setter
+@Getter
+public final class DropShardingAlgorithmStatementTestCase extends
SQLParserTestCase {
+
+ @XmlAttribute(name = "contains-exists-clause")
+ private boolean containsExistsClause;
+
+ @XmlElement(name = "algorithm")
+ private final List<String> algorithms = new LinkedList<>();
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/drop.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/drop.xml
index 26d09c2..ff68dee 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/drop.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/drop.xml
@@ -103,4 +103,8 @@
<drop-default-sharding-strategy
sql-case-id="drop-default-sharding-strategy" type="table"/>
<drop-sharding-scaling-rule sql-case-id="drop-sharding-scaling-rule"
scaling-name="default_scaling"/>
+
+ <drop-sharding-algorithm sql-case-id="drop-sharding-algorithm"
contains-exists-clause="true">
+ <algorithm>t_order_hash_mod</algorithm>
+ </drop-sharding-algorithm>
</sql-parser-test-cases>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/drop.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/drop.xml
index 480a7a1..4c92b2c 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/drop.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/drop.xml
@@ -38,4 +38,5 @@
<distsql-case id="drop-sharding-key-generator" value="DROP SHARDING KEY
GENERATOR uuid_key_generator" />
<distsql-case id="drop-default-sharding-strategy" value="DROP DEFAULT
SHARDING TABLE STRATEGY" />
<distsql-case id="drop-sharding-scaling-rule" value="DROP SHARDING SCALING
RULE default_scaling" />
+ <distsql-case id="drop-sharding-algorithm" value="DROP SHARDING ALGORITHM
IF EXISTS t_order_hash_mod" />
</sql-cases>