Skip to content

Conversation

@joe-ucp
Copy link

@joe-ucp joe-ucp commented Nov 19, 2025

What issue does this PR close?

This PR extracts the BooleanArray bitwise changes from a larger exploratory PR to enable focused and independent review.


Rationale

This change consolidates BooleanArray bitwise logic by leveraging new buffer-level bitwise primitives. By doing so:

  • High-level kernels become simpler and easier to maintain.
  • Bitmap behavior (including offsets, tail bits, and nulls) can be controlled and tested in one place.

Summary of Changes

  • New Helper Methods
    • Add BooleanArray::binary and BooleanArray::unary methods to operate on the value bitmap, built on top of Buffer::bitwise_binary and Buffer::bitwise_unary.
  • Kernel Updates
    • Update the boolean kernels in arrow-arith/src/boolean.rs to use these new helpers instead of manual bitmap logic.
  • New Tests
    • Add property-based tests in arrow-arith to validate the new helpers against existing logic across a range of offsets and lengths.
    • Add rand as a dev-dependency to arrow-arith for randomized testing.
  • No Change To
    • No updates to nullif or other higher-level APIs in this PR.

Testing

  • cargo test -p arrow-array --lib
  • cargo test -p arrow-arith --lib
  • cargo test -p arrow-select --lib

All tests pass.


User-Facing Changes

None.
This is an internal refactor: new helpers and tests only. No changes to existing public APIs or observable behavior.

Add BooleanArray::binary and BooleanArray::unary in arrow-array, implemented in terms of Buffer::bitwise_binary / Buffer::bitwise_unary

Update boolean kernels in arrow-arith to use these helpers instead of open-coded bitmap logic

Add randomized equivalence tests in arrow-arith to validate the new APIs against existing behavior

Add rand as a dev-dependency in arrow-arith for the new tests

All behavior should be unchanged; this is an internal refactor toward bitwise API consolidation

Tests run locally:

cargo test -p arrow-array --lib

cargo test -p arrow-arith --lib

cargo test -p arrow-select --lib
@github-actions github-actions bot added the arrow Changes to the arrow crate label Nov 19, 2025
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @joe-ucp -- this looks like a good start.

/// * `op` - The unary operation to apply.
pub fn unary<F>(&self, op: F) -> Self
where
F: Fn(u64) -> u64 + Copy,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we please change the bound to follow the bitwise unary signature ?

Namely

        F: FnMut(u64) -> u64

Copy link
Contributor

Choose a reason for hiding this comment

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

same thing applies below to binary

Copy link
Author

Choose a reason for hiding this comment

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

Good catch, thanks! I’ll update BooleanArray::unary to use FnMut(u64) -> u64 to match the bitwise helper signatures.

/// Returns `Err` if this is shared or its allocation is from an external source or
/// it is not allocated with alignment [`ALIGNMENT`]
///
/// # Example: Creating a [`MutableBuffer`] from a [`Buffer`]
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this removed?

Copy link
Author

Choose a reason for hiding this comment

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

Oversight from PR shuffle I did this morning, splitting these up. It got dropped when I pulled immutable.rs over from my exploratory branch.

I’ll restore the example doc comment in this PR; no behavior change was intended here.

Align BooleanArray helper bounds with Buffer bitwise APIs and restore the removed doc example in immutable.rs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants