TatvagnaTandel commented on code in PR #19239:
URL: https://github.com/apache/iceberg/pull/19239#discussion_r4757348426


##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkFixupTypes.java:
##########
@@ -24,21 +24,40 @@
 import org.apache.iceberg.types.TypeUtil;
 import org.apache.iceberg.types.Types;
 
-/**
- * The uuid and fixed are converted to the same Flink type. Conversion back 
can produce only one,
- * which may not be correct.
- */
+/** Restores Iceberg UUID types and field metadata after a Flink schema round 
trip. */
 class FlinkFixupTypes extends FixupTypes {
+  private final Schema referenceSchema;
 
   private FlinkFixupTypes(Schema referenceSchema) {
     super(referenceSchema);
+    this.referenceSchema = referenceSchema;
   }
 
   static Schema fixup(Schema schema, Schema referenceSchema) {
     return new Schema(
         TypeUtil.visit(schema, new 
FlinkFixupTypes(referenceSchema)).asStructType().fields());
   }
 
+  @Override
+  public Type struct(Types.StructType struct, Iterable<Type> fieldTypes) {
+    Types.StructType fixedStruct = super.struct(struct, 
fieldTypes).asStructType();
+    return Types.StructType.of(
+        
fixedStruct.fields().stream().map(this::restoreFieldMetadata).toList());
+  }
+
+  private Types.NestedField restoreFieldMetadata(Types.NestedField field) {
+    Types.NestedField referenceField = 
referenceSchema.findField(field.fieldId());

Review Comment:
   Both conversion paths call `TypeUtil.reassignIds` against the base schema 
before restoring metadata. An unknown field is rejected at that step, so I kept 
the lookup as is. The existing missing field test passed.



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