luoyexiaoran commented on issue #18949:
URL:
https://github.com/apache/shardingsphere/issues/18949#issuecomment-1198843475
`rules:
- !SHARDING
# 配置分片规则
tables:
# 配置商户汇总表cc_restaurant_collect_data规则
cc_restaurant_collect_data:
actualDataNodes:
ds0.cc_restaurant_collect_data$->{2020..2022}0$->{1..9},ds0.cc_restaurant_collect_data$->{2020..2022}1$->{0..2}
# 配置分表策略
tableStrategy:
standard:
shardingColumn: collectDate
shardingAlgorithmName: cc_restaurant_collect_data
# 商户汇总表(修正收运量)
cc_restaurant_collect_data_correct_weight:
actualDataNodes:
ds0.cc_restaurant_collect_data_correct_weight$->{2020..2022}0$->{1..9},ds0.cc_restaurant_collect_data_correct_weight$->{2020..2022}1$->{0..2}
# 配置分表策略
tableStrategy:
standard:
shardingColumn:
collectDaterestaurantCollectDataCorrectWeightController
shardingAlgorithmName: cc_restaurant_collect_data_correct_weight
# 配置商户汇总表cc_sypoint_collect_data规则
cc_sypoint_collect_data:
actualDataNodes:
ds0.cc_sypoint_collect_data$->{2020..2022}0$->{1..9},ds0.cc_sypoint_collect_data$->{2020..2022}1$->{0..2}
# 配置分表策略
tableStrategy:
standard:
shardingColumn: collectDate
shardingAlgorithmName: cc_sypoint_collect_data
# 配置商户汇总表cc_rfid规则
cc_rfid:
actualDataNodes:
ds0.cc_rfid$->{2020..2022}0$->{1..9},ds0.cc_rfid$->{2020..2022}1$->{0..2}
# 配置分表策略
tableStrategy:
standard:
shardingColumn: time
shardingAlgorithmName: cc_rfid
# 配置商户汇总表cc_weighbridge规则
cc_weighbridge:
actualDataNodes:
ds0.cc_weighbridge$->{2020..2022}0$->{1..9},ds0.cc_weighbridge$->{2020..2022}1$->{0..2}
# 配置分表策略
tableStrategy:
standard:
shardingColumn: grossDateTime
shardingAlgorithmName: cc_weighbridge
# 配置商户汇总表cc_sypoint_collect_data规则
cc_car_alarm_event:
actualDataNodes:
ds0.cc_car_alarm_event$->{2022}0$->{1..9},ds0.cc_car_alarm_event$->{2022}1$->{0..2}
# 配置分表策略
tableStrategy:
standard:
shardingColumn: alarmTime
shardingAlgorithmName: cc_car_alarm_event
shardingAlgorithms:
cc_restaurant_collect_data:
type: CLASS_BASED
props:
strategy: standard
algorithmClassName:
com.vortex.cloud.envcloud.cc.config.sharding.RestaurantCollectDataShardingAlgorithm
cc_restaurant_collect_data_correct_weight:
type: CLASS_BASED
props:
strategy: standard
algorithmClassName:
com.vortex.cloud.envcloud.cc.config.sharding.RestaurantCollectDataCorrectWeightShardingAlgorithm
cc_sypoint_collect_data:
type: CLASS_BASED
props:
strategy: standard
algorithmClassName:
com.vortex.cloud.envcloud.cc.config.sharding.SypointCollectDataShardingAlgorithm
cc_rfid:
type: CLASS_BASED
props:
strategy: standard
algorithmClassName:
com.vortex.cloud.envcloud.cc.config.sharding.RfidDataShardingAlgorithm
cc_weighbridge:
type: CLASS_BASED
props:
strategy: standard
algorithmClassName:
com.vortex.cloud.envcloud.cc.config.sharding.WeighbridgeShardingAlgorithm
cc_car_alarm_event:
type: CLASS_BASED
props:
strategy: standard
algorithmClassName:
com.vortex.cloud.envcloud.cc.config.sharding.CarAlarmEventShardingAlgorithm
#属性配置
props:
sql-show: true`
` @Override
public String doSharding(Collection availableTargetNames,
PreciseShardingValue shardingValue) {
String collectDate = (String) shardingValue.getValue();
LinkedList<String> tableNames = CollectionUtil.newLinkedList();
tableNames.addAll(availableTargetNames);
//获取所有表名,确定范围
for (String tableName : tableNames) {
String month = tableName.substring(tableName.length() - 6);
if (month.equals(collectDate.substring(0, 7).replaceAll("-",
""))) {
return tableName;
}
}
throw new VortexException("未找到分表路由");
}
@Override
public Collection<String> doSharding(Collection availableTargetNames,
RangeShardingValue shardingValue) {
List<String> result = CollectionUtil.newLinkedList();
Range<String> ranges = shardingValue.getValueRange();
result.addAll(availableTargetNames);
if (ranges.hasLowerBound()) {
String startDate = ranges.lowerEndpoint();
DateTime beginOfMonth =
DateUtil.beginOfMonth(DateUtil.parse(startDate.substring(0, 7), "yyyy-MM"));
result = result.stream().filter(tableName -> {
String month = tableName.substring(tableName.length() - 6);
DateTime endOfMonth =
DateUtil.endOfMonth(DateUtil.parse(month, "yyyyMM"));
return beginOfMonth.getTime() <= endOfMonth.getTime();
}).collect(Collectors.toList());
}
if (ranges.hasUpperBound()) {
String endDate = ranges.upperEndpoint();
DateTime endOfMonth =
DateUtil.endOfMonth(DateUtil.parse(endDate.substring(0, 7), "yyyy-MM"));
result = result.stream().filter(tableName -> {
String month = tableName.substring(tableName.length() - 6);
DateTime beginOfMonth =
DateUtil.beginOfMonth(DateUtil.parse(month, "yyyyMM"));
return beginOfMonth.getTime() <= endOfMonth.getTime();
}).collect(Collectors.toList());
}
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]