Skip to content

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

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

krishan711 wants to merge 6 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 Resolved
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 👍

@krishan711

Copy link
Copy Markdown
Author

@rambleraptor sorry for the ping, but any thoughts here? happy to update more if needed..

@rambleraptor rambleraptor 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.

PyArrow changes always scare me, but I think this looks correct. Thanks a lot!

@Fokko

Fokko commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@krishan711 Can you resolve the merge conflicts?

…of-structs

* upstream/main: (78 commits)
  fix(io): keep null lists of structs when projecting Arrow data (apache#4065)
  Skip unknown nested fields when resolving Avro read schemas (apache#4289)
  fix(expressions): reject non-finite floats on conversion to Decimal (apache#4287)
  fix: handle negative-scale Decimals in increment, decrement and truncate_decimal (apache#4285)
  Match NaN partition values with `IsNaN` in partition predicates (apache#4281)
  Fix append when a data column is named like a partition helper column (apache#4344)
  Widen decimal literal precision in scan filters (apache#4348)
  Add row-lineage support with Spark tests (apache#3972)
  Serialize purgeRequested as a lowercase boolean in REST drop_table (apache#4341)
  Validate each branch against its own commits on retry (apache#4317)
  Core: Compare upsert rows column by column instead of cell by cell (apache#4334)
  Core: Write added files under the partition spec they were planned with (apache#4338)
  Core: Check whether a failed last commit attempt landed before cleanup (apache#4339)
  REST: Use the standard User-Agent format (apache#4330)
  SQL: Accept an existing SQLAlchemy engine in SqlCatalog (apache#4336)
  Expose catalog labels on Table (apache#4321)
  Respect REST endpoint capabilities when checking view existence (apache#4337)
  Reject existing ref names in create_branch and create_tag (apache#4319)
  Assert every ref a transaction writes, not just the first (apache#4315)
  feat: send Idempotency-Key on REST mutations when the server advertises it (apache#4310)
  ...

# Conflicts:
#	pyiceberg/io/pyarrow.py
#	tests/io/test_pyarrow.py
@krishan711

Copy link
Copy Markdown
Author

@krishan711 Can you resolve the merge conflicts?

done.

@krishan711

Copy link
Copy Markdown
Author

Closing: the fix landed in #4065.

@krishan711 krishan711 closed this Nov 12, 2026
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.

3 participants