wombatu-kun commented on code in PR #16439:
URL: https://github.com/apache/iceberg/pull/16439#discussion_r3360514090
##########
core/src/main/java/org/apache/iceberg/StatsUtil.java:
##########
@@ -171,14 +171,14 @@ public Types.NestedField struct(Types.StructType struct,
List<Types.NestedField>
@Override
public Types.NestedField field(Types.NestedField field, Types.NestedField
fieldResult) {
- if (field.type().isNestedType() || field.type().isVariantType()) {
+ if (field.type().isNestedType()) {
return null;
}
int fieldId = StatsUtil.statsFieldIdForField(field.fieldId());
if (fieldId >= 0) {
Types.StructType structType = FieldStatistic.fieldStatsFor(field,
fieldId);
- return optional(fieldId, Integer.toString(field.fieldId()),
structType);
+ return optional(fieldId, field.name(), structType);
Review Comment:
`field.name()` is the field's simple (local) name, which is not unique
across nested fields. Two leaf columns that share a simple name in different
structs both produce a `content_stats` child with that name, which is an
invalid struct: name-indexing throws `ValidationException: Invalid schema:
multiple fields for name ...` (IndexByName.java:200), and `StructType`/Avro
also reject duplicate field names. The previous field-id string was always
unique. spec.md:800 recommends the full field name; since `contentStatsFor` has
the `Schema`, consider `schema.findColumnName(field.fieldId())` here instead.
Failing test against this branch:
```java
@Test
public void contentStatsChildNamesAreUnique() {
Schema schema =
new Schema(
required(1, "a", Types.StructType.of(required(2, "x",
Types.IntegerType.get()))),
required(3, "b", Types.StructType.of(required(4, "x",
Types.IntegerType.get()))));
Types.StructType contentStats =
StatsUtil.contentStatsFor(schema).type().asStructType();
// content_stats child names = [x, x]
assertThat(contentStats.fields().stream().map(Types.NestedField::name).toList())
.doesNotHaveDuplicates();
// and new Schema(contentStats.fields()) throws:
// ValidationException: Invalid schema: multiple fields for name
x.lower_bound: 10401 and 10801
}
```
--
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]