You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/10/08 09:25:51 UTC

[GitHub] [doris-flink-connector] dinggege1024 opened a new pull request, #71: [Enhancement] ADD RowSerializer for doris flink connector

dinggege1024 opened a new pull request, #71:
URL: https://github.com/apache/doris-flink-connector/pull/71

   # Proposed changes
   
   Issue Number: #70 
   
   ## Problem Summary:
   
   ADD RowSerializer AND ut
   
   ## Checklist(Required)
   
   1. Does it affect the original behavior: (No)
   2. Has unit tests been added: (Yes)
   3. Has document been added or modified: (No,but will)
   4. Does it need to update dependencies: (No)
   5. Are there any changes that cannot be rolled back: (No)
   
   ## Further comments
   


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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris-flink-connector] dinggege1024 commented on pull request #71: [Enhancement] ADD RowSerializer for doris flink connector

Posted by GitBox <gi...@apache.org>.
dinggege1024 commented on PR #71:
URL: https://github.com/apache/doris-flink-connector/pull/71#issuecomment-1272276351

   @JNSimba  Hi Simba, can you review this , thx~


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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris-flink-connector] JNSimba commented on a diff in pull request #71: [Enhancement] ADD RowSerializer for doris flink connector

Posted by GitBox <gi...@apache.org>.
JNSimba commented on code in PR #71:
URL: https://github.com/apache/doris-flink-connector/pull/71#discussion_r990999551


##########
flink-doris-connector/src/main/java/org/apache/doris/flink/sink/writer/RowSerializer.java:
##########
@@ -0,0 +1,117 @@
+// 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.doris.flink.sink.writer;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.conversion.RowRowConverter;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.types.Row;
+import org.apache.flink.types.RowKind;
+import org.apache.flink.util.Preconditions;
+import java.io.IOException;
+import static org.apache.doris.flink.sink.writer.LoadConstants.CSV;
+import static org.apache.doris.flink.sink.writer.LoadConstants.JSON;
+
+/**
+ * Serializer for {@link Row}.
+ * Quick way to support RowSerializer on existing code
+ * TODO: support original Doris to Row serializer
+ */
+public class RowSerializer implements DorisRecordSerializer<Row> {
+    /**
+     * converter {@link Row} to {@link RowData}
+     */
+    private final RowRowConverter rowRowConverter;
+    private final RowDataSerializer rowDataSerializer;
+
+    private RowSerializer(String[] fieldNames, DataType[] dataTypes, String type, String fieldDelimiter,
+                          boolean enableDelete) {
+        this.rowRowConverter = RowRowConverter.create(DataTypes.ROW(dataTypes));
+        this.rowDataSerializer = RowDataSerializer.builder()
+                .setFieldNames(fieldNames)
+                .setFieldType(dataTypes)
+                .setType(type)
+                .setFieldDelimiter(fieldDelimiter)
+                .enableDelete(enableDelete)
+                .build();
+    }
+
+    @Override
+    public byte[] serialize(Row record) throws IOException{
+        RowData rowDataRecord = this.rowRowConverter.toInternal(record);
+        return this.rowDataSerializer.serialize(rowDataRecord);
+    }
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    public String parseDeleteSign(RowKind rowKind) {
+        if (RowKind.INSERT.equals(rowKind) || RowKind.UPDATE_AFTER.equals(rowKind)) {
+            return "0";
+        } else if (RowKind.DELETE.equals(rowKind) || RowKind.UPDATE_BEFORE.equals(rowKind)) {
+            return "1";
+        } else {
+            throw new IllegalArgumentException("Unrecognized row kind:" + rowKind.toString());
+        }
+    }

Review Comment:
   This function seems to be useless?



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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris-flink-connector] dinggege1024 commented on a diff in pull request #71: [Enhancement] ADD RowSerializer for doris flink connector

Posted by GitBox <gi...@apache.org>.
dinggege1024 commented on code in PR #71:
URL: https://github.com/apache/doris-flink-connector/pull/71#discussion_r991006903


