Skip to content

Preserve null lists when projecting a list of structs - #4129

Open
krishan711 wants to merge 4 commits into
apache:mainfrom
krishan711:preserve-null-list-of-structs
Open

krishan711 wants to merge 4 commits into
apache:mainfrom
krishan711:preserve-null-list-of-structs

Conversation

@krishan711

@krishan711 krishan711 commented Oct 21, 2026 •

Copy link
Copy Markdown

Rationale for this change

ArrowProjectionVisitor.list rebuilds a list of structs with LargeListArray.from_arrays(list_array.offsets, value_array). That drops the validity mask, so a null list is written as an empty list. This is the list version of #4118, which fixed the same thing for maps.

The fix passes mask=list_array.is_null().

Are these changes tested?

Yes. test__to_requested_schema_null_list_of_structs covers a full batch and a sliced one. It fails without the fix.

test_null_list_and_map asserted [[], [{"test": 1}]] for col_list_with_struct, with a comment that it should be [None, [{"test": 1}]] once an Arrow issue was fixed. The null was lost by the rebuild here, not by Arrow: from_arrays was given the offsets but not the validity, and a null list and an empty one share offsets. So the test now asserts [None, [{"test": 1}]].

Are there any user-facing changes?

Null lists of structs stay null on write instead of becoming [].

Comment thread tests/io/test_pyarrow.py Outdated
assert result.column(1).to_pylist() == [[], None, [("b", 2), ("c", None)]]


def test__to_requested_schema_null_list_of_structs() -> None:

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.

Can you write a test that involves LargeListArray inputs? I'm pretty sure this change causes a regression.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Will test thanks

LargeListArray.from_arrays refuses a validity mask with sliced offsets, so a sliced large_list of
structs raised. Rebase the offsets to start at 0 and slice the values to match, and test list and
large_list, whole and sliced.
@krishan711

krishan711 commented Oct 23, 2026 •

Copy link
Copy Markdown
Author

@rambleraptor i see it: a sliced large_list of structs raised "Null bitmap with offsets slice not supported". rebased the offsets to start at 0 and sliced the values to match, and the test now covers list and large_list, whole and sliced.

i hope this is what you were looking out for? if not please let me know i can dive deeper 👍

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants