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 6b906c48c0f DistSQL: Fix case-sensitive matching for SHOW RULES USED
STORAGE UNIT (#38848)
6b906c48c0f is described below
commit 6b906c48c0fa22ffe10d2c9074739c1f29a74241
Author: Raigor <[email protected]>
AuthorDate: Sat Jun 13 23:33:00 2026 +0800
DistSQL: Fix case-sensitive matching for SHOW RULES USED STORAGE UNIT
(#38848)
* DistSQL: Fix case-sensitive matching for SHOW RULES USED STORAGE UNIT
* Update RELEASE-NOTES.md
---
RELEASE-NOTES.md | 1 +
.../query/InUsedReadwriteSplittingStorageUnitRetriever.java | 5 ++---
.../InUsedReadwriteSplittingStorageUnitRetrieverTest.java | 6 ++++++
.../handler/query/InUsedShadowStorageUnitRetriever.java | 4 ++--
.../handler/query/InUsedShadowStorageUnitRetrieverTest.java | 10 ++++++++--
.../handler/query/InUsedShardingStorageUnitRetriever.java | 3 +--
.../handler/query/InUsedShardingStorageUnitRetrieverTest.java | 6 ++++++
.../handler/query/InUsedSingleStorageUnitRetriever.java | 2 +-
.../handler/query/InUsedSingleStorageUnitRetrieverTest.java | 6 ++++++
9 files changed, 33 insertions(+), 10 deletions(-)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index bc8136aea4e..93b5685b0df 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -27,6 +27,7 @@
1. Pipeline: Fix escape MySQL JSON binlog control characters -
[#38800](https://github.com/apache/shardingsphere/pull/38800)
1. Sharding: Support ORDER BY MySQL VARBINARY column by wrapping byte[] values
in a Comparable adapter -
[#38699](https://github.com/apache/shardingsphere/pull/38699)
1. Sharding: Fix AUTO_INTERVAL sharding failure under JVM default locales that
use comma decimal separators -
[#38806](https://github.com/apache/shardingsphere/pull/38806)
+1. DistSQL: Fix case-sensitive storage unit matching in `SHOW RULES USED
STORAGE UNIT` - [#38848](https://github.com/apache/shardingsphere/pull/38848)
### Enhancements
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/InUsedReadwriteSplittingStorageUnitRetriever.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/InUsedReadwriteSplittingStorageUnitRetriever.java
index 3d05e1bb948..17d39eaa67c 100644
---
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/InUsedReadwriteSplittingStorageUnitRetriever.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/InUsedReadwriteSplittingStorageUnitRetriever.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.readwritesplitting.distsql.handler.query;
-import com.cedarsoftware.util.CaseInsensitiveSet;
import
org.apache.shardingsphere.distsql.handler.executor.rql.resource.InUsedStorageUnitRetriever;
import
org.apache.shardingsphere.distsql.statement.type.rql.rule.database.ShowRulesUsedStorageUnitStatement;
import
org.apache.shardingsphere.readwritesplitting.config.rule.ReadwriteSplittingDataSourceGroupRuleConfiguration;
@@ -35,10 +34,10 @@ public final class
InUsedReadwriteSplittingStorageUnitRetriever implements InUse
public Collection<String> getInUsedResources(final
ShowRulesUsedStorageUnitStatement sqlStatement, final ReadwriteSplittingRule
rule) {
Collection<String> result = new HashSet<>(1, 1F);
for (ReadwriteSplittingDataSourceGroupRuleConfiguration each :
rule.getConfiguration().getDataSourceGroups()) {
- if
(each.getWriteDataSourceName().equalsIgnoreCase(sqlStatement.getStorageUnitName()))
{
+ if
(sqlStatement.getStorageUnitName().equals(each.getWriteDataSourceName())) {
result.add(each.getName());
}
- if (new
CaseInsensitiveSet<>(each.getReadDataSourceNames()).contains(sqlStatement.getStorageUnitName()))
{
+ if
(each.getReadDataSourceNames().contains(sqlStatement.getStorageUnitName())) {
result.add(each.getName());
}
}
diff --git
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/InUsedReadwriteSplittingStorageUnitRetrieverTest.java
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/InUsedReadwriteSplittingStorageUnitRetrieverTest.java
index 426985f25d6..bc01dbd2876 100644
---
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/InUsedReadwriteSplittingStorageUnitRetrieverTest.java
+++
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/InUsedReadwriteSplittingStorageUnitRetrieverTest.java
@@ -49,6 +49,12 @@ class InUsedReadwriteSplittingStorageUnitRetrieverTest {
assertThat(retriever.getInUsedResources(sqlStatement, mockRule()),
is(Collections.singleton("foo_ds")));
}
+ @Test
+ void assertGetInUsedResourcesWithDifferentCaseDataSource() {
+ ShowRulesUsedStorageUnitStatement sqlStatement = new
ShowRulesUsedStorageUnitStatement("FOO_UNIT_READ", null);
+ assertThat(retriever.getInUsedResources(sqlStatement, mockRule()),
is(Collections.emptySet()));
+ }
+
private ReadwriteSplittingRule mockRule() {
ReadwriteSplittingRule result = mock(ReadwriteSplittingRule.class,
RETURNS_DEEP_STUBS);
ReadwriteSplittingDataSourceGroupRuleConfiguration
dataSourceGroupRuleConfig = new
ReadwriteSplittingDataSourceGroupRuleConfiguration(
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/InUsedShadowStorageUnitRetriever.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/InUsedShadowStorageUnitRetriever.java
index c13a8116092..d88b56e72cd 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/InUsedShadowStorageUnitRetriever.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/InUsedShadowStorageUnitRetriever.java
@@ -33,8 +33,8 @@ public final class InUsedShadowStorageUnitRetriever
implements InUsedStorageUnit
@Override
public Collection<String> getInUsedResources(final
ShowRulesUsedStorageUnitStatement sqlStatement, final ShadowRule rule) {
return rule.getConfiguration().getDataSources().stream()
- .filter(each ->
each.getShadowDataSourceName().equalsIgnoreCase(sqlStatement.getStorageUnitName())
- ||
each.getProductionDataSourceName().equalsIgnoreCase(sqlStatement.getStorageUnitName()))
+ .filter(each ->
each.getShadowDataSourceName().equals(sqlStatement.getStorageUnitName())
+ ||
each.getProductionDataSourceName().equals(sqlStatement.getStorageUnitName()))
.map(ShadowDataSourceConfiguration::getName).collect(Collectors.toList());
}
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/InUsedShadowStorageUnitRetrieverTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/InUsedShadowStorageUnitRetrieverTest.java
index 7b67e67375c..c1bfab5a396 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/InUsedShadowStorageUnitRetrieverTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/InUsedShadowStorageUnitRetrieverTest.java
@@ -38,17 +38,23 @@ class InUsedShadowStorageUnitRetrieverTest {
private final InUsedStorageUnitRetriever<ShadowRule> retriever =
TypedSPILoader.getService(InUsedStorageUnitRetriever.class, ShadowRule.class);
@Test
- void assertGetInUsedResourcesWithShadowDataSource() {
+ void assertGetInUsedResourcesWithProductionDataSource() {
ShowRulesUsedStorageUnitStatement sqlStatement = new
ShowRulesUsedStorageUnitStatement("prod_ds", null);
assertThat(retriever.getInUsedResources(sqlStatement, mockRule()),
is(Collections.singletonList("foo_ds")));
}
@Test
- void assertGetInUsedResourcesWithProductionDataSource() {
+ void assertGetInUsedResourcesWithShadowDataSource() {
ShowRulesUsedStorageUnitStatement sqlStatement = new
ShowRulesUsedStorageUnitStatement("shadow_ds", null);
assertThat(retriever.getInUsedResources(sqlStatement, mockRule()),
is(Collections.singletonList("foo_ds")));
}
+ @Test
+ void assertGetInUsedResourcesWithDifferentCaseDataSource() {
+ ShowRulesUsedStorageUnitStatement sqlStatement = new
ShowRulesUsedStorageUnitStatement("PROD_DS", null);
+ assertThat(retriever.getInUsedResources(sqlStatement, mockRule()),
is(Collections.emptyList()));
+ }
+
private ShadowRule mockRule() {
ShadowRule result = mock(ShadowRule.class, RETURNS_DEEP_STUBS);
ShadowDataSourceConfiguration dataSourceConfig = new
ShadowDataSourceConfiguration("foo_ds", "prod_ds", "shadow_ds");
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/InUsedShardingStorageUnitRetriever.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/InUsedShardingStorageUnitRetriever.java
index 77ef79076a9..e879d813f3a 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/InUsedShardingStorageUnitRetriever.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/InUsedShardingStorageUnitRetriever.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
-import com.cedarsoftware.util.CaseInsensitiveSet;
import
org.apache.shardingsphere.distsql.handler.executor.rql.resource.InUsedStorageUnitRetriever;
import
org.apache.shardingsphere.distsql.statement.type.rql.rule.database.ShowRulesUsedStorageUnitStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -35,7 +34,7 @@ public final class InUsedShardingStorageUnitRetriever
implements InUsedStorageUn
public Collection<String> getInUsedResources(final
ShowRulesUsedStorageUnitStatement sqlStatement, final ShardingRule rule) {
Collection<String> result = new
HashSet<>(rule.getShardingTables().size(), 1F);
for (ShardingTable each : rule.getShardingTables().values()) {
- if (new
CaseInsensitiveSet<>(each.getActualDataSourceNames()).contains(sqlStatement.getStorageUnitName()))
{
+ if
(each.getActualDataSourceNames().contains(sqlStatement.getStorageUnitName())) {
result.add(each.getLogicTable());
}
}
diff --git
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/InUsedShardingStorageUnitRetrieverTest.java
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/InUsedShardingStorageUnitRetrieverTest.java
index 7e98ff7b7ab..a05e067941c 100644
---
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/InUsedShardingStorageUnitRetrieverTest.java
+++
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/InUsedShardingStorageUnitRetrieverTest.java
@@ -43,6 +43,12 @@ class InUsedShardingStorageUnitRetrieverTest {
assertThat(retriever.getInUsedResources(sqlStatement, mockRule()),
is(Collections.singleton("foo_tbl")));
}
+ @Test
+ void assertGetInUsedResourcesWithDifferentCaseStorageUnit() {
+ ShowRulesUsedStorageUnitStatement sqlStatement = new
ShowRulesUsedStorageUnitStatement("FOO_DS", null);
+ assertThat(retriever.getInUsedResources(sqlStatement, mockRule()),
is(Collections.emptySet()));
+ }
+
private ShardingRule mockRule() {
ShardingRule result = mock(ShardingRule.class);
ShardingTable fooTbl = mock(ShardingTable.class);
diff --git
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/InUsedSingleStorageUnitRetriever.java
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/InUsedSingleStorageUnitRetriever.java
index becb6b1b9e8..609d7efecd1 100644
---
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/InUsedSingleStorageUnitRetriever.java
+++
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/InUsedSingleStorageUnitRetriever.java
@@ -39,7 +39,7 @@ public final class InUsedSingleStorageUnitRetriever
implements InUsedStorageUnit
Collection<String> result = new HashSet<>(dataNodes.size(), 1F);
for (Collection<DataNode> each : dataNodes.values()) {
String storageUnitName =
each.iterator().next().getDataSourceName();
- if
(storageUnitName.equalsIgnoreCase(sqlStatement.getStorageUnitName())) {
+ if (sqlStatement.getStorageUnitName().equals(storageUnitName)) {
result.add(each.iterator().next().getTableName());
}
}
diff --git
a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/InUsedSingleStorageUnitRetrieverTest.java
b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/InUsedSingleStorageUnitRetrieverTest.java
index 3117fbea29f..8f07f74dbbd 100644
---
a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/InUsedSingleStorageUnitRetrieverTest.java
+++
b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/InUsedSingleStorageUnitRetrieverTest.java
@@ -44,6 +44,12 @@ class InUsedSingleStorageUnitRetrieverTest {
assertThat(retriever.getInUsedResources(sqlStatement, mockRule()),
is(Collections.singleton("foo_table")));
}
+ @Test
+ void assertGetInUsedResourcesWithDifferentCaseStorageUnit() {
+ ShowRulesUsedStorageUnitStatement sqlStatement = new
ShowRulesUsedStorageUnitStatement("FOO_DS", null);
+ assertThat(retriever.getInUsedResources(sqlStatement, mockRule()),
is(Collections.emptySet()));
+ }
+
private SingleRule mockRule() {
SingleRule result = mock(SingleRule.class);
SingleDataNodeRuleAttribute attribute =
mock(SingleDataNodeRuleAttribute.class);