RaigorJiang commented on a change in pull request #16172:
URL: https://github.com/apache/shardingsphere/pull/16172#discussion_r829718509



##########
File path: 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBindingTableRulesStatementUpdater.java
##########
@@ -77,6 +88,73 @@ private void checkToBeAlteredDuplicateBindingTables(final 
String schemaName, fin
         }
     }
     
+    private void checkToBeAlteredCanBindBindingTables(final 
AlterShardingBindingTableRulesStatement sqlStatement, final 
ShardingRuleConfiguration currentRuleConfig) throws DistSQLException {
+        Collection<String> cannotBindRules = 
sqlStatement.getRules().stream().map(BindingTableRuleSegment::getTableGroups)
+                .filter(each -> !canBind(currentRuleConfig, 
each)).collect(Collectors.toCollection(LinkedList::new));
+        DistSQLException.predictionThrow(cannotBindRules.isEmpty(),
+            () -> new InvalidRuleConfigurationException("binding", 
cannotBindRules, Collections.singleton("Unable to bind with different sharding 
strategies")));
+    }
+    
+    private boolean canBind(final ShardingRuleConfiguration currentRuleConfig, 
final String bindingRule) {
+        LinkedList<String> shardingTables = new 
LinkedList<>(Splitter.on(",").trimResults().splitToList(bindingRule));
+        Collection<String> bindableShardingTables = 
getBindableShardingTable(currentRuleConfig, shardingTables.getFirst());
+        return bindableShardingTables.containsAll(shardingTables);
+    }
+    
+    private Collection<String> getBindableShardingTable(final 
ShardingRuleConfiguration currentRuleConfig, final String shardingTable) {

Review comment:
       `getBindableShardingTables` is better, because the result is a 
collection.




-- 
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