xrayw commented on issue #24328:
URL: 
https://github.com/apache/shardingsphere/issues/24328#issuecomment-1448184887

   Example:
   1. Insert 300 rows data to user, the max id in user is 300 now.
   2. manually move rows 1-100 to user_1, 101-200 to user_2,  **now user table 
have data 201-300**
   
   Data alwasy insert to main table `user`, other table like ** user_1, user_2 
... user_x ** just for query
   
   I can write a shardingRule such as:
   ```java
   public class UserShardingAlgorithm implements 
StandardShardingAlgorithm<Long> {
       @Override
       public String getType() {
           return "USER_SHARD";
       }
   
       @Override
       public String doSharding(Collection<String> availables, 
PreciseShardingValue<Long> shardingValue) {
           Long id = shardingValue.getValue();
           if (id == null) {
               // always insert to user
               return "user";
           }
           
           // for query
           List<IdTableRange> idTableMapping = someIdMappingLogic();
           for (IdTableRange idTableRange : idTableMapping) {
               if (idTableRange.contains(id)) {
                   return idTableRange.table;
               }
           }
   
           throw new RuntimeException("unreachable");
       }
   
       @Override
       public Collection<String> doSharding(Collection<String> collection, 
RangeShardingValue<Long> rangeShardingValue) {
           return null;
       }
   
       @Override
       public Properties getProps() {
           return null;
       }
   
       @Override
       public void init(Properties 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: [email protected]

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

Reply via email to