You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/04/21 06:59:16 UTC

[GitHub] [incubator-inlong] yunqingmoswu commented on a diff in pull request #3865: [INLONG-3860][Sort] Add json(avro/debezium-json/canal-json) format for ExtractNode and LoadNode

yunqingmoswu commented on code in PR #3865:
URL: https://github.com/apache/incubator-inlong/pull/3865#discussion_r854829586


##########
inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/node/load/KafkaLoadNode.java:
##########
@@ -77,13 +93,57 @@ public String genTableName() {
     @Override
     public Map<String, String> tableOptions() {
         Map<String, String> options = super.tableOptions();
-        options.put("connector", "kafka");
         options.put("topic", topic);
         options.put("properties.bootstrap.servers", bootstrapServers);
-        options.put("format", format);
         if (getSinkParallelism() != null) {
             options.put("sink.parallelism", getSinkParallelism().toString());
         }
+        if (format instanceof JsonFormat) {
+            JsonFormat jsonFormat = (JsonFormat) format;
+            options.put("connector", "upsert-kafka");
+            options.put("key.format", jsonFormat.getFormat());
+            options.put("value.format", jsonFormat.getFormat());
+            options.put("value.json.fail-on-missing-field", jsonFormat.getFailOnMissingField() + "");

Review Comment:
   It is recommended to use toString instead of concatenating empty strings



##########
inlong-sort/sort-common/src/test/java/org/apache/inlong/sort/protocol/node/format/FormatTest.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.sort.protocol.node.format;
+
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class FormatTest {

Review Comment:
   It is recommended to abstract a FormatBaseTest parent class, and each Format derived class provides a Unit test class



##########
inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/node/load/KafkaLoadNode.java:
##########
@@ -77,13 +93,57 @@ public String genTableName() {
     @Override
     public Map<String, String> tableOptions() {
         Map<String, String> options = super.tableOptions();
-        options.put("connector", "kafka");
         options.put("topic", topic);
         options.put("properties.bootstrap.servers", bootstrapServers);
-        options.put("format", format);
         if (getSinkParallelism() != null) {
             options.put("sink.parallelism", getSinkParallelism().toString());
         }
+        if (format instanceof JsonFormat) {
+            JsonFormat jsonFormat = (JsonFormat) format;
+            options.put("connector", "upsert-kafka");
+            options.put("key.format", jsonFormat.getFormat());
+            options.put("value.format", jsonFormat.getFormat());
+            options.put("value.json.fail-on-missing-field", jsonFormat.getFailOnMissingField() + "");
+            options.put("value.json.ignore-parse-errors", jsonFormat.getIgnoreParseErrors() + "");
+            options.put("value.json.timestamp-format.standard", jsonFormat.getTimestampFormatStandard());
+            options.put("value.json.map-null-key.mode", jsonFormat.getMapNullKeyMode());
+            options.put("value.json.map-null-key.literal", jsonFormat.getMapNullKeyLiteral());
+            options.put("value.json.encode.decimal-as-plain-number", jsonFormat.getEncodeDecimalAsPlainNumber() + "");
+            options.put("key.json.fail-on-missing-field", jsonFormat.getFailOnMissingField() + "");
+            options.put("key.json.ignore-parse-errors", jsonFormat.getIgnoreParseErrors() + "");
+            options.put("key.json.timestamp-format.standard", jsonFormat.getTimestampFormatStandard());
+            options.put("key.json.map-null-key.mode", jsonFormat.getMapNullKeyMode());
+            options.put("key.json.map-null-key.literal", jsonFormat.getMapNullKeyLiteral());
+            options.put("key.json.encode.decimal-as-plain-number", jsonFormat.getEncodeDecimalAsPlainNumber() + "");
+        } else if (format instanceof AvroFormat) {

Review Comment:
   It is recommended to decouple Format and Node, and try to avoid modifying Node when adding format support



-- 
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-unsubscribe@inlong.apache.org

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