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/24 08:25:25 UTC

[GitHub] [incubator-inlong] healchow commented on a diff in pull request #3901: [INLONG-3885][Sort] Add KafkaExtractNode supporting

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


##########
inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/node/extract/KafkaExtractNode.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.extract;
+
+import com.google.common.base.Preconditions;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonTypeName;
+import org.apache.inlong.sort.protocol.FieldInfo;
+import org.apache.inlong.sort.protocol.enums.ScanStartupMode;
+import org.apache.inlong.sort.protocol.node.ExtractNode;
+import org.apache.inlong.sort.protocol.node.format.AvroFormat;
+import org.apache.inlong.sort.protocol.node.format.CanalJsonFormat;
+import org.apache.inlong.sort.protocol.node.format.CsvFormat;
+import org.apache.inlong.sort.protocol.node.format.DebeziumJsonFormat;
+import org.apache.inlong.sort.protocol.node.format.Format;
+import org.apache.inlong.sort.protocol.node.format.JsonFormat;
+import org.apache.inlong.sort.protocol.transformation.WatermarkField;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Kafka extract node for extract data from kafka
+ */
+@EqualsAndHashCode(callSuper = true)
+@JsonTypeName("kafkaExtract")
+@Data
+public class KafkaExtractNode extends ExtractNode implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Nonnull
+    @JsonProperty("topic")
+    private String topic;
+    @Nonnull
+    @JsonProperty("bootstrapServers")
+    private String bootstrapServers;
+    @Nonnull
+    @JsonProperty("format")
+    private Format format;
+
+    @JsonProperty("scanStartupMode")
+    private ScanStartupMode scanStartupMode;
+
+    @JsonProperty("primaryKey")
+    private String primaryKey;
+
+    @JsonCreator
+    public KafkaExtractNode(@JsonProperty("id") String id,
+            @JsonProperty("name") String name,
+            @JsonProperty("fields") List<FieldInfo> fields,
+            @Nullable @JsonProperty("watermarkField") WatermarkField watermarkField,
+            @JsonProperty("properties") Map<String, String> properties,
+            @Nonnull @JsonProperty("topic") String topic,
+            @Nonnull @JsonProperty("bootstrapServers") String bootstrapServers,
+            @Nonnull @JsonProperty("format") Format format,
+            @JsonProperty("scanStartupMode") ScanStartupMode scanStartupMode,
+            @JsonProperty("primaryKey") String primaryKey) {
+        super(id, name, fields, watermarkField, properties);
+        this.topic = Preconditions.checkNotNull(topic, "kafka topic is empty");
+        this.bootstrapServers = Preconditions.checkNotNull(bootstrapServers, "kafka bootstrapServers is empty");
+        this.format = Preconditions.checkNotNull(format, "kafka format is empty");
+        this.scanStartupMode = Preconditions.checkNotNull(scanStartupMode, "kafka scanStartupMode is empty");
+        this.primaryKey = primaryKey;
+    }
+
+    /**
+     * generate table options
+     *
+     * @return options
+     */
+    @Override
+    public Map<String, String> tableOptions() {
+        Map<String, String> options = super.tableOptions();
+        options.put("topic", topic);

Review Comment:
   These are magic strings. Can they be extracted as constants?



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