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


##########
flink-doris-connector/src/main/java/org/apache/doris/flink/tools/cdc/mongodb/MongoDBSchema.java:
##########
@@ -64,6 +65,28 @@ public MongoDBSchema(
         primaryKeys.add("_id");
     }
 
+    public MongoDBSchema(
+            JsonNode jsonData, String databaseName, String tableName, String 
tableComment)
+            throws Exception {
+        super(databaseName, null, tableName, tableComment);
+        fields = new LinkedHashMap<>();
+        processSampleData(jsonData);
+
+        primaryKeys = new ArrayList<>();
+        primaryKeys.add("_id");
+    }
+
+    @VisibleForTesting
+    protected void processSampleData(JsonNode data) {
+        data.fieldNames()
+                .forEachRemaining(
+                        fieldName -> {
+                            JsonNode value = data.get(fieldName);
+                            String dorisType = 
MongoDBType.jsonNodeToDorisType(value);
+                            fields.put(fieldName, new FieldSchema(fieldName, 
dorisType, null));
+                        });
+    }
+

Review Comment:
   maybe we can add ut for this like MongoDBSchemaTest



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