Repository navigation
Fix fixed-size lists and renamed struct fields in nested lists and maps - #4436
Draft
rahulsmahadev wants to merge 4 commits into
Draft
rahulsmahadev wants to merge 4 commits into
rahulsmahadev wants to merge 4 commits into
Conversation
The list visitor rebuilt struct lists from their first two buffers, which are not offsets for a FixedSizeListArray, so the append failed. Rebuild every list and map around its projected children, keeping only the buffers its type has, so renamed struct fields inside nested lists and maps are no longer dropped. Project a struct without a validity mask when it has no nulls, so a rebuilt map with struct keys stays valid (apache/arrow#51029). Co-authored-by: Isaac <[email protected]>
Contributor
Author
|
@rambleraptor, this fixes appending fixed-size lists of structs in |
Contributor
Author
|
@rambleraptor could you take a look when you have a chance? Thanks! |
Co-authored-by: Isaac <[email protected]>
With downcast-ns-timestamp-to-us-on-write on, the list visitor rebuilt the list around the values from before _cast_if_needed, so its final safe cast raised ArrowInvalid on timestamp[ns] and time64[ns] values with sub-microsecond digits. Cast the values first, as the map and struct branches do. Co-authored-by: Isaac <[email protected]>
A row filter can give map keys an all-valid validity buffer, which the rebuilt map kept, and PyArrow 23 to 25 abort when to_arrow_batch_reader casts such a map (apache/arrow#51029). This also fixes maps of structs, which main rebuilt the same way (apache#4084). Co-authored-by: Isaac <[email protected]>
rahulsmahadev
marked this pull request as draft
December 1, 2026 02:16
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Bug: appending a fixed-size list of structs fails. The struct branch of
ArrowProjectionVisitor.listrebuilds the list from its first two buffers, which are the validity and offsets buffers only for a variable-size list. AFixedSizeListArrayhas no offsets buffer, so the rebuilt array is invalid:Fix: rebuild lists and maps around their projected children, preserving validity and offsets; fixed-size lists retain their list size instead of offsets. Lists and maps nested in other lists or maps were cast with the unprojected children, so a renamed struct field (e.g.
a b) came back as null on PyArrow 25 and raised on PyArrow 18. A map with list values had the same gap. This follows #4065's null-list fix; fixed-size lists failed before it too.Bug: with
downcast-ns-timestamp-to-us-on-writeon, appending a list oftimestamp[ns]values with sub-microsecond digits fails. The list visitor downcasts the values but only keeps their type, then casts the original list with a safe cast:Fix: cast the values before rebuilding the list, as the map and struct branches do, so they are truncated to microseconds like a top-level column. Maps failed the same way on main, and the map rebuild above fixes them. This also fixes nested
time64[ns]downcasts, supported since #4471.Bug: a filtered
to_arrow_batch_reader()scan or anupsertof a table with a map of structs aborts the process on PyArrow 23 to 25 (#4084). The map rebuild keeps the keys array, which a row filter can give an all-valid validity buffer, and PyArrow aborts when the reader casts such a map (apache/arrow#51029). Fix: drop that buffer from non-nested, non-dictionary keys, which are never null. This restores filtered reads of maps with ordinary string keys after the map rebuild.Java's lists have no fixed length; Spark writes them through
SparkParquetWriters, without an Arrow writer. This fixes PyArrow's shared read/write projection.Known limit: PyArrow 18 still rejects some null fixed-size lists in its Parquet writer, as it does for
fixed_size_list<int>.Are these changes tested?
Yes,
test__to_requested_schema_fixed_size_list_of_structs,test__to_requested_schema_list_of_lists_of_renamed_structs,test__to_requested_schema_map_of_lists_of_renamed_structs,test_append_fixed_size_list_of_structsandtest_append_map_of_fixed_size_list_of_structsintests/io/test_pyarrow.py. All five fail on main (invalid buffers, or a rename that raises on PyArrow 18 and returns nulls on 25) and pass with this change.test_append_map_with_struct_keyspasses on main and guards the map rebuild for struct keys (apache/arrow#51029).test_append_lists_and_maps_of_ns_temporalsappendstimestamp[ns],timestamp[ns, UTC]andtime64[ns]values with sub-microsecond digits in a list, large list, fixed-size list and map with the option on, and checks the stored microseconds. It fails on main with theArrowInvalidabove and passes with this change.test_filtered_batch_reader_and_upsert_of_mapsreads maps with int, struct and map values through a filteredto_arrow_batch_reader()and upserts them. The struct case aborts on main with PyArrow 25, the others pass on main and guard the map rebuild, and all pass with this change.Are there any user-facing changes?
Yes, fixed-size lists of structs can be appended, renamed struct fields in nested lists and maps are preserved on read and write, and with
downcast-ns-timestamp-to-us-on-writeon,timestamp[ns]andtime64[ns]values in lists and maps are downcast on write instead of raising. Filteredto_arrow_batch_reader()scans and upserts of tables containing maps with non-dictionary string keys and struct values no longer abort on PyArrow 23 to 25. Dictionary-encoded string keys can still trigger the upstream Arrow abort, as on main.Please add the
changeloglabel.This pull request and its description were written by Isaac.