Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](cdc) configure table buckets for a single sink #307

Merged
merged 9 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.doris.flink.sink.schema.SchemaChangeHelper.DDLSchema;
import org.apache.doris.flink.sink.schema.SchemaChangeManager;
import org.apache.doris.flink.sink.writer.EventType;
import org.apache.doris.flink.tools.cdc.DatabaseSync;
import org.apache.doris.flink.tools.cdc.SourceConnector;
import org.apache.doris.flink.tools.cdc.mysql.MysqlType;
import org.apache.doris.flink.tools.cdc.oracle.OracleType;
Expand Down Expand Up @@ -246,9 +247,34 @@ public TableSchema extractCreateTableSchema(JsonNode record) throws JsonProcessi
Preconditions.checkArgument(split.length == 2);
tableSchema.setDatabase(split[0]);
tableSchema.setTable(split[1]);
if (tableProperties.containsKey("table-buckets")) {
String tableBucketsConfig = tableProperties.get("table-buckets");
Map<String, Integer> tableBuckets = DatabaseSync.getTableBuckets(tableBucketsConfig);
Integer buckets = getTableSchemaBuckets(tableBuckets, tableSchema.getTable());
tableSchema.setTableBuckets(buckets);
}
return tableSchema;
}

@VisibleForTesting
public Integer getTableSchemaBuckets(Map<String, Integer> tableBucketsMap, String tableName) {
if (tableBucketsMap != null) {
// Firstly, if the table name is in the table-buckets map, set the buckets of the table.
if (tableBucketsMap.containsKey(tableName)) {
return tableBucketsMap.get(tableName);
}
// Secondly, iterate over the map to find a corresponding regular expression match,
for (Map.Entry<String, Integer> entry : tableBucketsMap.entrySet()) {

Pattern pattern = Pattern.compile(entry.getKey());
if (pattern.matcher(tableName).matches()) {
return entry.getValue();
}
}
}
return null;
}

private List<String> buildDistributeKeys(
List<String> primaryKeys, Map<String, FieldSchema> fields) {
if (!CollectionUtil.isNullOrEmpty(primaryKeys)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ protected HashMap<Pattern, String> multiToOneRulesParser(
* @param tableBuckets the string of tableBuckets, eg:student:10,student_info:20,student.*:30
* @return The table name and buckets map. The key is table name, the value is buckets.
*/
public Map<String, Integer> getTableBuckets(String tableBuckets) {
public static Map<String, Integer> getTableBuckets(String tableBuckets) {
Map<String, Integer> tableBucketsMap = new LinkedHashMap<>();
String[] tableBucketsArray = tableBuckets.split(",");
for (String tableBucket : tableBucketsArray) {
Expand Down
Loading