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.
##########
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(
Review Comment:
I added a comment explaining why `.asStructType()` is safe here. The parent
method returns either the original struct or a rebuilt struct.
##########
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.
##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkSchemaUtil.java:
##########
@@ -152,10 +152,7 @@ public static Schema convert(Schema baseSchema,
TableSchema flinkSchema) {
Types.StructType struct = convert(flinkSchema).asStruct();
// reassign ids to match the base schema
Schema schema = TypeUtil.reassignIds(new Schema(struct.fields()),
baseSchema);
- // reassign doc to match the base schema
- schema = TypeUtil.reassignDoc(schema, baseSchema);
Review Comment:
I added an assertion for both conversion overloads. The projected schema
starts without the nested field description, and both cases recover it from the
Iceberg schema. Both fail if doc restoration is removed.
##########
flink/v2.3/flink/src/test/java/org/apache/iceberg/flink/source/TestFlinkInitialDefaults.java:
##########
@@ -0,0 +1,88 @@
+/*
Review Comment:
I added ORC cases for both legacy and FLIP-27 sources. They assert the
unsupported-default exception and passed locally. On the pre-PR baseline, the
same query returned without throwing.
--
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]