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 11:13:16 UTC

[GitHub] [shardingsphere] terrymanu commented on a diff in pull request #18606: Support force route use hint provider sharding value

terrymanu commented on code in PR #18606:
URL: https://github.com/apache/shardingsphere/pull/18606#discussion_r906797347


##########
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRoutingEngine.java:
##########
@@ -214,10 +238,23 @@ 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)) {
+            if (!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:
   There are too many nested if, could you refactor them?



##########
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRoutingEngine.java:
##########
@@ -202,10 +214,22 @@ private Collection<DataNode> route0(final TableRule tableRule,
     }
     
     private Collection<String> routeDataSources(final TableRule tableRule, final ShardingStrategy databaseShardingStrategy, final List<ShardingConditionValue> databaseShardingValues) {
-        if (databaseShardingValues.isEmpty()) {
-            return tableRule.getActualDatasourceNames();
+        Collection<String> result = null;
+        if (!(databaseShardingStrategy instanceof HintShardingStrategy)) {
+            if (!databaseShardingValues.isEmpty()) {
+                ShardingConditionValue shardingConditionValue = databaseShardingValues.iterator().next();
+                List<ShardingConditionValue> databaseHintShardingValues = getDatabaseShardingValuesFromHint(shardingConditionValue);
+                if (!databaseHintShardingValues.isEmpty()) {
+                    result = databaseShardingStrategy.doSharding(tableRule.getActualDatasourceNames(), databaseHintShardingValues, tableRule.getDataSourceDataNode(), properties);
+                }
+            }
+        }
+        if (result == null) {
+            if (databaseShardingValues.isEmpty()) {
+                return tableRule.getActualDatasourceNames();
+            }

Review Comment:
   There are too many nested if, could you refactor them?



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