mxm commented on code in PR #12996:
URL: https://github.com/apache/iceberg/pull/12996#discussion_r2081893582


##########
flink/v2.0/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/DynamicRecordInternalSerializer.java:
##########
@@ -0,0 +1,292 @@
+/*
+ * 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.dynamic;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility;
+import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.memory.DataInputView;
+import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.runtime.typeutils.RowDataSerializer;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.PartitionSpecParser;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.SchemaParser;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+
+@Internal
+class DynamicRecordInternalSerializer extends 
TypeSerializer<DynamicRecordInternal> {
+
+  private static final long serialVersionUID = 1L;
+
+  private final RowDataSerializerCache serializerCache;
+  private final boolean writeSchemaAndSpec;
+
+  DynamicRecordInternalSerializer(
+      RowDataSerializerCache serializerCache, boolean writeSchemaAndSpec) {
+    this.serializerCache = serializerCache;
+    this.writeSchemaAndSpec = writeSchemaAndSpec;
+  }
+
+  @Override
+  public TypeSerializer<DynamicRecordInternal> duplicate() {
+    return new DynamicRecordInternalSerializer(
+        new RowDataSerializerCache(serializerCache.catalogLoader(), 
serializerCache.maximumSize()),
+        writeSchemaAndSpec);
+  }
+
+  @Override
+  public DynamicRecordInternal createInstance() {
+    return new DynamicRecordInternal();
+  }
+
+  @Override
+  public void serialize(DynamicRecordInternal toSerialize, DataOutputView 
dataOutputView)
+      throws IOException {
+    dataOutputView.writeUTF(toSerialize.tableName());
+    dataOutputView.writeUTF(toSerialize.branch());
+    if (writeSchemaAndSpec) {
+      dataOutputView.writeUTF(SchemaParser.toJson(toSerialize.schema()));
+      dataOutputView.writeUTF(PartitionSpecParser.toJson(toSerialize.spec()));
+    } else {
+      dataOutputView.writeInt(toSerialize.schema().schemaId());
+      dataOutputView.writeInt(toSerialize.spec().specId());
+    }
+    dataOutputView.writeInt(toSerialize.writerKey());
+    final RowDataSerializer rowDataSerializer;
+    if (writeSchemaAndSpec) {
+      rowDataSerializer =
+          serializerCache.serializer(
+              toSerialize.tableName(), toSerialize.schema(), 
toSerialize.spec());
+    } else {
+      // Check that the schema id can be resolved. Not strictly necessary for 
serialization.
+      Tuple3<RowDataSerializer, Schema, PartitionSpec> serializer =
+          serializerCache.serializerWithSchemaAndSpec(
+              toSerialize.tableName(),
+              toSerialize.schema().schemaId(),
+              toSerialize.spec().specId());

Review Comment:
   This is basically a sanity-test, to test that looking up the serializer by 
id on the remote side will work. The remote side won't have the schema 
available, because it is not written in this branch. If there are any issues, 
we will know about them on the sender side, as opposed on the receiving side.
   
   I've added a JavaDoc which should clarify things.



-- 
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: issues-unsubscr...@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to