##########
flink-doris-connector/src/main/java/org/apache/doris/flink/sink/writer/RowSerializer.java:
##########
@@ -0,0 +1,117 @@
+// 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.doris.flink.sink.writer;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.conversion.RowRowConverter;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.types.Row;
+import org.apache.flink.types.RowKind;
+import org.apache.flink.util.Preconditions;
+import java.io.IOException;
+import static org.apache.doris.flink.sink.writer.LoadConstants.CSV;
+import static org.apache.doris.flink.sink.writer.LoadConstants.JSON;
+
+/**
+ * Serializer for {@link Row}.
+ * Quick way to support RowSerializer on existing code
+ * TODO: support original Doris to Row serializer
+ */
+public class RowSerializer implements DorisRecordSerializer<Row> {
+    /**
+     * converter {@link Row} to {@link RowData}
+     */
+    private final RowRowConverter rowRowConverter;
+    private final RowDataSerializer rowDataSerializer;
+
+    private RowSerializer(String[] fieldNames, DataType[] dataTypes, String type, String fieldDelimiter,
+                          boolean enableDelete) {
+        this.rowRowConverter = RowRowConverter.create(DataTypes.ROW(dataTypes));
+        this.rowDataSerializer = RowDataSerializer.builder()
+                .setFieldNames(fieldNames)
+                .setFieldType(dataTypes)
+                .setType(type)
+                .setFieldDelimiter(fieldDelimiter)
+                .enableDelete(enableDelete)
+                .build();
+    }
+
+    @Override
+    public byte[] serialize(Row record) throws IOException{
+        RowData rowDataRecord = this.rowRowConverter.toInternal(record);
+        return this.rowDataSerializer.serialize(rowDataRecord);
+    }
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    public String parseDeleteSign(RowKind rowKind) {
+        if (RowKind.INSERT.equals(rowKind) || RowKind.UPDATE_AFTER.equals(rowKind)) {
+            return "0";
+        } else if (RowKind.DELETE.equals(rowKind) || RowKind.UPDATE_BEFORE.equals(rowKind)) {
+            return "1";
+        } else {
+            throw new IllegalArgumentException("Unrecognized row kind:" + rowKind.toString());
+        }
+    }

Review Comment:
   > This function seems to be useless?
   
   LGTM



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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris-flink-connector] JNSimba merged pull request #71: [Enhancement] ADD RowSerializer for doris flink connector

Posted by GitBox <gi...@apache.org>.
JNSimba merged PR #71:
URL: https://github.com/apache/doris-flink-connector/pull/71


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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris-flink-connector] JNSimba commented on a diff in pull request #71: [Enhancement] ADD RowSerializer for doris flink connector

Posted by GitBox <gi...@apache.org>.
JNSimba commented on code in PR #71:
URL: https://github.com/apache/doris-flink-connector/pull/71#discussion_r990722243


