maven:
yml:
sharding:
tables:
emp:
actual-data-nodes : d1.emp_$->{2018..2020},d2.emp_2017
database-strategy.standard.sharding-column : user_id
database-strategy.standard.precise-algorithm-class-name : com.example.sharding.config.MyPreciseDBShardingAlgorithm
table-strategy.standard.sharding-column : user_id
table-strategy.standard.precise-algorithm-class-name : com.example.sharding.config.MyPreciseShardingAlgorithm
table-strategy.standard.range-algorithm-class-name : com.example.sharding.config.MyPreciseShardingAlgorithm
public class MyPreciseShardingAlgorithm implements PreciseShardingAlgorithm
@Override
public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Integer> rangeShardingValue) {
System.out.println("--------"+JSON.toJSONString(collection));
System.out.println("--------"+JSON.toJSONString(rangeShardingValue));
return collection;
}
@Override
public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Integer> shardingValue) {
System.out.println("-----table----"+JSON.toJSONString(availableTargetNames));
System.out.println("-----table----"+JSON.toJSONString(shardingValue));
}
}
sql:
select * from emp where user_id = 20
success: console print log:
-----db----["d1","d2"]
-----db----{"columnName":"user_id","logicTableName":"emp","value":2}
-----table----["emp_2017"]
-----table----{"columnName":"user_id","logicTableName":"emp","value":2}
sql:
select * from emp where user_id between 0 and 20
error: Exception:
java.lang.UnsupportedOperationException: Cannot find range sharding strategy in sharding rule.] with root cause
console not print log:
Not executed "System.out.println("--------"+JSON.toJSONString(collection))" in MyPreciseShardingAlgorithm
@bx189303 Could you provide the demo so that we can reproduce this problem
@bx189303 I guess you should add database-strategy.standard.range-algorithm-class-name config, if you use range sql.
@bx189303 I guess you should add
database-strategy.standard.range-algorithm-class-nameconfig, if you use range sql.
you are right , I used to think only config table-strategy.standard.range-algorithm-class-name
Most helpful comment
@bx189303 I guess you should add
database-strategy.standard.range-algorithm-class-nameconfig, if you use range sql.