JNSimba commented on code in PR #288:
URL: 
https://github.com/apache/doris-flink-connector/pull/288#discussion_r1450053836


##########
flink-doris-connector/src/main/java/org/apache/doris/flink/tools/cdc/DatabaseSync.java:
##########
@@ -338,6 +350,60 @@ 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 LinkedHashMap<>();
+        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,
+            for (Map.Entry<String, Integer> entry : 
tableBucketsMap.entrySet()) {
+                if (tableHasSet.contains(entry.getKey())) {
+                    continue;
+                }
+
+                Pattern pattern = Pattern.compile(entry.getKey());
+                if (pattern.matcher(dorisTable).matches()) {

Review Comment:
   Do we need to consider tablePrefix and tableSuffix?



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to