You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/09/30 10:39:38 UTC
[shardingsphere] branch master updated: optimize aggregation logic
in single table rule (#12857)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 2e621d7 optimize aggregation logic in single table rule (#12857)
2e621d7 is described below
commit 2e621d72d5adc154d8fe58a996022bb17ad5d244
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Thu Sep 30 18:39:06 2021 +0800
optimize aggregation logic in single table rule (#12857)
---
.../java/org/apache/shardingsphere/shadow/rule/ShadowRule.java | 4 ++--
.../apache/shardingsphere/singletable/rule/SingleTableRule.java | 7 +++----
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
index 7aaf3bb..36c40b1 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
@@ -31,8 +31,8 @@ import org.apache.shardingsphere.shadow.rule.checker.ShadowRuleChecker;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
@@ -209,7 +209,7 @@ public final class ShadowRule implements SchemaRule, DataSourceContainedRule {
public Map<String, Collection<String>> getDataSourceMapper() {
Map<String, Collection<String>> result = new HashMap<>(shadowMappings.size(), 1);
for (Entry<String, String> entry : shadowMappings.entrySet()) {
- result.put(entry.getKey(), Collections.singletonList(entry.getValue()));
+ result.put(entry.getKey(), Arrays.asList(entry.getKey(), entry.getValue()));
}
return result;
}
diff --git a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
index 62192e1..f31e231 100644
--- a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
+++ b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
@@ -71,7 +71,7 @@ public final class SingleTableRule implements SchemaRule, DataNodeContainedRule,
for (Entry<String, Collection<String>> entry : builtRules.getDataSourceMapper().entrySet()) {
for (String each : entry.getValue()) {
if (dataSourceMap.containsKey(each)) {
- result.put(entry.getKey(), dataSourceMap.remove(each));
+ result.putIfAbsent(entry.getKey(), dataSourceMap.remove(each));
}
}
}
@@ -118,9 +118,8 @@ public final class SingleTableRule implements SchemaRule, DataNodeContainedRule,
@Override
public Map<String, Collection<DataNode>> getAllDataNodes() {
- Map<String, Collection<DataNode>> result = new LinkedHashMap<>();
- singleTableDataNodes.forEach((key, value) -> result.put(key, Collections.singleton(new DataNode(value.getDataSourceName(), value.getTableName()))));
- return result;
+ return singleTableDataNodes.values().stream().map(each -> new DataNode(each.getDataSourceName(), each.getTableName()))
+ .collect(Collectors.groupingBy(DataNode::getTableName, LinkedHashMap::new, Collectors.toCollection(LinkedList::new)));
}
@Override