Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The focused change preserves metadata and fits existing reader handling, with no blocking issues identified; tests were not executed.
0 open findings
What changed in this PR
Fixes #3393 by normalizing Arrow list views before projection, preventing missing list values and incorrect selection of later columns.
Changes:
- Recursively converts list views to lists while preserving metadata.
- Applies normalization before field-ID handling and timestamp coercion.
- Adds schema-conversion and reader regression tests.
| File | Description |
|---|---|
crates/iceberg/src/arrow/reader/projection.rs |
Adds recursive normalization and unit coverage. |
crates/iceberg/src/arrow/reader/pipeline.rs |
Integrates normalization and adds a reader regression test. |
crates/iceberg/src/arrow/reader/mod.rs |
Makes the helper available within the reader module. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
ewoodbury
left a comment
There was a problem hiding this comment.
Chiming in with a short review, fix looks good. I checked the main correctness claims locally against a8df712, and they all line up:
- On main, projecting only id after a list_view<struct<a, b>> returns all NULLs, and projecting both columns errors. Both read correctly here.
- test_read_list_view_columns fails with the rewrite disabled. Reader tests, clippy, fmt and rustdoc are clean, and the branch merges cleanly with main.
- These also read correctly here (all broken on main): LargeListView, a row filter on the column after the list view, and files without field IDs through name mapping (including a pyarrow-written file) and through position fallback.
- iceberg-java 1.12.0 reads the same file identically.
- The INT96 claim holds: main reads 0 for a 3333-01-01 value next to a list view, and this branch reads it correctly.
Rewriting once in the schema hint is the right approach since every later step sees a plain List, with no public API change.
As a nit, I left one test suggestion inline regarding the name mapping branch for imported files, just to pin that fix.
| Arc::clone(arrow_metadata.schema()), | ||
| name_mapping, | ||
| )? | ||
| apply_name_mapping_to_arrow_schema(Arc::clone(file_schema), name_mapping)? |
There was a problem hiding this comment.
Imported files are probably the most common source of list views. iceberg-rust's writers emit List, and a pyarrow pa.list_view(...) file has no field IDs, so it is read through this name-mapping branch.
This branch doesn't seem to be covered by the new tests yet. If I pass the uncoerced arrow_metadata.schema() here, both tests still pass. Meanwhile, a pyarrow-written lv list_view<struct<a, b>>, id file read with a name mapping goes back to returning id as all NULLs, and to erroring when lv is also projected.
I think it would be worth having test_read_list_view_columns also read the file through a name mapping, for example by writing the same batch without the field-ID metadata and setting with_name_mapping on the task. Not blocking.
There was a problem hiding this comment.
Done in 33c4193. test_read_list_view_columns also writes the file without field IDs and reads it through a name mapping. Passing the original hint to apply_name_mapping_to_arrow_schema now trips the new debug_assert!, and with the assert removed, lv reads as all NULL.
|
Thanks for the PR! I'm not sure if this should be fixed in the iceberg code, it seems like a bug in arrow-rs related to im a bit worried about the maintenance burden of working around it here, since we'd be patching arrow types one at a time ( What do you think about picking up the fix from upstream arrow-rs/parquet-rs instead, and keeping #3393 open until then? 😄 |
laskoviymishka
left a comment
There was a problem hiding this comment.
Approving. Fixing this on the ARROW:schema hint, before the ID branches, means INT96 and the row-number install get the fix for free. Since Parquet has no list-view type, the rewrite produces the same List shape schema_to_arrow already gives us.
The inline comments are follow-ups, not blockers. +1 to @ewoodbury's name-mapping test, and I'd pin position fallback the same way, since leaf-position ID assignment is exactly what this bug broke. The other two are small hardening. Landing them here or in a follow-up PR are both fine with me.
I'll leave this open for a day or two in case anyone else wants a look.
| // otherwise, use applyNameMapping() followed by pruneColumns() when configured, or | ||
| // addFallbackIds() followed by pruneColumnsFallback() for position-based fallback. | ||
| // The fast path returns early without materializing an owned schema. | ||
| let without_list_views = coerce_list_views(arrow_metadata.schema()); |
There was a problem hiding this comment.
The comment block above only covers the field-ID strategy, but this step now runs before all of it and changes the emitted type. I'd call that out here:
| let without_list_views = coerce_list_views(arrow_metadata.schema()); | |
| // Rewrite list views to lists first: `filter_leaves` treats them as leaves (#3393), | |
| // so everything below, including the emitted batches, sees `List`/`LargeList`. | |
| let without_list_views = coerce_list_views(arrow_metadata.schema()); |
That also explains the without_list_views.is_some() arm further down. Callers who wrote ListView now get List back. That's the right contract for an Iceberg list, but it's worth a line in the PR description too.
There was a problem hiding this comment.
Done in fe3120a, without the filter_leaves reason, since 60.1.0 fixed that part. The PR description now says a list view column comes back as List.
| apply_name_mapping_to_arrow_schema(Arc::clone(file_schema), name_mapping)? | ||
| } else { | ||
| add_fallback_field_ids_to_arrow_schema(arrow_metadata.schema()) | ||
| add_fallback_field_ids_to_arrow_schema(file_schema) |
There was a problem hiding this comment.
This is the position-fallback counterpart to @ewoodbury's name-mapping note. The test file carries field IDs, so nothing reaches this line. Fallback IDs are assigned by leaf position, and leaf position is exactly what the list-view bug threw off. Writing the batch without IDs and reading it twice, with and without a name mapping, would pin both branches in one test. Making lv a LargeListView in one of those runs would also cover that arm end to end. Fine as a follow-up.
There was a problem hiding this comment.
| } | ||
| // `Fields::filter_leaves` treats `ListView` and `LargeListView` as leaves, so projection | ||
| // cannot select their elements even with IDs. | ||
| // List views were already rewritten to lists by `coerce_list_views`. |
There was a problem hiding this comment.
This comment is now a precondition on every caller of apply_name_mapping_to_arrow_schema, but the other => other.clone() arm still lets a list view through silently. I'd state the precondition in that function's doc and add debug_assert!(!matches!(other, DataType::ListView(_) | DataType::LargeListView(_))) here. Then a new call site that skips coerce_list_views fails in tests instead of quietly bringing back the all-NULL projection.
There was a problem hiding this comment.
Done in 33c4193. The arrow_schema argument doc states the precondition, and the other arm has the debug_assert!.
| let id = HashMap::from([(PARQUET_FIELD_ID_META_KEY.to_string(), "9".to_string())]); | ||
| let int = |name: &str| Field::new(name, DataType::Int32, true); | ||
| let element = |data_type| Arc::new(Field::new("element", data_type, true)); | ||
| let ints = element(DataType::Int32); |
There was a problem hiding this comment.
Only nested carries an ID, so this test would still pass if the rewrite dropped metadata on a list element or on the fields inside a struct. I'd give ints and the fields inside s IDs too, since projection selects by exactly those fields.
There was a problem hiding this comment.
Done in fe3120a. test_coerce_list_layouts replaces this test and main's FixedSizeList one, and every field carries an ID.
Agreed, especially since I think it'll make the 60.1.0 maintenance release this week. apache/arrow-rs#10525 |
|
okie, lets wait for 60.1.0 and btw we already have Arrow 60 migration opened in #3257 |
I agreed with this earlier, and I'd like to reopen it. arrow 60.1.0 shipped apache/arrow-rs#11657, and main has locked
The upstream fix only repaired the leaf shift, so projecting Since #3629 we rewrite The rewrite also keeps the reader correct for a downstream crate that resolves |
mbutrovich
left a comment
There was a problem hiding this comment.
Thanks @comphead, and sorry for steering this toward waiting on arrow-rs. 60.1.0 is on main now, but it doesn't fix #3393, so I think we should take this PR after all. Could you rebase onto main? The comment below suggests folding the list view arms into the FixedSizeList rewrite that main now has. @kevinjqliu, does one shared rewrite address your maintenance concern?
Once the rewrite runs on main, PresenceWalk::visit no longer sees a list view, because its only caller passes record_batch_stream_builder.schema(), which parquet-rs builds from the rewritten hint. Could the rebase fold the list view arm in projection.rs#L719-L727 into the List arm, and update the comments that point at this PR's rewrite in projection.rs#L905-L906 and pipeline.rs#L702-L703? Otherwise those lines describe a path the reader can't reach.
| /// Rewrites every `ListView` and `LargeListView` in `arrow_schema` to `List` and `LargeList`, | ||
| /// because `Fields::filter_leaves`, which the projection relies on, treats list views as leaves | ||
| /// (#3393). Returns `None` if there are none. | ||
| pub(super) fn coerce_list_views(arrow_schema: &ArrowSchemaRef) -> Option<ArrowSchemaRef> { | ||
| let fields = coerce_list_views_in_fields(arrow_schema.fields())?; | ||
| Some(Arc::new(ArrowSchema::new_with_metadata( | ||
| fields, | ||
| arrow_schema.metadata().clone(), | ||
| ))) | ||
| } | ||
|
|
||
| /// Returns `fields` with their list views rewritten, or `None` if they have none. Unchanged | ||
| /// fields are shared, and nothing is allocated before the first change. | ||
| fn coerce_list_views_in_fields(fields: &Fields) -> Option<Fields> { | ||
| let (index, first) = fields | ||
| .iter() | ||
| .enumerate() | ||
| .find_map(|(index, field)| Some((index, coerce_list_views_in_field(field)?)))?; | ||
| let rest = fields | ||
| .iter() | ||
| .skip(index + 1) | ||
| .map(coerce_list_views_or_share); | ||
| Some( | ||
| fields | ||
| .iter() | ||
| .take(index) | ||
| .cloned() | ||
| .chain([first]) | ||
| .chain(rest) | ||
| .collect(), | ||
| ) | ||
| } | ||
|
|
||
| /// Returns `field` with its list views rewritten, or `None` if it has none. | ||
| fn coerce_list_views_in_field(field: &FieldRef) -> Option<FieldRef> { | ||
| let data_type = match field.data_type() { | ||
| DataType::ListView(element) => DataType::List(coerce_list_views_or_share(element)), | ||
| DataType::LargeListView(element) => { | ||
| DataType::LargeList(coerce_list_views_or_share(element)) | ||
| } | ||
| DataType::List(element) => DataType::List(coerce_list_views_in_field(element)?), | ||
| DataType::LargeList(element) => DataType::LargeList(coerce_list_views_in_field(element)?), | ||
| DataType::FixedSizeList(element, size) => { | ||
| DataType::FixedSizeList(coerce_list_views_in_field(element)?, *size) | ||
| } | ||
| DataType::Map(entries, sorted) => { | ||
| DataType::Map(coerce_list_views_in_field(entries)?, *sorted) | ||
| } | ||
| DataType::Struct(fields) => DataType::Struct(coerce_list_views_in_fields(fields)?), | ||
| _ => return None, | ||
| }; | ||
| Some(Arc::new(field.as_ref().clone().with_data_type(data_type))) | ||
| } | ||
|
|
||
| fn coerce_list_views_or_share(field: &FieldRef) -> FieldRef { | ||
| coerce_list_views_in_field(field).unwrap_or_else(|| Arc::clone(field)) | ||
| } |
There was a problem hiding this comment.
Main now has coerce_fixed_size_lists from #3629, which has the same shape as coerce_list_views and runs at the same spot in the pipeline. Could we add the list view arms to that function, and give it a name that covers both, instead of adding a second rewrite pass? These arms are all it needs:
DataType::ListView(element) => DataType::List(coerce_fixed_size_lists_or_share(element)),
DataType::LargeListView(element) => {
DataType::LargeList(coerce_fixed_size_lists_or_share(element))
}The reason in the doc comment also changed. arrow-schema 60.1.0 fixed Fields::filter_leaves in apache/arrow-rs#11657. The rewrite is still needed because arrow_schema_to_schema and RecordBatchTransformer can't convert a list view. Could the doc comment and the PR description say that instead?
There was a problem hiding this comment.
Done in fe3120a. The arms are in the FixedSizeList rewrite, renamed coerce_list_layouts after Arrow's list layouts, and its doc comment gives the reason after 60.1.0. PresenceWalk::visit folds its list view arm into the List arm without the pick flag, and the comments that pointed at this PR are updated.
|
THanks @mbutrovich for double checking, I'm rebasing the PR and checking what is still left after 60.1.0 has applied |
parquet-rs reads a Parquet LIST as ListView or LargeListView when the file's embedded Arrow schema says so. arrow-schema 60.1.0 made Fields::filter_leaves descend into list views (apache/arrow-rs@a8306d6), but Iceberg still cannot read them. arrow_schema_to_schema has no list view arm, and RecordBatchTransformer cannot promote a list view to List. Add ListView and LargeListView arms to the FixedSizeList hint rewrite from apache#3629, and rename it to coerce_list_layouts. PresenceWalk no longer sees a list view, so its list view arm folds into the List arm. Closes apache#3393
- test_read_list_view_columns also writes the file without field IDs, as a LargeListView, and reads it through a name mapping and through fallback IDs. - test_coerce_list_layouts gives every field an ID and nests a list view under a large list view. - The presence walk case also counts leaves through a LargeListView. - apply_name_mapping_to_field asserts in debug builds that no list view reaches it, and the argument doc states the precondition.
a8df712 to
33c4193
Compare
|
@mbutrovich please take another look |
mbutrovich
left a comment
There was a problem hiding this comment.
Thanks @comphead for the rebase and for folding this into the FixedSizeList rewrite. One request on the name-mapping guard below.
Co-authored-by: Matt Butrovich <[email protected]>
Thanks @mbutrovich its done! |
Which issue does this PR close?
What changes are included in this PR?
parquet-rs reads a Parquet LIST as
ListVieworLargeListViewwhen the file's embedded Arrow schema says so. arrow-schema 60.1.0 madeFields::filter_leavesdescend into list views (apache/arrow-rs@a8306d6), but the reader still can't handle them.arrow_schema_to_schemahas no list view arm, andRecordBatchTransformercan't promote a list view toList. So projecting a list view column fails, or reads it as NULL through a name mapping.coerce_fixed_size_listsfrom fix(arrow): promote FixedSizeList file columns to List #3629 is nowcoerce_list_layouts. It also rewritesListViewtoListandLargeListViewtoLargeListin the hint, before name mapping, fallback IDs, and INT96 coercion.List, like any Iceberglist.PresenceWalkno longer sees a list view, so its list view arm folds into theListarm. The two presence cases that pinned the old arm are removed, and the leaf-counting case also coversLargeListView.apply_name_mapping_to_fieldasserts in debug builds that no list view reaches it.INT96 coercion now also runs on files with a list view. Its visitor failed on the list view, so the coercion was skipped. That follows from the code, and ewoodbury confirmed it on the earlier revision. The rewrite also keeps the reader correct with arrow-schema 60.0.0, which our
arrow-schema = "60.0"requirement allows.Are these changes tested?
Yes.
test_read_list_view_columnswrites the file from the issue, alist_view<struct<a, b>>followed by anint, and reads it with field IDs. It also writes it as aLargeListViewwithout IDs and reads that through a name mapping and through fallback IDs.test_coerce_list_layoutsreplaces the two schema-level tests. It covers every arm of the rewrite, with a field ID on every field.As a spot check, I broke the change in 25 ways, one at a time, from dropping each arm of the rewrite to handing one pipeline branch the original hint. Each mutation failed at least one test.
AI Disclosure
Drafted with Claude Code.