JonSnow1807 opened a new pull request, #54938: URL: https://github.com/apache/arrow/pull/54938
### Rationale for this change `SparseUnionArray::Make` used `type_ids.offset()` as the offset of the union array. The offset of a sparse union also applies to its children, so with a sliced `type_ids` array the union referred to child positions shifted by that offset, while `Make` still required the children to have the same length as `type_ids`. As reported in GH-54907, this made it impossible to build a valid sparse union from a sliced `type_ids` array: children of length `len(type_ids)` produce an invalid array, children of length `offset + len(type_ids)` are rejected. ### What changes are included in this PR? When `type_ids` is sliced, its type ids buffer is sliced (zero-copy) to the logical window of `type_ids` and the union is built with offset 0, so the children keep corresponding to the logical positions of `type_ids` as the existing length check requires. Unsliced inputs keep using the original buffer, so nothing changes for them. ### Are these changes tested? Yes. `TestSparseUnionArray.MakeFromSlicedTypeIds` builds a union from a sliced `type_ids` array (with plain and with sliced children) and checks the values; on main it fails with `Sparse union child array #0 has length smaller than expected for union array (3 < 4)`. `arrow-array-test`, `arrow-scalar-test`, `arrow-ipc-read-write-test` and `arrow-compute-scalar-type-test` pass locally (Debug, ASan/UBSan). ### Are there any user-facing changes? A sparse union built from a sliced `type_ids` array is now valid and has offset 0 instead of `type_ids.offset()`. AI usage disclosure: Claude Code assisted with investigating the root cause, preparing the implementation, and developing the regression test. I reviewed the changes and am responsible for their correctness. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
