You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/01/05 17:05:39 UTC
[shardingsphere] branch master updated: Add `ifExist` for `drop mask rule` (#23361)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 d4d029b72e0 Add `ifExist` for `drop mask rule` (#23361)
d4d029b72e0 is described below
commit d4d029b72e0c13aa58039d18aa7d1862b65d6fae
Author: Zichao <57...@users.noreply.github.com>
AuthorDate: Fri Jan 6 06:05:22 2023 +1300
Add `ifExist` for `drop mask rule` (#23361)
---
.../handler/update/DropMaskRuleStatementUpdater.java | 3 +++
.../handler/update/DropMaskRuleStatementUpdaterTest.java | 13 +++++++++++++
2 files changed, 16 insertions(+)
diff --git a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleStatementUpdater.java b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleStatementUpdater.java
index 1d7c3a37127..726b1e96fae 100644
--- a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleStatementUpdater.java
+++ b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleStatementUpdater.java
@@ -41,6 +41,9 @@ public final class DropMaskRuleStatementUpdater implements RuleDefinitionDropUpd
}
private void checkToBeDroppedMaskTableNames(final String databaseName, final DropMaskRuleStatement sqlStatement, final MaskRuleConfiguration currentRuleConfig) {
+ if (sqlStatement.isIfExists()) {
+ return;
+ }
ShardingSpherePreconditions.checkState(isExistRuleConfig(currentRuleConfig), () -> new MissingRequiredRuleException("Mask", databaseName));
Collection<String> currentMaskTableNames = currentRuleConfig.getTables().stream().map(MaskTableRuleConfiguration::getName).collect(Collectors.toList());
Collection<String> notExistedTableNames = sqlStatement.getTables().stream().filter(each -> !currentMaskTableNames.contains(each)).collect(Collectors.toList());
diff --git a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleStatementUpdaterTest.java b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleStatementUpdaterTest.java
index 88521fa0ffc..cda9fcb1cbf 100644
--- a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleStatementUpdaterTest.java
+++ b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleStatementUpdaterTest.java
@@ -33,7 +33,11 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
@RunWith(MockitoJUnitRunner.class)
public final class DropMaskRuleStatementUpdaterTest {
@@ -61,6 +65,15 @@ public final class DropMaskRuleStatementUpdaterTest {
assertTrue(ruleConfig.getTables().isEmpty());
}
+ @Test
+ public void assertUpdateCurrentRuleConfigurationWithIfExists() {
+ MaskRuleConfiguration ruleConfig = createCurrentRuleConfiguration();
+ DropMaskRuleStatement statement = createSQLStatement(true, "t_user");
+ updater.checkSQLStatement(database, statement, mock(MaskRuleConfiguration.class));
+ assertFalse(updater.updateCurrentRuleConfiguration(statement, ruleConfig));
+ assertThat(ruleConfig.getTables().size(), is(1));
+ }
+
private DropMaskRuleStatement createSQLStatement(final boolean ifExists, final String tableName) {
return new DropMaskRuleStatement(ifExists, Collections.singleton(tableName));
}