Repository navigation
fix(arrow/compute): allow casting nullable struct fields to non-nullable when no nulls - #1363
Merged
zeroshade merged 1 commit intoOct 13, 2026
Conversation
zeroshade
approved these changes
Oct 13, 2026
zeroshade
left a comment
Member
There was a problem hiding this comment.
LGTM — this matches the C++ struct cast (scalar_cast_nested.cc): reject only when a nullable source field actually has nulls, with the same Invalid message. Locally the full arrow/compute/... suite passes, and a checked-allocator probe of the new error path (failure on the first and on a later field) shows no leaks.
Smaller observations
arrow/compute/cast_test.go— the successful cases (out3,out4) only assert length/no error; consider asserting the cast output (e.g. compare against the expected struct viaarray.Equal) and that the result's field is non-nullable.- The error type changes from
arrow.ErrTypetoarrow.ErrInvalidfor this case; callers matchingerrors.Is(err, arrow.ErrType)will see different behavior, so it's worth calling out in the release notes.
This review was drafted by an AI-assisted tool and
confirmed by an Apache Arrow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.More on how Apache Arrow handles maintainer review:
CONTRIBUTING.md.
…ble when no nulls Casting a struct whose field is nullable to a struct whose matching field is non-nullable always failed with ErrType, even when the field held no nulls. Check the field's null count at cast time instead, as the C++ implementation does: the cast succeeds when the field has no nulls and returns ErrInvalid when it does.
zeroshade
force-pushed
the
fix/133-struct-cast-nullable
branch
from
October 13, 2026 13:43
15d3b0e to
a44d190
Compare
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
Casting a struct with a nullable field to a struct type where that field is non-nullable always failed with
arrow.ErrType, even when the field held no nulls. The C++ implementation only rejects the cast when the field actually has nulls (scalar_cast_nested.cc).What changes are included in this PR?
CastStructno longer rejects nullable to non-nullable fields while matching field names. It checks each selected field's null count at cast time instead, and returnsarrow.ErrInvalidwith the same message as C++ when the field has nulls.Are these changes tested?
Yes.
TestStructToDifferentNullabilityStructnow covers a field with no nulls (cast succeeds), fields with nulls (ErrInvalid), and a slice that skips the null rows (cast succeeds).go test ./arrow/compute/...: okgo vet ./arrow/compute/...andgofmt -l arrow/compute: cleanAre there any user-facing changes?
Yes. These casts now succeed when the field has no nulls. When it has nulls, the error is now
arrow.ErrInvalidinstead ofarrow.ErrType, matching C++.Fixes #133
AI/LLM disclosure