Skip to content

Commit

Permalink
optimize aggregation logic in single table rule (apache#12857)
Browse files Browse the repository at this point in the history
  • Loading branch information
strongduanmu authored Sep 30, 2021
1 parent e5e397f commit 2e621d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
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;
Expand Down Expand Up @@ -209,7 +209,7 @@ public Map<String, String> getAllShadowDataSourceMappings() {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private Map<String, DataSource> getAggregateDataSourceMap(final Map<String, Data
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));
}
}
}
Expand Down Expand Up @@ -118,9 +118,8 @@ private Collection<String> getExcludedTables(final Collection<ShardingSphereRule

@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
Expand Down

0 comments on commit 2e621d7

Please sign in to comment.