Skip to content

fix(arrow): handle dense union slices and empty validation - #1385

Merged
zeroshade merged 3 commits into
apache:mainfrom
skyon0522-ai:fix/ipc-dense-union-middle-slice
Oct 20, 2026
Merged

zeroshade merged 3 commits into
apache:mainfrom
skyon0522-ai:fix/ipc-dense-union-middle-slice

Conversation

@skyon0522-ai

@skyon0522-ai skyon0522-ai commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Writing a middle slice of a List or LargeList containing dense unions fails even when the input is valid. The stream writer returns an index-out-of-range error, and the file writer panics. RawTypeCodes() includes the backing buffer's remaining entries, while the rebased output buffer holds only the logical slice length.

Using the exported array.ValidateFull in the regression also exposes an empty-array issue: an empty dense-union child decoded from IPC can have no value-offset buffer, but union validation unconditionally accesses that buffer.

What changes are included in this PR?

  • Limit dense union rebasing to arr.Len() type codes.
  • Exercise IPC roundtrips with the exported array.ValidateFull helper.
  • In arrow/array/union.go, run per-value dense offset validation only when the union has values. Child-type checks and nonempty offset validation remain unchanged.
  • Add a direct TestDenseUnionValidateEmpty regression in arrow/array/union_test.go for an empty dense union with a nil value-offset buffer.

Are these changes tested?

On Linux amd64 with Go 1.27.2:

  • The middle-slice regression fails without the IPC rebasing fix.
  • The requested helper replacements reproduce a panic for an empty dense-union List stream roundtrip before the empty-array guard.
  • The direct empty-union validation test reproduces the nil-offset panic when only that guard is removed, and passes with the guard.
  • All 24 roundtrip combinations pass with both fixes: List/LargeList, dense/sparse unions, full/middle/empty slices, and File/Stream, including custom type codes and a selected null child.
  • go test ./arrow/array ./arrow/ipc -count=1 passes.
  • go vet ./arrow/array ./arrow/ipc passes.

Are there any user-facing changes?

Valid middle slices containing dense unions can be written and read back through IPC, and full validation handles empty decoded dense unions. No public API changes.

AI assistance: Codex generated the patch, regression test, and this description, and ran the recorded checks.

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, clear diagnosis and a minimal fix. RawTypeCodes() runs to the end of the backing buffer, so limiting it to arr.Len() is right, and it also stops per-child lengths being computed from type codes outside the slice. I confirmed the new test fails without the fix: putting back only the old line fails exactly the dense-union middle-slice cases for List and LargeList, over both file and stream. The full arrow/ipc suite passes with it.

One small tidy-up inline before this lands; happy to approve once it's in.


This review was drafted by an AI-assisted tool and
confirmed by an Apache Arrow maintainer. After you've
addressed the points above and pushed an update, an Apache Arrow
maintainer — a real person — will take the next look
at the PR. The findings cite the project's review criteria;
if you think one of them is mis-applied, please reply on the
PR and a maintainer will weigh in.

More on how Apache Arrow handles maintainer review:
CONTRIBUTING.md.

Comment thread arrow/ipc/ipc_test.go Resolved
@skyon0522-ai skyon0522-ai changed the title fix(arrow/ipc): bound dense union rebasing to the logical slice fix(arrow): handle dense union slices and empty validation Oct 20, 2026

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for switching to array.ValidateFull, and nice catch on what it turned up: union.ValidateFull crashed on an empty dense union with no offsets buffer, and skipping the offset checks when the array is empty is right. Two small follow-ups:

  • A direct test in arrow/array/union_test.go (empty DenseUnion, nil offsets buffer, ValidateFull() returns nil) would cover that fix on its own rather than only through the IPC round-trip.
  • Please mention the arrow/array change in the PR description.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Arrow maintainer. The findings
below are observations, not blockers; an Apache Arrow
maintainer — a real person — will take the next look at the
PR. If you think a finding is mis-applied, please reply on
the PR and a maintainer will weigh in.

More on how Apache Arrow handles maintainer review:
CONTRIBUTING.md.

Comment thread arrow/array/union.go Resolved

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the direct ValidateFull test is exactly what I was after (it fails without the length > 0 check), and the description now covers both fixes. LGTM.


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.

@zeroshade
zeroshade merged commit 9ee6706 into apache:main Oct 20, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants