Skip to content

GH-51223: [C++] Fix copying sliced boolean arrays - #51240

Open
A-makarim wants to merge 2 commits into
apache:mainfrom
A-makarim:GH-51223-fix-sliced-boolean-arrays
Open

GH-51223: [C++] Fix copying sliced boolean arrays#51240
A-makarim wants to merge 2 commits into
apache:mainfrom
A-makarim:GH-51223-fix-sliced-boolean-arrays

Conversation

@A-makarim

Copy link
Copy Markdown

Rationale for this change

Boolean values are bit-packed. When copying values from a sliced boolean array,
the copy path did not include the array's slice offset. This caused
fill_null_forward, fill_null_backward, and replace_with_mask to read
values from earlier positions in the parent array.

What changes are included in this PR?

  • Apply ArraySpan::offset to the bit index when copying boolean values from
    an ArraySpan.
  • Add regression coverage for sliced boolean inputs in replace_with_mask,
    fill_null_forward, and fill_null_backward.

Are these changes tested?

Yes. I ran arrow-compute-vector-test locally.

Are there any user-facing changes?

Only a bugfix.

This PR contains a "Critical Fix".

This fixes a bug that caused compute operations on sliced boolean arrays with
a non-zero offset to produce incorrect values.

Fixes apache#51223

Signed-off-by: Abdul Azeem Makarim <114302821+A-makarim@users.noreply.github.com>
@A-makarim
A-makarim requested a review from pitrou as a code owner September 8, 2026 16:17
Copilot AI lite review requested due to automatic review settings September 8, 2026 16:17
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #51223 has no components, please add labels for components.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The boolean ArraySpan copy now correctly accounts for slice offsets and the added regression tests directly cover the reported failure modes.

Pull request overview

Fixes incorrect bit indexing when copying from sliced boolean ArraySpans by ensuring the slice offset is applied during bitmap copies, and adds regression tests covering the affected compute kernels.

Changes:

  • Apply ArraySpan::offset to the bit index when copying boolean values via CopyDataUtils<BooleanType>.
  • Add regression tests for sliced boolean inputs in replace_with_mask, fill_null_forward, and fill_null_backward.
File summaries
File Description
cpp/src/arrow/compute/kernels/copy_data_internal.h Fix boolean ArraySpan copy to include in.offset in the bit index passed to CopyBitmap.
cpp/src/arrow/compute/kernels/vector_replace_test.cc Add regression tests that exercise non-byte-aligned (offset=3) sliced boolean arrays for replace_with_mask and fill-null kernels.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@singhpratech

Copy link
Copy Markdown
Contributor

Tested this against the reproducer from #51223: with the branch built locally, fill_null_forward,
fill_null_backward and replace_with_mask give the same result for full.slice(3, 5) as for a
fresh copy of the same values, and both new tests fail with copy_data_internal.h from main, so
they cover the bug. One small thing: FillNullSlicedArray landed between the comment that describes
FillNullForwardChunkedArray and that test, so the comment now sits above the wrong one.

singhpratech added a commit to singhpratech/ArrowMetal that referenced this pull request Sep 9, 2026
… verified against the reporter's reproducer

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings September 9, 2026 22:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The fix correctly accounts for boolean slice offsets in the copy path and is backed by targeted regression tests for the reported failing kernels.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@A-makarim

Copy link
Copy Markdown
Author

Thanks for validating this against the reproducer and for spotting the misplaced comment. Fixed in efb7d1f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants