fix(array): compare sparse union slices at relative offsets - #1096
Merged
zeroshade merged 1 commit intoAug 6, 2026
Merged
Conversation
zeroshade
approved these changes
Aug 6, 2026
zeroshade
left a comment
Member
There was a problem hiding this comment.
LGTM. The root cause is confirmed: union.setData already slices each sparse-union child by the parent offset (union.go L137-143), and RawTypeCodes() returns typecodes[offset:], so children and type codes are both already offset-adjusted. Adding data.offset again in arraySparseUnionApproxEqual double-counted the offset. The fix brings the approx-equal path in line with the already-correct exact-equality path (arraySparseUnionEqual, L454), and dense unions are correctly left untouched.
Verified locally:
- New test passes; full
./arrow/array -run Unionsuite passes. - Regression proof: reverting only the union.go change (keeping the test) makes the test fail, confirming it genuinely catches the bug.
- The test uses distinct offsets on each side over different underlying values, so it faithfully reproduces the reported issue.
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
SparseUnion.setData already slices each child using the parent union offset. ApproxEqual adds that offset again, so sliced unions can compare the wrong child values or hit invalid slice bounds.
What changes are included in this PR?
Compare each selected child at its relative i:i+1 position, matching exact equality and the representation used by sparse unions.
Are these changes tested?
go test ./arrow/array -run TestSparseUnionApproxEqualSlicesWithDifferentOffsets -count=1Are there any user-facing changes?
No API changes. This corrects the reported behavior while preserving the existing ownership and compatibility contracts.