You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/06/17 09:39:10 UTC

[GitHub] [shardingsphere] tuichenchuxin commented on a diff in pull request #18372: add actualDataNodes for auto tables.

tuichenchuxin commented on code in PR #18372:
URL: https://github.com/apache/shardingsphere/pull/18372#discussion_r899953266


##########
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java:
##########
@@ -153,24 +152,15 @@ private DataNodeInfo createTableDataNode(final Collection<DataNode> actualDataNo
     }
     
     private List<String> getDataNodes(final ShardingAutoTableRuleConfiguration tableRuleConfig, final ShardingAutoTableAlgorithm shardingAlgorithm, final Collection<String> dataSourceNames) {
+        if (null != tableRuleConfig.getActualDataNodes() && !tableRuleConfig.getActualDataNodes().isEmpty()) {
+            return new InlineExpressionParser(tableRuleConfig.getActualDataNodes()).splitAndEvaluate();
+        }
         if (null == tableShardingStrategyConfig) {
             return new LinkedList<>();
         }
         List<String> dataSources = Strings.isNullOrEmpty(tableRuleConfig.getActualDataSources()) ? new LinkedList<>(dataSourceNames)
                 : new InlineExpressionParser(tableRuleConfig.getActualDataSources()).splitAndEvaluate();
-        return fillDataSourceNames(shardingAlgorithm.getAutoTablesAmount(), dataSources);
-    }
-    
-    private List<String> fillDataSourceNames(final int amount, final List<String> dataSources) {
-        List<String> result = new LinkedList<>();
-        Iterator<String> iterator = dataSources.iterator();
-        for (int i = 0; i < amount; i++) {
-            if (!iterator.hasNext()) {
-                iterator = dataSources.iterator();
-            }
-            result.add(String.format("%s.%s_%s", iterator.next(), logicTable, i));
-        }
-        return result;
+        return DataNodeUtil.getFormatDataNodeList(shardingAlgorithm.getAutoTablesAmount(), logicTable, dataSources);

Review Comment:
   OK, Thank you. Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org