utafrali commented on code in PR #19239:
URL: https://github.com/apache/iceberg/pull/19239#discussion_r4757183708
##########
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:
`referenceSchema.findField(field.fieldId())` returns `null` when the field
ID is absent from the base schema. The subsequent `.doc()` call on line 50 will
throw a NullPointerException in that case. While `TypeUtil.reassignIds` should
keep IDs aligned, a projected schema subset can expose this if IDs drift. Add a
guard:
```java
private Types.NestedField restoreFieldMetadata(Types.NestedField field) {
Types.NestedField referenceField =
referenceSchema.findField(field.fieldId());
if (referenceField == null) {
return field;
}
// ... rest of method
}
```
##########
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:
The cast `super.struct(struct, fieldTypes).asStructType()` is unchecked.
`FixupTypes.struct()` returns a `Type`, and while in practice it always returns
a `StructType`, calling `.asStructType()` without a guard will throw
`ClassCastException` if the parent ever returns something unexpected. Either
add an `instanceof` check or inline a comment explaining why the cast is
guaranteed safe, so future readers don't silently widen this.
##########
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:
The two `TypeUtil.reassignDoc` calls were removed here and in the
`ResolvedSchema` overload, with doc restoration now delegated to
`FlinkFixupTypes.restoreFieldMetadata`. That method only iterates fields at the
top-level struct; `reassignDoc` previously walked the whole tree recursively.
If a projected schema includes nested structs whose fields carry Iceberg doc
strings, those docs will now be silently dropped. Please add a test that
round-trips a schema with a documented nested field, or confirm that
`TypeVisitor` recursion in `FlinkFixupTypes` covers nested structs via repeated
`struct()` calls.
##########
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:
Defaults are only restored for primitive types, which is a reasonable
starting point, but the condition silently drops defaults for any non-primitive
field without explanation. Add a short comment so reviewers and future
contributors know this is a deliberate scope boundary rather than an oversight:
```java
// Default restoration is limited to primitive types; struct/list/map
defaults
// are not yet supported by the Iceberg reader layer.
if (field.type().isPrimitiveType() && ...) {
```
##########
flink/v2.3/flink/src/test/java/org/apache/iceberg/flink/source/TestFlinkInitialDefaults.java:
##########
@@ -0,0 +1,88 @@
+/*
Review Comment:
The integration test covers Parquet and Avro but the PR description
explicitly states that ORC raises an unsupported-default error on a projected
field. That error path is verified only in a local reproduction and is absent
from this test class. Even a small negative test that asserts the exception is
thrown would prevent a future regression where the error silently disappears
(or is swallowed) without anyone noticing.
--
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]