Skip to content

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

Merged
pitrou merged 2 commits into
apache:mainfrom
A-makarim:GH-51223-fix-sliced-boolean-arrays
Sep 23, 2026
Merged

pitrou merged 2 commits into
apache:mainfrom
A-makarim:GH-51223-fix-sliced-boolean-arrays

Conversation

@A-makarim

Copy link
Copy Markdown
Contributor

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.

@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
Contributor Author

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

Comment on lines 38 to 41
static void CopyData(const DataType&, const uint8_t* in, const int64_t in_offset,
uint8_t* out, const int64_t out_offset, const int64_t length) {
arrow::internal::CopyBitmap(in, in_offset, length, out, out_offset);
}

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.

Is this one ever called directly without accounting for the input offset?
If so, then we must fix those use cases as well. Otherwise, perhaps make this method protected to avoid external usage?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I checked the direct uses of the uint8_t* overload. They already pass an absolute bit offset, including the source ArraySpan::offset (for example, CopyValues in scalar_if_else.cc passes array.offset + in_offset).

The affected callers use the ArraySpan overload and pass an offset relative to that span, so adding in.offset there matches the fixed-width specializations and fixes the sliced boolean case. The raw-pointer overload still needs to remain accessible for callers that already supply an absolute offset.

singhpratech added a commit to singhpratech/ArrowMetal that referenced this pull request Sep 17, 2026
singhpratech added a commit to singhpratech/ArrowMetal that referenced this pull request Sep 18, 2026
@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Sep 23, 2026

@pitrou pitrou 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 the explanation @A-makarim . This looks good to me, I'll wait for additional CI and then we can merge.

Copilot AI review requested due to automatic review settings September 23, 2026 12:48
@pitrou
pitrou force-pushed the GH-51223-fix-sliced-boolean-arrays branch from efb7d1f to 398dcdf Compare September 23, 2026 12:48
@pitrou

pitrou commented Sep 23, 2026

Copy link
Copy Markdown
Member

Rebased.

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.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified, and regression coverage is included.

Review effort: Lite
Findings: None

@pitrou
pitrou merged commit 0efbdec into apache:main Sep 23, 2026
60 checks passed
@pitrou pitrou removed the awaiting committer review Awaiting committer review label Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants