ewoodbury opened a new pull request, #3843:
URL: https://github.com/apache/iceberg-rust/pull/3843
## Which issue does this PR close?
- Closes #3261. Remaining work is tracked in #3842.
## What changes are included in this PR?
In a v3 table, a field added to a schema can have an `initial-default`: the
value that rows written before the field existed should read as. Take the
spec's example: if `point.y` is added with default 0, an old row `{"x": 3}`
reads as `{"x": 3, "y": 0}`, and a null `point` stays null. iceberg-rust did
this for top-level fields, but nested fields failed with `initial-default of
nested field ... is not supported`. This PR applies the default to nested
fields too, including structs inside lists and maps.
Top-level and nested fields now share one helper for the value of a missing
field. A required nested field without a default now reports `Missing required
field`, as the top-level path and iceberg-java do.
Two related cases now fail with `FeatureUnsupported` instead of returning
wrong results:
- Filters on these fields. `main` treats the missing field as null, so
`WHERE point.y = 0` returns no rows. The right answer depends on which rows
have `point`, and the row filter can't see that. The same goes for equality
deletes, and for nested fields filled from an identity partition value. If the
file doesn't have `point` at all, `point.y` is null and filters work as before.
Filters on nested columns that a file does store already fail today; once #2906
fixes that, this is the remaining gap.
- A struct that no column can track. If none of a struct's columns can be
read (for example, its only column is a `uint64`), the reader can't tell which
rows have the struct, so it can't apply the default. iceberg-java fails here
too, in
[`ParquetValueReaders.presenceColumn`](https://github.com/apache/iceberg/blob/apache-iceberg-1.12.0/parquet/src/main/java/org/apache/iceberg/parquet/ParquetValueReaders.java#L293-L311).
Before, the struct read as null.
Non-null defaults on struct, list and map fields, such as the spec's `{}`,
are still unsupported (also in #3842). iceberg-java rejects them when it builds
a schema.
Differences from iceberg-java 1.12.0:
- Java evaluates the filters above; this PR errors.
- For a file without field ids read by position, Java fails to find a column
to track the struct; this PR applies the default.
- For a required struct whose columns can't be read, Java returns the
default; this PR errors, as required structs already did in #3438.
## Are these changes tested?
Yes. I compared results with iceberg-java 1.12.0 on Java-written v3 tables:
`point` with `x` kept and dropped, `outer.inner.y`, a missing nested struct,
and lists and maps of structs. Rows match, and Java's `point.y = 0` returns the
rows where `point` is present.
- `test_nested_initial_default_where_struct_is_present` reads the `point`
example through `ArrowReader` with field ids, name mapping and position
fallback, each with `x` kept and dropped. Filtering on `point.y` fails in each
case. On `main`, the reads fail and the filtered read returns no rows.
- `promote_nested_field_applies_initial_default` covers optional and
required children, null parent rows, and structs in a list and a map.
- `identity_partition_fills_missing_nested_field` now also checks that the
partition value wins over the default.
- `test_residual_for_nested_field_with_value_under_stored_struct_errors`
covers the filter check two structs deep.
- `test_projection_mask_reads_one_presence_leaf` and
`test_arrow_projection_mask_variant_nested_in_struct` cover the presence check,
including a projected variant.
I broke each part of the change in turn and confirmed a test fails each
time. Local checks: `cargo test -p iceberg --lib --all-features`, clippy with
`-D warnings`, `cargo fmt --check`, rustdoc with `-D warnings`, `cargo
machete`, the license check and `typos`.
## AI Disclosure
Drafted with AI assistance (Grok and Claude). I fully own the fix strategy
and its correctness. The parts most worth a close look are the two new
`FeatureUnsupported` errors and the differences from Java above.
--
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]