hililiwei commented on code in PR #4904:
URL: https://github.com/apache/iceberg/pull/4904#discussion_r926540313


##########
flink/v1.15/flink/src/main/java/org/apache/iceberg/flink/sink/v2/FilesCommittableSerializer.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.iceberg.flink.sink.v2;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import org.apache.flink.core.io.SimpleVersionedSerializer;
+import org.apache.flink.core.memory.DataInputDeserializer;
+import org.apache.flink.core.memory.DataOutputViewStreamWrapper;
+import org.apache.flink.util.InstantiationUtil;
+import org.apache.iceberg.io.WriteResult;
+
+class FilesCommittableSerializer implements 
SimpleVersionedSerializer<FilesCommittable> {
+  private static final int SERIALIZER_VERSION = 1;
+
+  @Override
+  public int getVersion() {
+    return SERIALIZER_VERSION;
+  }
+
+  @Override
+  public byte[] serialize(FilesCommittable committable) throws IOException {
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    DataOutputViewStreamWrapper view = new DataOutputViewStreamWrapper(out);
+    byte[] serialize = 
writeResultSerializer.serialize(committable.committable());
+    view.writeUTF(committable.jobID());
+    view.writeLong(committable.checkpointId());
+    view.writeInt(committable.subtaskId());
+    view.writeInt(serialize.length);
+    view.write(serialize);
+    return out.toByteArray();
+  }
+
+  @Override
+  public FilesCommittable deserialize(int version, byte[] serialized) throws 
IOException {
+    switch (version) {
+      case SERIALIZER_VERSION:
+        DataInputDeserializer view = new DataInputDeserializer(serialized);
+        String jobID = view.readUTF();
+        long checkpointId = view.readLong();
+        int subtaskId = view.readInt();
+        int len = view.readInt();
+        byte[] buf = new byte[len];
+        view.read(buf);
+        WriteResult writeResult = 
writeResultSerializer.deserialize(writeResultSerializer.getVersion(), buf);
+        return new FilesCommittable(writeResult, jobID, checkpointId, 
subtaskId);
+      default:
+        throw new IOException("Unrecognized version or corrupt state: " + 
version);
+    }
+  }
+
+  private final SimpleVersionedSerializer<WriteResult> writeResultSerializer =
+      new SimpleVersionedSerializer<WriteResult>() {
+        @Override
+        public int getVersion() {
+          return 1;

Review Comment:
   rename to `VERSION_1`. 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to