TatvagnaTandel commented on code in PR #19239:
URL: https://github.com/apache/iceberg/pull/19239#discussion_r4757349448
##########
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());
+ Types.NestedField.Builder builder =
Types.NestedField.from(field).withDoc(referenceField.doc());
+ if (field.type().isPrimitiveType()
Review Comment:
I added a comment explaining the primitive guard. Iceberg rejects non null
default literals for nested types.
--
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]