Hei-MaoM opened a new pull request, #51017:
URL: https://github.com/apache/arrow/pull/51017
### Rationale for this change
`StructArray::GetFlattenedField` currently combines a struct's validity
bitmap with a child by assigning it to buffer 0. Union arrays do not have
top-level validity buffers, so flattening a union field aborts even when
the parent bitmap is all-valid. When the parent contains nulls, that
validity must instead be represented by the union's child arrays.
### What changes are included in this PR?
- Preserve the union's null top-level validity buffer and its type codes.
- Apply parent validity to every aligned child of a sparse union.
- Rebuild dense-union child segments in logical order so parent-null slots
are null without invalidating valid slots that share the same original
child offset.
- Preserve non-decreasing dense-union offsets and handle sliced arrays.
- Add sparse and dense regression tests.
### Are these changes tested?
- `cmake --build /build/cpp --target arrow-array-test -j 4`
- `/build/cpp/debug/arrow-array-test
--gtest_filter=StructArray.FlattenSparseUnion:StructArray.FlattenDenseUnionWithSharedOffsets
--gtest_brief=1`
- `/build/cpp/debug/arrow-array-test --gtest_brief=1`
- 1062 passed
- 1 skipped because the local build does not enable the required threading
configuration
- `clang-format 18.1.8`
- `cpplint 1.6.1`
- `git diff --check`
### Are there any user-facing changes?
Yes. `StructArray::GetFlattenedField` and callers such as `struct_field`
and `Flatten` no longer crash when selecting a union field from a nullable
struct. Parent nulls are represented in the appropriate union children.
There are no public API changes.
**This PR contains a "Critical Fix".** It fixes a crash on valid input.
Closes #14736.
### AI assistance disclosure
I used OpenAI Codex to help investigate the issue, draft parts of the
implementation and tests, and run verification. I reviewed the final diff
and am responsible for understanding, debugging, and maintaining the change.
--
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]