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:33:45 UTC
[GitHub] [shardingsphere] gavenpeng opened a new pull request, #18611: Support force route use hint provider sharding value when sharding strategy not is hint mode
gavenpeng opened a new pull request, #18611:
URL: https://github.com/apache/shardingsphere/pull/18611
Increment feature: support forced route use hint not influenced with sharding strategy
Changes proposed in this pull request:
support force routing by hint with in code mode,as long as the thread context has the force-routing flag,may be route
to config database or config table,not influenced by standard sharding strategy config.
demo:
```
public void demoFunc() {
HintManager hintManager = HintManager.getInstance();
//force route to config database
hintManager.addDatabaseShardingValue("logic_table_name", "sharding-value");
// force route to
hintManager.addTableShardingValue("logic_table_name", "sharding-value");
try {
//your code
} catch (Throwable e) {
xxxxxxx
} finally {
// this is must
hintManager.close();
}
```
--
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
[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
Posted by GitBox <gi...@apache.org>.
gavenpeng commented on code in PR #18611:
URL: https://github.com/apache/shardingsphere/pull/18611#discussion_r906839060
##########
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:
refactor after code
```
Collection<String> routedTables = null;
if (!(tableShardingStrategy instanceof HintShardingStrategy)
&& existHintTableShardingValues()
&& !tableShardingValues.isEmpty()) {
ShardingConditionValue shardingConditionValue = tableShardingValues.iterator().next();
List<ShardingConditionValue> tableHintShardingValues = getTableShardingValuesFromHint(shardingConditionValue);
Collection<String> availableTargetTables = tableRule.getActualTableNames(routedDataSource);
routedTables = new LinkedHashSet<>(tableShardingStrategy.doSharding(availableTargetTables, tableHintShardingValues, tableRule.getTableDataNode(), properties));
}
if (routedTables == null) {
Collection<String> availableTargetTables = tableRule.getActualTableNames(routedDataSource);
routedTables = new LinkedHashSet<>(tableShardingValues.isEmpty()
? availableTargetTables
: tableShardingStrategy.doSharding(availableTargetTables, tableShardingValues, tableRule.getTableDataNode(), properties));
}
```
remove nested if 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
[GitHub] [shardingsphere] terrymanu commented on pull request #18611: Support force route use hint provider sharding value when sharding strategy not is hint mode
Posted by GitBox <gi...@apache.org>.
terrymanu commented on PR #18611:
URL: https://github.com/apache/shardingsphere/pull/18611#issuecomment-1179469974
It is better to not change hint default usage, I just close the issue.
--
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
[GitHub] [shardingsphere] terrymanu closed pull request #18611: Support force route use hint provider sharding value when sharding strategy not is hint mode
Posted by GitBox <gi...@apache.org>.
terrymanu closed pull request #18611: Support force route use hint provider sharding value when sharding strategy not is hint mode
URL: https://github.com/apache/shardingsphere/pull/18611
--
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
[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
Posted by GitBox <gi...@apache.org>.
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
[GitHub] [shardingsphere] codecov-commenter commented on pull request #18611: Support force route use hint provider sharding value when sharding strategy not is hint mode
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #18611:
URL: https://github.com/apache/shardingsphere/pull/18611#issuecomment-1166513121
# [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/18611?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#18611](https://codecov.io/gh/apache/shardingsphere/pull/18611?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (94aed23) into [master](https://codecov.io/gh/apache/shardingsphere/commit/abe8c569d34f4a7cb9ddc3b9717087f1ed6e7523?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (abe8c56) will **decrease** coverage by `0.00%`.
> The diff coverage is `91.66%`.
```diff
@@ Coverage Diff @@
## master #18611 +/- ##
============================================
- Coverage 59.36% 59.36% -0.01%
Complexity 2256 2256
============================================
Files 3720 3720
Lines 54724 54742 +18
Branches 9318 9326 +8
============================================
+ Hits 32489 32498 +9
- Misses 19491 19498 +7
- Partials 2744 2746 +2
```
| [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/18611?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...e/type/standard/ShardingStandardRoutingEngine.java](https://codecov.io/gh/apache/shardingsphere/pull/18611/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvcm91dGUvZW5naW5lL3R5cGUvc3RhbmRhcmQvU2hhcmRpbmdTdGFuZGFyZFJvdXRpbmdFbmdpbmUuamF2YQ==) | `95.32% <91.66%> (-1.31%)` | :arrow_down: |
| [...d/text/distsql/ral/common/hint/HintSourceType.java](https://codecov.io/gh/apache/shardingsphere/pull/18611/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L2Rpc3RzcWwvcmFsL2NvbW1vbi9oaW50L0hpbnRTb3VyY2VUeXBlLmphdmE=) | `0.00% <0.00%> (-42.86%)` | :arrow_down: |
| [.../frontend/netty/FrontendChannelInboundHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/18611/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvZnJvbnRlbmQvbmV0dHkvRnJvbnRlbmRDaGFubmVsSW5ib3VuZEhhbmRsZXIuamF2YQ==) | `64.10% <0.00%> (-10.26%)` | :arrow_down: |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/18611?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/18611?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [abe8c56...94aed23](https://codecov.io/gh/apache/shardingsphere/pull/18611?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
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
[GitHub] [shardingsphere] terrymanu commented on a diff in pull request #18611: Support force route use hint provider sharding value when sharding strategy not is hint mode
Posted by GitBox <gi...@apache.org>.
terrymanu commented on code in PR #18611:
URL: https://github.com/apache/shardingsphere/pull/18611#discussion_r906940381
##########
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:
great
--
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
[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
Posted by GitBox <gi...@apache.org>.
gavenpeng commented on code in PR #18611:
URL: https://github.com/apache/shardingsphere/pull/18611#discussion_r906839060
##########
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:
refactor after code
```
Collection<String> routedTables = null;
if (!(tableShardingStrategy instanceof HintShardingStrategy)
&& existHintTableShardingValues()
&& !tableShardingValues.isEmpty()) {
ShardingConditionValue shardingConditionValue = tableShardingValues.iterator().next();
List<ShardingConditionValue> tableHintShardingValues = getTableShardingValuesFromHint(shardingConditionValue);
Collection<String> availableTargetTables = tableRule.getActualTableNames(routedDataSource);
routedTables = new LinkedHashSet<>(tableShardingStrategy.doSharding(availableTargetTables, tableHintShardingValues, tableRule.getTableDataNode(), properties));
}
if (routedTables == null) {
Collection<String> availableTargetTables = tableRule.getActualTableNames(routedDataSource);
routedTables = new LinkedHashSet<>(tableShardingValues.isEmpty()
? availableTargetTables
: tableShardingStrategy.doSharding(availableTargetTables, tableShardingValues, tableRule.getTableDataNode(), properties));
}
```
--
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
[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
Posted by GitBox <gi...@apache.org>.
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] terrymanu commented on a diff in pull request #18611: Support force route use hint provider sharding value when sharding strategy not is hint mode
Posted by GitBox <gi...@apache.org>.
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org