GH-50515: [C++][Compute] Respect parent validity bitmap when casting nested structs with non-nullable fields#50546
Open
aaron-seq wants to merge 1 commit into
Conversation
…ct cast When casting a struct with a nullable->non-nullable field change, CastStruct::Exec checks GetNullCount() on the child array without considering the parent struct's validity bitmap. This rejects casts where the child's physical nulls are fully masked by parent-level nulls. Intersect the parent and child validity bitmaps before deciding whether unmasked nulls exist, using BinaryBitBlockCounter for the common case and explicit fallbacks for absent bitmaps.
|
|
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
When casting a nested struct whose inner field changes from nullable to
non-nullable,
CastStruct::Execcurrently callsin_values->GetNullCount() > 0without considering the parent struct'svalidity bitmap. This causes a spurious
ArrowInvaliderror when thechild's physical nulls are fully masked by null parent entries.
Reported in #50515.
What changes are included in this PR?
In
scalar_cast_nested.cc, replace the unconditional rejection with athree-way check:
BinaryBitBlockCounter::NextAndNotWord()to detect parent-valid-AND-child-null positions without heap allocation.
Are these changes tested?
Five new C++ test cases in
scalar_cast_test.cc:StructNestedNullabilityAbsentParent— true violation, must rejectStructNestedNullabilityMasked— masked null, must succeedStructNestedNullabilitySliced— offset correctness for both outcomesStructNestedNullabilityAbsentChild— no nulls, must succeedStructNestedNullabilityDeep— 3-level nesting with masked nullOne new Python test in
test_compute.py:test_cast_struct_nested_nullability— end-to-end PyArrow validationcovering success, rejection, and sliced array cases
Are there any user-facing changes?
Struct casts that were previously rejected with
ArrowInvalid: field '...' has nullswill now succeed when the nullsare masked by parent-level nulls. This is a correctness fix, not a
behavior change — the previous behavior was incorrect per the Arrow
columnar format specification.