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/26 13:32:45 UTC

[GitHub] [shardingsphere] gavenpeng commented on a diff in pull request #18611: Support force route use hint provider sharding value when sharding strategy not is hint mode

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


##########
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:
   ok,me refactor the code



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