healchow commented on code in PR #4666:
URL: https://github.com/apache/incubator-inlong/pull/4666#discussion_r898144305


##########
inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/node/extract/MongoExtractNode.java:
##########
@@ -61,23 +63,28 @@ public class MongoExtractNode extends ExtractNode 
implements Serializable {
 
     @JsonCreator
     public MongoExtractNode(@JsonProperty("id") String id,
-        @JsonProperty("name") String name,
-        @JsonProperty("fields") List<FieldInfo> fields,
-        @Nullable @JsonProperty("watermarkField") WatermarkField 
waterMarkField,
-        @JsonProperty("properties") Map<String, String> properties,
-        @JsonProperty("primaryKey") String primaryKey,
-        @JsonProperty("collection") @Nonnull String collection,
-        @JsonProperty("hostname") String hostname,
-        @JsonProperty("username") String username,
-        @JsonProperty("password") String password,
-        @JsonProperty("database") String database) {
+            @JsonProperty("name") String name,
+            @JsonProperty("fields") List<FieldInfo> fields,
+            @Nullable @JsonProperty("watermarkField") WatermarkField 
waterMarkField,
+            @JsonProperty("properties") Map<String, String> properties,
+            @JsonProperty("collection") @Nonnull String collection,
+            @JsonProperty("hostname") String hostname,
+            @JsonProperty("username") String username,
+            @JsonProperty("password") String password,
+            @JsonProperty("database") String database) {
         super(id, name, fields, waterMarkField, properties);
+        if (fields.stream().noneMatch(m -> m.getName().equals("_id"))) {
+            List<FieldInfo> allFields = new ArrayList<>(fields);
+            allFields.add(new FieldInfo("_id", new StringFormatInfo()));
+            this.setFields(allFields);
+        }
         this.collection = Preconditions.checkNotNull(collection, "collection 
is null");
         this.hosts = Preconditions.checkNotNull(hostname, "hostname is null");
         this.username = Preconditions.checkNotNull(username, "username is 
null");
         this.password = Preconditions.checkNotNull(password, "password is 
null");
         this.database = Preconditions.checkNotNull(database, "database is 
null");
-        this.primaryKey = primaryKey;
+        // the primaryKey must be "_id"
+        this.primaryKey = "_id";

Review Comment:
   Suggest using a String constant for `_id`, and add a link for why the 
primary key must be `_id`.



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

Reply via email to