gavenpeng commented on code in PR #18611:
URL: https://github.com/apache/shardingsphere/pull/18611#discussion_r908026575


##########
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRoutingEngine.java:
##########
@@ -214,10 +236,21 @@ private Collection<String> routeDataSources(final 
TableRule tableRule, final Sha
     
     private Collection<DataNode> routeTables(final TableRule tableRule, final 
String routedDataSource,
                                              final ShardingStrategy 
tableShardingStrategy, final List<ShardingConditionValue> tableShardingValues) {
-        Collection<String> availableTargetTables = 
tableRule.getActualTableNames(routedDataSource);
-        Collection<String> routedTables = tableShardingValues.isEmpty()
-                ? availableTargetTables
-                : tableShardingStrategy.doSharding(availableTargetTables, 
tableShardingValues, tableRule.getTableDataNode(), properties);
+        Collection<String> routedTables = null;
+        if (!(tableShardingStrategy instanceof HintShardingStrategy) && 
!tableShardingValues.isEmpty()) {
+            ShardingConditionValue shardingConditionValue = 
tableShardingValues.iterator().next();
+            List<ShardingConditionValue> tableHintShardingValues = 
getTableShardingValuesFromHint(shardingConditionValue);
+            if (!tableHintShardingValues.isEmpty()) {
+                Collection<String> availableTargetTables = 
tableRule.getActualTableNames(routedDataSource);
+                routedTables = new 
LinkedHashSet<>(tableShardingStrategy.doSharding(availableTargetTables, 
tableHintShardingValues, tableRule.getTableDataNode(), properties));
+            }
+        }
+        if (routedTables == null || routedTables.isEmpty()) {
+            Collection<String> availableTargetTables = 
tableRule.getActualTableNames(routedDataSource);
+            routedTables = new LinkedHashSet<>(tableShardingValues.isEmpty()
+                    ? availableTargetTables
+                    : tableShardingStrategy.doSharding(availableTargetTables, 
tableShardingValues, tableRule.getTableDataNode(), properties));
+        }

Review Comment:
   I refactor the logic,moved to create the sharding condition address,this 
look more concise



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