You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2023/01/07 09:07:59 UTC

[GitHub] [incubator-seatunnel] TaoZex commented on a diff in pull request #3892: [Feature][CDC] Support write cdc changelog event in doris sink

TaoZex commented on code in PR #3892:
URL: https://github.com/apache/incubator-seatunnel/pull/3892#discussion_r1063979253


##########
seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/serialize/DorisColumnRowSerialize.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.seatunnel.connectors.doris.serialize;
+
+import org.apache.seatunnel.api.serialization.SerializationSchema;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.common.exception.CommonErrorCode;
+import org.apache.seatunnel.connectors.doris.client.DorisRecord;
+import org.apache.seatunnel.connectors.doris.config.SinkConfig;
+import org.apache.seatunnel.connectors.doris.exception.DorisConnectorException;
+import org.apache.seatunnel.connectors.doris.util.DelimiterParserUtil;
+import org.apache.seatunnel.format.json.JsonSerializationSchema;
+import org.apache.seatunnel.format.text.TextSerializationSchema;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.Getter;
+
+public class DorisColumnRowSerialize implements SeaTunnelRowSerializer{
+    /**
+     * RowType to generate the runtime converter.
+     */
+    private final SeaTunnelRowType rowType;
+    private final SinkConfig sinkConfig;
+
+    /** Object mapper that is used to create output JSON objects. */
+    @Getter
+    private final ObjectMapper mapper = new ObjectMapper();
+
+    public DorisColumnRowSerialize(SeaTunnelRowType rowType, SinkConfig sinkConfig) {
+        this.rowType = rowType;
+        this.sinkConfig = sinkConfig;
+    }
+
+    @Override
+    public DorisRecord serialize(SeaTunnelRow row) {
+        switch (row.getRowKind()) {
+            case INSERT:
+                return serializeInsert(row);
+            case UPDATE_AFTER:
+                return serializeUpsert(row);
+            case DELETE:
+                return serializeDelete(row);
+            default:
+                throw new DorisConnectorException(
+                    CommonErrorCode.UNSUPPORTED_OPERATION, "Unsupported write row kind: " + row.getRowKind());
+        }
+    }
+
+    private DorisRecord serializeDelete(SeaTunnelRow row) {
+        SerializationSchema serializer = createSerializer(sinkConfig, rowType);
+        String record = new String(serializer.serialize(row));
+        DorisRecord dorisRecord = DorisRecord.builder().record(record)
+            .enableDelete(true).mergeType("DELETE").build();
+        return dorisRecord;
+    }
+
+    private DorisRecord serializeUpsert(SeaTunnelRow row) {
+        SerializationSchema serializer = createSerializer(sinkConfig, rowType);

Review Comment:
   Calling the createSerializer method on each row may affect performance.
   How about calling the createSerializer method only once?



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

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