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 2019/12/05 11:23:57 UTC

[GitHub] [incubator-shardingsphere] lightning-pro commented on issue #3670: if null value is not supported?

lightning-pro commented on issue #3670: if null value is not supported?
URL: https://github.com/apache/incubator-shardingsphere/issues/3670#issuecomment-562088575
 
 
   my tables split to 17 tables from 0 to 16
   when execute below sql, which the value of COMMENTS field is null
   ```
   SELECT PRIM.SMS_NUM_ID, PRIM.PUBLIC_VIEW_ID,PRIM.COMMENTS
   FROM CUSTOMER_SMS_NUM PRIM WHERE (PRIM.SMS_NUM_ID >= 1 AND PRIM.SMS_NUM_ID <= 18) order by PRIM.SMS_NUM_ID
   ```
   the above sql work perfect
   
   when execute like below, there will be a row with all null values and other rows ok
   ```
   SELECT PRIM.SMS_NUM_ID, PRIM.PUBLIC_VIEW_ID,PRIM.COMMENTS
   FROM CUSTOMER_SMS_NUM PRIM WHERE (PRIM.SMS_NUM_ID >= 1 AND PRIM.SMS_NUM_ID <= 19) order by PRIM.SMS_NUM_ID
   ```
   
   while increase the bigger range with 20,21,22....the rows with null values will increase randomly.
   
   but when I remove the PRIM.COMMENTS fields, everything is ok. return the expected records
   
   the sharding field is SMS_NUM_ID with Integer value
    and my sharding algorithm as belows
   RangeShardingAlgorithm
   
   ```
   @Override
       public Collection<String> doSharding(Collection<String> availableTargetNames, RangeShardingValue<Integer> shardingValue) {
           Collection<String> result = new HashSet<>();
           if(shardingValue.getValueRange().hasUpperBound()){
               for (int i = shardingValue.getValueRange().lowerEndpoint(); i <= shardingValue.getValueRange().upperEndpoint(); i++) {
                   for (String each : availableTargetNames) {
                       if (each.endsWith(String.valueOf(i % availableTargetNames.size()))) {
                           result.add(each);
                       }
                   }
               }
           }else {
               result = availableTargetNames;
           }
   
           return result;
       }
   ```
   PreciseShardingAlgorithm
   ```
   @Override
       public String doSharding(Collection<String> collection, PreciseShardingValue<Integer> preciseShardingValue) {
           for (String each : collection) {
               if (each.endsWith(String.valueOf(preciseShardingValue.getValue() % collection.size()))) {
                   return each;
               }
           }
           return null;
       }
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services