This is an automated email from the ASF dual-hosted git repository. jiangmaolin 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 68a202767ec Fix duplicate result when show rules used storage unit with readwrite-splitting rule (#35129) 68a202767ec is described below commit 68a202767eca26668fd21e4e6aa852dc71bc71f3 Author: Raigor <raigor.ji...@gmail.com> AuthorDate: Fri Apr 4 23:12:09 2025 +0800 Fix duplicate result when show rules used storage unit with readwrite-splitting rule (#35129) * Fix duplicate result when show rules used storage unit with readwrite-splitting rule * Update RELEASE-NOTES.md --- RELEASE-NOTES.md | 1 + .../handler/query/InUsedReadwriteSplittingStorageUnitRetriever.java | 4 ++-- .../query/InUsedReadwriteSplittingStorageUnitRetrieverTest.java | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 2bcda0954b8..940c7f6b5dc 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -40,6 +40,7 @@ 1. SQL Parser: Fix mysql sql parser error when sql contains implicit concat expression - [#34660](https://github.com/apache/shardingsphere/pull/34660) 1. JDBC: Fix wrong jdbc database metadata pass through logic - [#34959](https://github.com/apache/shardingsphere/pull/34959) 1. JDBC: Fix getting database name from sql statement context - [#34960](https://github.com/apache/shardingsphere/pull/34960) +1. DistSQL: Fix duplicate result when show rules used storage unit with readwrite-splitting rule - [#35129](https://github.com/apache/shardingsphere/pull/35129) ### Change Logs 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 2ca1c694251..898ade8f2d5 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 @@ -25,7 +25,7 @@ import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule; import java.util.Collection; import java.util.Collections; -import java.util.LinkedList; +import java.util.HashSet; /** * In used readwrite-splitting storage unit retriever. @@ -37,7 +37,7 @@ public final class InUsedReadwriteSplittingStorageUnitRetriever implements InUse if (!sqlStatement.getStorageUnitName().isPresent()) { return Collections.emptyList(); } - Collection<String> result = new LinkedList<>(); + Collection<String> result = new HashSet<>(1, 1F); for (ReadwriteSplittingDataSourceGroupRuleConfiguration each : rule.getConfiguration().getDataSourceGroups()) { if (each.getWriteDataSourceName().equalsIgnoreCase(sqlStatement.getStorageUnitName().get())) { 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 d6fb83438da..bdad6bc2cd0 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 @@ -47,13 +47,13 @@ class InUsedReadwriteSplittingStorageUnitRetrieverTest { @Test void assertGetInUsedResourcesWithWriteDataSource() { ShowRulesUsedStorageUnitStatement sqlStatement = new ShowRulesUsedStorageUnitStatement("foo_unit_write", null); - assertThat(retriever.getInUsedResources(sqlStatement, mockRule()), is(Collections.singletonList("foo_ds"))); + assertThat(retriever.getInUsedResources(sqlStatement, mockRule()), is(Collections.singleton("foo_ds"))); } @Test void assertGetInUsedResourcesWithReadDataSource() { ShowRulesUsedStorageUnitStatement sqlStatement = new ShowRulesUsedStorageUnitStatement("foo_unit_read", null); - assertThat(retriever.getInUsedResources(sqlStatement, mockRule()), is(Collections.singletonList("foo_ds"))); + assertThat(retriever.getInUsedResources(sqlStatement, mockRule()), is(Collections.singleton("foo_ds"))); } private ReadwriteSplittingRule mockRule() {