Guosmilesmile commented on code in PR #11662:
URL: https://github.com/apache/iceberg/pull/11662#discussion_r1876059320


##########
flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/sink/shuffle/SortKeySerializer.java:
##########
@@ -52,8 +52,32 @@ class SortKeySerializer extends TypeSerializer<SortKey> {
   private final int size;
   private final Types.NestedField[] transformedFields;
 
+  private int version = SortKeySerializerSnapshot.CURRENT_VERSION;
+
   private transient SortKey sortKey;
 
+  SortKeySerializer(Schema schema, SortOrder sortOrder, int version) {
+    this.version = version;
+    this.schema = schema;
+    this.sortOrder = sortOrder;
+    this.size = sortOrder.fields().size();
+
+    this.transformedFields = new Types.NestedField[size];
+    for (int i = 0; i < size; ++i) {
+      SortField sortField = sortOrder.fields().get(i);
+      Types.NestedField sourceField = schema.findField(sortField.sourceId());
+      Type resultType = 
sortField.transform().getResultType(sourceField.type());
+      Types.NestedField transformedField =
+          Types.NestedField.of(
+              sourceField.fieldId(),
+              sourceField.isOptional(),
+              sourceField.name(),
+              resultType,
+              sourceField.doc());
+      transformedFields[i] = transformedField;
+    }

Review Comment:
   @pvary Thank you very much for your suggestion. Since all member variables 
are final, they can only be initialized through the constructor. Most of the 
initialization for SortKeySerializer uses the latest version, and only when 
restoring the serializer do we need to pass in the version number during 
initialization. Therefore, I added a new constructor. 
   
   Another option is to remove the newly added constructor and use a setVersion 
method for injection. Because the version number is only needed for 
initialization in one place.
   
   Which approach do you think is more appropriate?



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