Skip to content

fix(reader): read list views as lists - #3467

Open
comphead wants to merge 3 commits into
apache:mainfrom
comphead:fix-3393-list-view
Open

comphead wants to merge 3 commits into
apache:mainfrom
comphead:fix-3393-list-view

Conversation

@comphead

@comphead comphead commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Which issue does this PR close?

What changes are included in this PR?

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 the reader still can't handle them. arrow_schema_to_schema has no list view arm, and RecordBatchTransformer can't promote a list view to List. So projecting a list view column fails, or reads it as NULL through a name mapping.

  • coerce_fixed_size_lists from fix(arrow): promote FixedSizeList file columns to List #3629 is now coerce_list_layouts. It also rewrites ListView to List and LargeListView to LargeList in the hint, before name mapping, fallback IDs, and INT96 coercion.
  • A list view column now comes back as List, like any Iceberg list.
  • PresenceWalk no longer sees a list view, so its list view arm folds into the List arm. The two presence cases that pinned the old arm are removed, and the leaf-counting case also covers LargeListView.
  • apply_name_mapping_to_field asserts 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_columns writes the file from the issue, a list_view<struct<a, b>> followed by an int, and reads it with field IDs. It also writes it as a LargeListView without IDs and reads that through a name mapping and through fallback IDs.
  • test_coerce_list_layouts replaces 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.

@comphead
comphead marked this pull request as ready for review October 15, 2026 23:20
Copilot AI balanced review requested due to automatic review settings October 15, 2026 23:20
@comphead comphead added the bug Something isn't working label Oct 15, 2026
@comphead
comphead requested a review from mbutrovich October 15, 2026 23:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 ewoodbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kevinjqliu

Copy link
Copy Markdown
Contributor

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 filter_leaves. Thanks for reporting it upstream (apache/arrow-rs#11612), looks like it's already fixed on main in apache/arrow-rs#11657, just not released yet.

im a bit worried about the maintenance burden of working around it here, since we'd be patching arrow types one at a time (FixedSizeList hits a similar issue). And list views in parquet files seem pretty rare.

What do you think about picking up the fix from upstream arrow-rs/parquet-rs instead, and keeping #3393 open until then? 😄

@laskoviymishka laskoviymishka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 33c4193. The file without IDs is a LargeListView, read through a name mapping and through fallback IDs. Fallback IDs are top-level only, so that run reads the struct's fields as null (#3437) and checks the list offsets and id. Each run fails if its branch gets the original hint.

}
// `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`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in fe3120a. test_coerce_list_layouts replaces this test and main's FixedSizeList one, and every field carries an ID.

@mbutrovich

Copy link
Copy Markdown
Collaborator

What do you think about picking up the fix from upstream arrow-rs/parquet-rs instead, and keeping #3393 open until then? 😄

Agreed, especially since I think it'll make the 60.1.0 maintenance release this week. apache/arrow-rs#10525

@comphead

Copy link
Copy Markdown
Collaborator Author

okie, lets wait for 60.1.0 and btw we already have Arrow 60 migration opened in #3257

@mbutrovich

Copy link
Copy Markdown
Collaborator

What do you think about picking up the fix from upstream arrow-rs/parquet-rs instead, and keeping #3393 open until then?

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 arrow-schema 60.1.0 since #3257. The reproduction from #3393 still fails on main at 7cf825fcf. I ran it with a ListView and a LargeListView column, each read three ways. The results were the same for both types:

File Project id Project lv, id Project lv
Field IDs at every level correct error error
No field IDs, name mapping correct lv all NULL error
No field IDs, fallback IDs correct error error

The upstream fix only repaired the leaf shift, so projecting id alone now works. With field IDs, the mask builder now keeps the list view and fails converting it in arrow_schema_to_schema (Cannot visit Arrow data type: ListView(...)). The fallback and name-mapping errors come from RecordBatchTransformer (cannot promote ListView(...) to List(...)). The name-mapped lv, id case returns wrong results without an error.

Since #3629 we rewrite FixedSizeList hints to List in coerce_fixed_size_lists, which follows this PR's design. That answers the FixedSizeList maintenance concern: both types can go through one rewrite. When I added ListView and LargeListView arms to that function, all 18 cases read correctly and the arrow:: tests passed.

The rewrite also keeps the reader correct for a downstream crate that resolves arrow-schema 60.0.0, which our arrow-schema = "60.0" requirement allows.

@mbutrovich mbutrovich left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +535 to +591
/// 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))
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@comphead

Copy link
Copy Markdown
Collaborator Author

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.
@comphead comphead changed the title fix(reader): read list views as lists so projection can select their leaves fix(reader): read list views as lists Nov 21, 2026
@comphead

Copy link
Copy Markdown
Collaborator Author

Rebased onto main. The first commit folds the list view arms into the FixedSizeList rewrite from #3629, and the second addresses the October comments. Folding the PresenceWalk arm removed two list view cases from the presence test added in #3438, since they pinned the removed arm.

@comphead

Copy link
Copy Markdown
Collaborator Author

@mbutrovich please take another look

@mbutrovich mbutrovich left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @comphead for the rebase and for folding this into the FixedSizeList rewrite. One request on the name-mapping guard below.

@comphead

Copy link
Copy Markdown
Collaborator Author

Thanks @comphead for the rebase and for folding this into the FixedSizeList rewrite. One request on the name-mapping guard below.

Thanks @mbutrovich its done!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working datafusion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ListView columns read as NULL and shift later columns to the wrong Parquet leaf

6 participants