Commit 5bfde8e4 authored by wangpeng's avatar wangpeng

优化分区判断逻辑

parent 3ff74d4b
...@@ -96,7 +96,7 @@ public class FlinkStatementUtil { ...@@ -96,7 +96,7 @@ public class FlinkStatementUtil {
sb.append("` "); sb.append("` ");
sb.append(convertSinkColumnType(type, config)); sb.append(convertSinkColumnType(type, config));
sb.append("\n"); sb.append("\n");
if ((Objects.isNull(partitionKey) || partitionKey.isEmpty()) && table.getColumns().get(i).isKeyFlag()) { if (Boolean.FALSE.equals(isExitSchemaTable(table, partitionKey)) && table.getColumns().get(i).isKeyFlag()) {
pks.add(table.getColumns().get(i).getName()); pks.add(table.getColumns().get(i).getName());
} }
} }
...@@ -123,12 +123,27 @@ public class FlinkStatementUtil { ...@@ -123,12 +123,27 @@ public class FlinkStatementUtil {
return sb.toString(); return sb.toString();
} }
public static Boolean isExitSchemaTable(Table table, String partitionKey) {
if (Objects.isNull(partitionKey) || partitionKey.isEmpty()) {
return false;
}
JSONArray array = JSON.parseArray(partitionKey);
for (int i = 0; i < array.size(); i++) {
JSONObject jsonObject = array.getJSONObject(i);
String schemaTable = jsonObject.getString("schema-table");
if (Objects.equals(table.getSchemaTableName(), schemaTable)) {
return true;
}
}
return false;
}
public static void getPks(Table table, List<String> pks, String partitionKey) { public static void getPks(Table table, List<String> pks, String partitionKey) {
JSONArray array = JSON.parseArray(partitionKey); JSONArray array = JSON.parseArray(partitionKey);
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
JSONObject jsonObject = array.getJSONObject(i); JSONObject jsonObject = array.getJSONObject(i);
String schemaTable = jsonObject.getString("schema-table"); String schemaTable = jsonObject.getString("schema-table");
if (table.getSchemaTableName().equals(schemaTable)) { if (Objects.equals(table.getSchemaTableName(), schemaTable)) {
pks.addAll(Arrays.asList(jsonObject.getString("keys").split(","))); pks.addAll(Arrays.asList(jsonObject.getString("keys").split(",")));
} }
} }
......
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