Commit 2d9ab50f authored by 沈毫厘's avatar 沈毫厘

分库分表修改

parent e552acf5
package com.dsk.flink.dsc.common.function;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dsk.flink.dsc.utils.EnvProperties;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.functions.async.ResultFuture;
import org.apache.flink.streaming.api.functions.async.RichAsyncFunction;
......@@ -66,6 +69,24 @@ public class AsyncMysqlDataTransferFunction extends RichAsyncFunction<JSONObject
pkNames.forEach(name -> pkNameSet.add(String.valueOf(name)));
}
String shardingRule = dataObj.getString("shardingRule");
String concat = "";
if (StrUtil.isNotBlank(shardingRule)){
Map<String,Object> map = JSON.parseObject(shardingRule, Map.class);
String strategy = map.get("strategy").toString();
Map<String,Object> strategyMap = JSON.parseObject(strategy, Map.class);
String str = MapUtil.getStr(strategyMap, "sharding-column");
int i = MapUtil.getInt(strategyMap, "sharding-count").intValue();
if (i > 1){
int tableNum = dataObj.getInteger(str).intValue() % i;
concat = table.concat("_").concat(String.valueOf(tableNum));
}else {
concat = table;
}
}else {
String shardedTable = dbInfoMap.getSharded_table();
List<Map<String,Object>> list = JSONArray.parseObject(shardedTable, List.class);
......@@ -73,7 +94,9 @@ public class AsyncMysqlDataTransferFunction extends RichAsyncFunction<JSONObject
return l.get("table").toString().equals(table);
}).collect(Collectors.toList());
String concat = "";
if (ObjectUtils.isEmpty(table1)){
concat = table;
}else {
//分表数
String tbNum = table1.get(0).get("tb_num").toString();
//分表字段
......@@ -84,6 +107,8 @@ public class AsyncMysqlDataTransferFunction extends RichAsyncFunction<JSONObject
}else {
concat = table;
}
}
}
String excueteSql = "";
if(isDdl){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment