Skip to content

GH-45819: [C++] Add OptionalBitmapAnd utility#49848

Open
Shockp wants to merge 4 commits intoapache:mainfrom
Shockp:feat-optional-bitmap-and
Open

GH-45819: [C++] Add OptionalBitmapAnd utility#49848
Shockp wants to merge 4 commits intoapache:mainfrom
Shockp:feat-optional-bitmap-and

Conversation

@Shockp
Copy link
Copy Markdown
Contributor

@Shockp Shockp commented Apr 23, 2026

Rationale for this change

In Arrow, null bitmaps are optional and represented by nullptr when a column contains no nulls. Previously, conjoining two optional bitmaps required downstream code to manually handle the nullptr checks and memory allocations. This change centralizes that logic into a single, highly optimized utility function.

What changes are included in this PR?

  • Added OptionalBitmapAnd to cpp/src/arrow/util/bitmap_ops.h and bitmap_ops.cc.
  • The implementation safely handles the four possible memory permutations with minimal allocations:
    1. Both buffers nullptr: Returns nullptr.
    2. Left is nullptr: Returns a copy of the right buffer.
    3. Right is nullptr: Returns a copy of the left buffer.
    4. Both valid: Defers to the low-level BitmapAnd function.

Are these changes tested?

Yes. I added a new test case (OptionalBitmapAnd) to cpp/src/arrow/util/bitmap_test.cc that explicitly verifies the correct buffer allocation and bitwise output for all four memory states.

Are there any user-facing changes?

No. This simply exposes a new C++ utility for internal development.

Closes #45819

Centralizes the logic for conjoining optional null bitmaps.
Optimizes memory allocations by returning nullptr or falling back to
CopyBitmap when one or both of the input buffers are missing.
@Shockp Shockp force-pushed the feat-optional-bitmap-and branch 2 times, most recently from 6e35d79 to 7fd57ca Compare April 23, 2026 10:52
@Shockp Shockp force-pushed the feat-optional-bitmap-and branch from 7fd57ca to 28d69c7 Compare April 23, 2026 11:14
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.

[C++] Add OptionalBitmapAnd utility

1 participant