strongduanmu commented on a change in pull request #14864:
URL: https://github.com/apache/shardingsphere/pull/14864#discussion_r795112948



##########
File path: 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
##########
@@ -203,6 +212,60 @@ private BindingTableRule createBindingTableRule(final 
String bindingTableGroup)
         result.getTableRules().putAll(tableRules);
         return result;
     }
+
+    private void checkTheSameActualDataSourceNamesAndActualTableIndex(final 
Collection<String> bindingTableGroups, final 
Collection<ShardingTableRuleConfiguration> tables) {
+        if (null == bindingTableGroups || bindingTableGroups.size() <= 0) {

Review comment:
       @cheese8 Do you think `bindingTableGroups.isEmpty()` is better?

##########
File path: 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
##########
@@ -203,6 +212,60 @@ private BindingTableRule createBindingTableRule(final 
String bindingTableGroup)
         result.getTableRules().putAll(tableRules);
         return result;
     }
+
+    private void checkTheSameActualDataSourceNamesAndActualTableIndex(final 
Collection<String> bindingTableGroups, final 
Collection<ShardingTableRuleConfiguration> tables) {
+        if (null == bindingTableGroups || bindingTableGroups.size() <= 0) {
+            return;
+        }
+        Iterator<String> itBindingTableGroups = bindingTableGroups.iterator();
+        Map<String, ShardingTableRuleConfiguration> 
shardingTableRuleConfigurationMap = 
tables.stream().collect(Collectors.toMap(ShardingTableRuleConfiguration::getLogicTable,
 Function.identity()));
+        while (itBindingTableGroups.hasNext()) {

Review comment:
       Can we use foreach here?

##########
File path: 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
##########
@@ -203,6 +212,60 @@ private BindingTableRule createBindingTableRule(final 
String bindingTableGroup)
         result.getTableRules().putAll(tableRules);
         return result;
     }
+
+    private void checkTheSameActualDataSourceNamesAndActualTableIndex(final 
Collection<String> bindingTableGroups, final 
Collection<ShardingTableRuleConfiguration> tables) {
+        if (null == bindingTableGroups || bindingTableGroups.size() <= 0) {
+            return;
+        }
+        Iterator<String> itBindingTableGroups = bindingTableGroups.iterator();
+        Map<String, ShardingTableRuleConfiguration> 
shardingTableRuleConfigurationMap = 
tables.stream().collect(Collectors.toMap(ShardingTableRuleConfiguration::getLogicTable,
 Function.identity()));
+        while (itBindingTableGroups.hasNext()) {
+            String bindingTableGroup = itBindingTableGroups.next();
+            List<String> bindingTableList = 
Splitter.on(",").trimResults().splitToList(bindingTableGroup);
+            List<Object> savedActualDataNodesList = null;
+            for (String bindingTable : bindingTableList) {
+                ShardingTableRuleConfiguration shardingTableRuleConfiguration 
= shardingTableRuleConfigurationMap.get(bindingTable);
+                if (null == shardingTableRuleConfiguration) {
+                    continue;
+                }
+                String actualDataNodes = 
shardingTableRuleConfiguration.getActualDataNodes();
+                if (null == actualDataNodes) {
+                    continue;
+                }
+                if (null == savedActualDataNodesList || 
savedActualDataNodesList.size() == 0) {
+                    savedActualDataNodesList = new 
InlineExpressionParser(actualDataNodes).splitAndEvaluateNotFlatten();

Review comment:
       @cheese8 Why not use bindingTableRules for judgement?

##########
File path: 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
##########
@@ -132,6 +140,7 @@ public ShardingRule(final 
AlgorithmProvidedShardingRuleConfiguration config, fin
         defaultKeyGenerateAlgorithm = null == 
config.getDefaultKeyGenerateStrategy()
                 ? 
RequiredSPIRegistry.getRegisteredService(KeyGenerateAlgorithm.class) : 
keyGenerators.get(config.getDefaultKeyGenerateStrategy().getKeyGeneratorName());
         defaultShardingColumn = config.getDefaultShardingColumn();
+        
checkTheSameActualDataSourceNamesAndActualTableIndex(config.getBindingTableGroups(),
 config.getTables());

Review comment:
       Do you think `checkSameBindingTables` is better?




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to