##########
flink-doris-connector/src/main/java/org/apache/doris/flink/sink/writer/RowSerializer.java:
##########
@@ -0,0 +1,166 @@
+// 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.doris.flink.sink.writer;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.doris.flink.deserialization.converter.DorisRowConverter;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.conversion.RowRowConverter;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.types.Row;
+import org.apache.flink.types.RowKind;
+import org.apache.flink.util.Preconditions;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringJoiner;
+
+import static org.apache.doris.flink.sink.writer.LoadConstants.CSV;
+import static org.apache.doris.flink.sink.writer.LoadConstants.DORIS_DELETE_SIGN;
+import static org.apache.doris.flink.sink.writer.LoadConstants.JSON;
+import static org.apache.doris.flink.sink.writer.LoadConstants.NULL_VALUE;
+
+/**
+ * Serializer for {@link Row}.
+ */
+public class RowSerializer implements DorisRecordSerializer<Row> {
+    String[] fieldNames;
+    String type;
+    private ObjectMapper objectMapper;
+    private final String fieldDelimiter;
+    private final boolean enableDelete;
+    private final DorisRowConverter rowConverter;
+    private final DataType[] dataTypes;
+
+    private RowSerializer(String[] fieldNames, DataType[] dataTypes, String type, String fieldDelimiter, boolean enableDelete) {
+        this.fieldNames = fieldNames;
+        this.dataTypes = dataTypes;
+        this.type = type;
+        this.fieldDelimiter = fieldDelimiter;
+        this.enableDelete = enableDelete;
+        if (JSON.equals(type)) {
+            objectMapper = new ObjectMapper();
+        }
+        this.rowConverter = new DorisRowConverter(dataTypes);
+    }
+
+    @Override
+    public byte[] serialize(Row record) throws IOException{
+        RowData rowDataRecord = RowRowConverter.create(DataTypes.ROW(dataTypes)).toInternal(record);
+        int maxIndex = Math.min(record.getArity(), fieldNames.length);
+        String valString;
+        if (JSON.equals(type)) {
+            valString = buildJsonString(rowDataRecord, maxIndex);
+        } else if (CSV.equals(type)) {
+            valString = buildCSVString(rowDataRecord, maxIndex);
+        } else {
+            throw new IllegalArgumentException("The type " + type + " is not supported!");
+        }
+        return valString.getBytes(StandardCharsets.UTF_8);
+    }

Review Comment:
   How about calling `RowDataSerializer.serialize(record)` directly?



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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris-flink-connector] dinggege1024 commented on a diff in pull request #71: [Enhancement] ADD RowSerializer for doris flink connector

Posted by GitBox <gi...@apache.org>.
dinggege1024 commented on code in PR #71:
URL: https://github.com/apache/doris-flink-connector/pull/71#discussion_r990977828


##########
flink-doris-connector/src/main/java/org/apache/doris/flink/sink/writer/RowSerializer.java:
##########
@@ -0,0 +1,166 @@
+// 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.doris.flink.sink.writer;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.doris.flink.deserialization.converter.DorisRowConverter;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.conversion.RowRowConverter;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.types.Row;
+import org.apache.flink.types.RowKind;
+import org.apache.flink.util.Preconditions;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringJoiner;
+
+import static org.apache.doris.flink.sink.writer.LoadConstants.CSV;
+import static org.apache.doris.flink.sink.writer.LoadConstants.DORIS_DELETE_SIGN;
+import static org.apache.doris.flink.sink.writer.LoadConstants.JSON;
+import static org.apache.doris.flink.sink.writer.LoadConstants.NULL_VALUE;
+
+/**
+ * Serializer for {@link Row}.
+ */
+public class RowSerializer implements DorisRecordSerializer<Row> {
+    String[] fieldNames;
+    String type;
+    private ObjectMapper objectMapper;
+    private final String fieldDelimiter;
+    private final boolean enableDelete;
+    private final DorisRowConverter rowConverter;
+    private final DataType[] dataTypes;
+
+    private RowSerializer(String[] fieldNames, DataType[] dataTypes, String type, String fieldDelimiter, boolean enableDelete) {
+        this.fieldNames = fieldNames;
+        this.dataTypes = dataTypes;
+        this.type = type;
+        this.fieldDelimiter = fieldDelimiter;
+        this.enableDelete = enableDelete;
+        if (JSON.equals(type)) {
+            objectMapper = new ObjectMapper();
+        }
+        this.rowConverter = new DorisRowConverter(dataTypes);
+    }
+
+    @Override
+    public byte[] serialize(Row record) throws IOException{
+        RowData rowDataRecord = RowRowConverter.create(DataTypes.ROW(dataTypes)).toInternal(record);
+        int maxIndex = Math.min(record.getArity(), fieldNames.length);
+        String valString;
+        if (JSON.equals(type)) {
+            valString = buildJsonString(rowDataRecord, maxIndex);
+        } else if (CSV.equals(type)) {
+            valString = buildCSVString(rowDataRecord, maxIndex);
+        } else {
+            throw new IllegalArgumentException("The type " + type + " is not supported!");
+        }
+        return valString.getBytes(StandardCharsets.UTF_8);
+    }

Review Comment:
   > How about calling `RowDataSerializer.serialize(record)` directly?
   
   LGTM



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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org