此种规则类似于取模范围约束,此规则支持数据符号字母取模。
user_id
sharding-by-prefixpattern
256
5
partition-pattern.txt
partition-pattern.txt:
partition-pattern.txt
# range start-end ,data node index
# ASCII
# 8-57=0-9阿拉伯数字
# 64、65-90=@、A-Z
# 97-122=a-z
###### first host configuration
1-4=0
5-8=1
9-12=2
13-16=3
###### second host configuration
17-20=4
21-24=5
25-28=6
29-32=7
0-0=7
配置说明: 上面columns 标识将要分片的表字段,algorithm 分片函数,patternValue 即求模基数,prefixLength ASCII 截取的位数。
mapFile 配置文件路径: 配置文件中,1-32 即代表id%256后分布的范围,如果在1-32则在分区1,其他类推。
此种方式类似方式6只不过采取的是将列种获取前prefixLength位列所有ASCII码的和进行求模sum%patternValue ,获取的值,在范围内的分片数
String idVal=“gf89f9a”;
Assert.assertEquals(true, 0==autoPartition.calculate(idVal));
idVal=“8df99a”;
Assert.assertEquals(true, 4==autoPartition.calculate(idVal));
idVal=“8dhdf99a”;Assert.assertEquals(true,3==autoPartition.calculate(idVal));