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 2026/05/22 15:46:57 UTC

(shardingsphere) branch master updated: preserve the case of the rule name when drop encrypt rule (#38713)

This is an automated email from the ASF dual-hosted git repository.

RaigorJiang 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 9ad3d5e7203 preserve the case of the rule name when drop encrypt rule (#38713)
9ad3d5e7203 is described below

commit 9ad3d5e720308cb05a9df919d405e0424384fb65
Author: jiangML <10...@qq.com>
AuthorDate: Fri May 22 23:46:49 2026 +0800

    preserve the case of the rule name when drop encrypt rule (#38713)
---
 .../handler/update/DropEncryptRuleExecutor.java       |  7 +++++--
 .../handler/update/DropEncryptRuleExecutorTest.java   | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java
index 9c88f5b050f..ab2a796b3a3 100644
--- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java
+++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java
@@ -70,8 +70,11 @@ public final class DropEncryptRuleExecutor implements DatabaseRuleDropExecutor<D
         Collection<EncryptTableRuleConfiguration> toBeDroppedTables = new LinkedList<>();
         Map<String, AlgorithmConfiguration> toBeDroppedEncryptors = new HashMap<>(sqlStatement.getTables().size(), 1F);
         for (String each : sqlStatement.getTables()) {
-            toBeDroppedTables.add(new EncryptTableRuleConfiguration(each, Collections.emptyList()));
-            dropRule(each);
+            Optional<EncryptTableRuleConfiguration> tableRuleConfig = rule.getConfiguration().getTables().stream().filter(optional -> optional.getName().equalsIgnoreCase(each)).findFirst();
+            if (tableRuleConfig.isPresent()) {
+                toBeDroppedTables.add(new EncryptTableRuleConfiguration(tableRuleConfig.get().getName(), Collections.emptyList()));
+                dropRule(tableRuleConfig.get().getName());
+            }
         }
         UnusedAlgorithmFinder.findUnusedEncryptor(rule.getConfiguration()).forEach(each -> toBeDroppedEncryptors.put(each, rule.getConfiguration().getEncryptors().get(each)));
         return new EncryptRuleConfiguration(toBeDroppedTables, toBeDroppedEncryptors);
diff --git a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutorTest.java b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutorTest.java
index f12de877234..e8796f7fdc9 100644
--- a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutorTest.java
+++ b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutorTest.java
@@ -74,6 +74,18 @@ class DropEncryptRuleExecutorTest {
         metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfiguration));
     }
     
+    @Test
+    void assertBuildToBeDroppedRuleConfigurationUsesOriginalCaseTableName() {
+        EncryptRuleConfiguration ruleConfig = createCurrentRuleConfigurationWithCaseSensitiveTableName();
+        EncryptRule rule = mock(EncryptRule.class);
+        when(rule.getConfiguration()).thenReturn(ruleConfig);
+        DropEncryptRuleExecutor executor = new DropEncryptRuleExecutor();
+        executor.setRule(rule);
+        EncryptRuleConfiguration actual = executor.buildToBeDroppedRuleConfiguration(createSQLStatement("T_ENCRYPT"));
+        assertThat(actual.getTables().size(), is(1));
+        assertThat(actual.getTables().iterator().next().getName(), is("t_Encrypt"));
+    }
+    
     private boolean assertRuleConfiguration(final EncryptRuleConfiguration actual) {
         assertThat(actual.getTables().size(), is(1));
         assertThat(actual.getEncryptors().size(), is(3));
@@ -138,6 +150,13 @@ class DropEncryptRuleExecutorTest {
                 new EncryptTableRuleConfiguration("t_encrypt_another", Collections.singleton(columnRuleConfig)))), encryptors);
     }
     
+    private EncryptRuleConfiguration createCurrentRuleConfigurationWithCaseSensitiveTableName() {
+        EncryptColumnRuleConfiguration columnRuleConfig = new EncryptColumnRuleConfiguration("user_id", new EncryptColumnItemRuleConfiguration("user_cipher", "t_encrypt_user_id_MD5"));
+        EncryptTableRuleConfiguration tableRuleConfig = new EncryptTableRuleConfiguration("t_Encrypt", Collections.singleton(columnRuleConfig));
+        Map<String, AlgorithmConfiguration> encryptors = Collections.singletonMap("t_encrypt_user_id_MD5", new AlgorithmConfiguration("TEST", new Properties()));
+        return new EncryptRuleConfiguration(new LinkedList<>(Collections.singleton(tableRuleConfig)), encryptors);
+    }
+    
     private ContextManager mockContextManager(final EncryptRule rule) {
         ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
         ShardingSphereDatabase database =