JNSimba commented on code in PR #288:
URL:
https://github.com/apache/doris-flink-connector/pull/288#discussion_r1446857087
##########
flink-doris-connector/src/main/java/org/apache/doris/flink/tools/cdc/DatabaseSync.java:
##########
@@ -338,6 +349,67 @@ protected HashMap<Pattern, String> multiToOneRulesParser(
return multiToOneRulesPattern;
}
+ /**
+ * Get table buckets Map.
+ *
+ * @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) {
+ Map<String, Integer> tableBucketsMap = new HashMap<>();
+ String[] tableBucketsArray = tableBuckets.split(",");
+ for (String tableBucket : tableBucketsArray) {
+ String[] tableBucketArray = tableBucket.split(":");
+ tableBucketsMap.put(
+ tableBucketArray[0].trim(),
Integer.parseInt(tableBucketArray[1].trim()));
+ }
+ return tableBucketsMap;
+ }
+
+ /**
+ * Set table schema buckets.
+ *
+ * @param tableBucketsMap The table name and buckets map. The key is table
name, the value is
+ * buckets.
+ * @param dorisSchema @{TableSchema}
+ * @param dorisTable the table name need to set buckets
+ * @param tableHasSet The buckets table is set
+ */
+ public void setTableSchemaBuckets(
+ Map<String, Integer> tableBucketsMap,
+ TableSchema dorisSchema,
+ String dorisTable,
+ Set<String> tableHasSet) {
+
+ if (tableBucketsMap != null) {
+ // Firstly, if the table name is in the table-buckets map, set the
buckets of the table.
+ if (tableBucketsMap.containsKey(dorisTable)) {
+ dorisSchema.setTableBuckets(tableBucketsMap.get(dorisTable));
+ tableHasSet.add(dorisTable);
+ return;
+ }
+ // Secondly, iterate over the map to find a corresponding regular
expression match,
+ // excluding .* matches
+ for (Map.Entry<String, Integer> entry :
tableBucketsMap.entrySet()) {
+ if (tableHasSet.contains(entry.getKey())) {
+ continue;
+ }
+
+ Pattern pattern = Pattern.compile(entry.getKey());
+ if (!entry.getKey().equals(".*") &&
pattern.matcher(dorisTable).matches()) {
Review Comment:
`.*` is also a regular expression and can be matched directly
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]