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


##########
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRoutingEngine.java:
##########
@@ -202,10 +214,20 @@ 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) && 
!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();
+            }
+            result = 
databaseShardingStrategy.doSharding(tableRule.getActualDatasourceNames(), 
databaseShardingValues, tableRule.getDataSourceDataNode(), 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:
##########
@@ -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:
   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: [email protected]

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

Reply via email to