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


##########
flink-doris-connector/src/main/java/org/apache/doris/flink/tools/cdc/mongodb/serializer/MongoJsonDebeziumSchemaChange.java:
##########
@@ -118,6 +159,45 @@ public boolean schemaChange(JsonNode recordRoot) {
         }
     }
 
+    public static <K, V> V getRandomValue(Map<K, V> map) {
+        Collection<V> values = map.values();
+        return values.stream().findAny().orElse(null);
+    }
+
+    private void tryCreateTableIfAbsent(
+            DorisSystem dorisSystem, String targetDb, String dorisTable, 
SourceSchema schema) {
+        if (!dorisSystem.tableExists(targetDb, dorisTable)) {
+            if (changeContext.getDorisTableConf().isConvertUniqToPk()
+                    && CollectionUtil.isNullOrEmpty(schema.primaryKeys)
+                    && !CollectionUtil.isNullOrEmpty(schema.uniqueIndexs)) {
+                schema.primaryKeys = new ArrayList<>(schema.uniqueIndexs);
+            }
+            TableSchema dorisSchema =
+                    DorisSchemaFactory.createTableSchema(
+                            targetDb,
+                            dorisTable,
+                            schema.getFields(),
+                            schema.getPrimaryKeys(),
+                            changeContext.getDorisTableConf(),
+                            schema.getTableComment());
+            try {
+                dorisSystem.createTable(dorisSchema);
+            } catch (Exception ex) {
+                handleTableCreationFailure(ex);
+            }
+        }
+    }
+
+    private void handleTableCreationFailure(Exception ex) throws 
DorisSystemException {
+        if (ex.getCause() instanceof SQLSyntaxErrorException) {
+            LOG.warn(
+                    "Doris schema and source table schema are not compatible. 
Error: {} ",
+                    ex.getCause().toString());
+        } else {
+            throw new DorisSystemException("Failed to create table due to: ", 
ex);
+        }
+    }
+

Review Comment:
   This looks like duplicate code, maybe we can probably pull it out.



-- 
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