You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "IcebergXTY (via GitHub)" <gi...@apache.org> on 2023/06/14 12:14:36 UTC

[GitHub] [shardingsphere] IcebergXTY opened a new issue, #26348: why return empty when just one conditon is empty

IcebergXTY opened a new issue, #26348:
URL: https://github.com/apache/shardingsphere/issues/26348

   ## Question
   
   [code location](https://github.com/apache/shardingsphere/blob/a0a1f25e187010cc79adccd432bf94bfac3fc416/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/WhereClauseShardingConditionEngine.java#LL98C13-L98C13)。
   
   See the sql below
   ```sql
   select concat(data_source_id, '_', cost_item_name) as ruleKey,
       sum(ori_amount) as ori_amount
   from cost_item_order_detail
   where tenant_code = ?
       and platform_code = ?
       and shop_code = ?
       and order_date between ? and ?
       and (
           data_source_id = ?
           and cost_item_name = ?
       )
       or (
           data_source_id = ?
           and cost_item_name = ?
       )
   group by data_source_id,
       cost_item_name
   ```
   shardingsphere will analyse two `AndPredicate`, one is `tenant_code = ? platform_code = ? and shop_code = ? and order_date between ? and ? and (data_source_id = ? and cost_item_name = ?)` and the other is `data_source_id = ? and cost_item_name = ?`.
   
   We use `tenant_code = ? platform_code = ? and shop_code = ?` as table sharding rule so the `shardingConditionValues`  from the first `AndPredicate` is OK, but the second is empty. But in the code above, if there is any empty `shardingConditionValues`, it will return `Collections.emptyList()` which raise an error in our project.
   
   I wonder to know why return empty when just one conditon is empty here 🤨
   


-- 
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.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] IcebergXTY commented on issue #26348: why return empty when just one conditon is empty

Posted by "IcebergXTY (via GitHub)" <gi...@apache.org>.
IcebergXTY commented on issue #26348:
URL: https://github.com/apache/shardingsphere/issues/26348#issuecomment-1598159661

   As said in the first, the code [here](https://github.com/apache/shardingsphere/blob/a0a1f25e187010cc79adccd432bf94bfac3fc416/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/WhereClauseShardingConditionEngine.java#LL98C13-L98C13) are weird.
   ```java
   private Collection<ShardingCondition> createShardingConditions(final ExpressionSegment expression, final List<Object> params, final Map<String, String> columnExpressionTableNames) {
       Collection<AndPredicate> andPredicates = ExpressionExtractUtil.getAndPredicates(expression);
       Collection<ShardingCondition> result = new LinkedList<>();
       for (AndPredicate each : andPredicates) {
           Map<Column, Collection<ShardingConditionValue>> shardingConditionValues = createShardingConditionValueMap(each.getPredicates(), params, columnExpressionTableNames);
           // If any `AndPredicate` is empty, then all this method will return empty
           if (shardingConditionValues.isEmpty()) {
               return Collections.emptyList();
           }
           ShardingCondition shardingCondition = createShardingCondition(shardingConditionValues);
           shardingCondition.setStartIndex(expression.getStartIndex());
           result.add(shardingCondition);
       }
       return result;
   }
   ```


-- 
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] RaigorJiang commented on issue #26348: why return empty when just one conditon is empty

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on issue #26348:
URL: https://github.com/apache/shardingsphere/issues/26348#issuecomment-1594834594

   > In this scenario shown in the demo, empty shardingcondition will lead to a whole route so it will try to execute sql on the all 1000 table and then throw a exception Table 'cost_item_order_detail_11' doesn't exist
   
   @IcebergXTY Because you said that there was an empty sharding condition.


-- 
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] RaigorJiang commented on issue #26348: why return empty when just one conditon is empty

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on issue #26348:
URL: https://github.com/apache/shardingsphere/issues/26348#issuecomment-1593842730

   @IcebergXTY There is no sharding key when database routing, so all data sources are routed.


-- 
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] IcebergXTY commented on issue #26348: why return empty when just one conditon is empty

Posted by "IcebergXTY (via GitHub)" <gi...@apache.org>.
IcebergXTY commented on issue #26348:
URL: https://github.com/apache/shardingsphere/issues/26348#issuecomment-1592311600

   @RaigorJiang Of course, I push [here](https://github.com/IcebergXTY/shardingsphere-return-empty-demo).
   Just explain it, we set `actualDataNodes: ds_$->{0..1}.cost_item_order_detail_$->{0..999}`, but we may just use `ds_$->{0..1}.cost_item_order_detail_$->{0..10}`, so the number of tables in the database are 11 rather than 1000.
   We use `shop_code` to judge the actual sharding table and the user can add shop at any time so we need a large enough range like `$->{0..999}` .
   In this scenario shown in the demo, empty shardingcondition will lead to a whole route so it will try to execute sql on the all 1000 table and then throw a exception `Table 'cost_item_order_detail_11' doesn't exist`


-- 
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] github-actions[bot] commented on issue #26348: why return empty when just one conditon is empty

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #26348:
URL: https://github.com/apache/shardingsphere/issues/26348#issuecomment-1644528277

   There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.


-- 
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] IcebergXTY commented on issue #26348: why return empty when just one conditon is empty

Posted by "IcebergXTY (via GitHub)" <gi...@apache.org>.
IcebergXTY commented on issue #26348:
URL: https://github.com/apache/shardingsphere/issues/26348#issuecomment-1593999786

   > @IcebergXTY There is no sharding key when database routing, so all data sources are routed.
   
   `tenant_code = 'a' and platform_code = 'b' and shop_code = 'c'` are not valid sharding key?🤨


-- 
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] IcebergXTY commented on issue #26348: why return empty when just one conditon is empty

Posted by "IcebergXTY (via GitHub)" <gi...@apache.org>.
IcebergXTY commented on issue #26348:
URL: https://github.com/apache/shardingsphere/issues/26348#issuecomment-1598156736

   > @IcebergXTY Because you said that there was an empty sharding condition.
   
   That's the question, I have set all the values, but shardingsphere consider there is no `sharding condition`


-- 
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] RaigorJiang commented on issue #26348: why return empty when just one conditon is empty

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on issue #26348:
URL: https://github.com/apache/shardingsphere/issues/26348#issuecomment-1592243287

   Hi @IcebergXTY 
   Can you provide a sharding configuration and table structure for testing?


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