pub struct BooleanArray {
values: BooleanBuffer,
nulls: Option<NullBuffer>,
}Expand description
An array of boolean values
§Example: From a Vec
let arr: BooleanArray = vec![true, true, false].into();§Example: From an optional Vec
let arr: BooleanArray = vec![Some(true), None, Some(false)].into();§Example: From an iterator
let arr: BooleanArray = (0..5).map(|x| (x % 2 == 0).then(|| x % 3 == 0)).collect();
let values: Vec<_> = arr.iter().collect();
assert_eq!(&values, &[Some(true), None, Some(false), None, Some(false)])§Example: Using Builder
let mut builder = BooleanBuilder::new();
builder.append_value(true);
builder.append_null();
builder.append_value(false);
let array = builder.finish();
let values: Vec<_> = array.iter().collect();
assert_eq!(&values, &[Some(true), None, Some(false)])Fields§
§values: BooleanBuffer§nulls: Option<NullBuffer>Implementations§
Source§impl BooleanArray
impl BooleanArray
Sourceconst CHUNK_FOLD_BLOCK_SIZE: usize = 16
const CHUNK_FOLD_BLOCK_SIZE: usize = 16
Block size for chunked fold operations in Self::has_true and Self::has_false.
Using chunks_exact with this size lets the compiler fully unroll the inner
fold (no inner branch/loop), enabling short-circuit exits every N chunks.
Sourcepub fn new(values: BooleanBuffer, nulls: Option<NullBuffer>) -> Self
pub fn new(values: BooleanBuffer, nulls: Option<NullBuffer>) -> Self
Create a new BooleanArray from the provided values and nulls
§Panics
Panics if values.len() != nulls.len()
Sourcepub fn new_null(len: usize) -> Self
pub fn new_null(len: usize) -> Self
Create a new BooleanArray with length len consisting only of nulls
Sourcepub fn new_scalar(value: bool) -> Scalar<Self>
pub fn new_scalar(value: bool) -> Scalar<Self>
Create a new Scalar from value
Sourcepub fn new_from_packed(
buffer: impl Into<Buffer>,
offset: usize,
len: usize,
) -> Self
pub fn new_from_packed( buffer: impl Into<Buffer>, offset: usize, len: usize, ) -> Self
Create a new BooleanArray from a [Buffer] specified by offset and len, the offset and len in bits
Logically convert each bit in [Buffer] to boolean and use it to build BooleanArray.
using this method will make the following points self-evident:
- there is no
nullin the constructedBooleanArray; - without considering
buffer.into(), this method is efficient because there is no need to perform pack and unpack operations on boolean;
Sourcepub fn new_from_u8(value: &[u8]) -> Self
pub fn new_from_u8(value: &[u8]) -> Self
Create a new BooleanArray from &[u8]
This method uses new_from_packed and constructs a [Buffer] using value, and offset is set to 0 and len is set to value.len() * 8
using this method will make the following points self-evident:
- there is no
nullin the constructedBooleanArray; - the length of the constructed
BooleanArrayis always a multiple of 8;
Sourcepub fn slice(&self, offset: usize, length: usize) -> Self
pub fn slice(&self, offset: usize, length: usize) -> Self
Returns a zero-copy slice of this array with the indicated offset and length.
Sourcepub fn builder(capacity: usize) -> BooleanBuilder
pub fn builder(capacity: usize) -> BooleanBuilder
Returns a new boolean array builder
Sourcepub fn values(&self) -> &BooleanBuffer
pub fn values(&self) -> &BooleanBuffer
Returns the underlying [BooleanBuffer] holding all the values of this array
Sourcefn unaligned_bit_chunks(&self) -> UnalignedBitChunk<'_>
fn unaligned_bit_chunks(&self) -> UnalignedBitChunk<'_>
Returns an [UnalignedBitChunk] over this array’s values.
Sourcepub fn true_count(&self) -> usize
pub fn true_count(&self) -> usize
Returns the number of non null, true values within this array.
If you only need to check if there is at least one true value, consider using has_true() which can short-circuit and be more efficient.
Sourcepub fn false_count(&self) -> usize
pub fn false_count(&self) -> usize
Returns the number of non null, false values within this array.
If you only need to check if there is at least one false value, consider using has_false() which can short-circuit and be more efficient.
Sourcepub fn has_true(&self) -> bool
pub fn has_true(&self) -> bool
Returns whether there is at least one non-null true value in this array.
This is more efficient than true_count() > 0 because it can short-circuit
as soon as a true value is found, without counting all set bits.
Null values are not counted as true. Returns false for empty arrays.
Sourcepub fn has_false(&self) -> bool
pub fn has_false(&self) -> bool
Returns whether there is at least one non-null false value in this array.
This is more efficient than false_count() > 0 because it can short-circuit
as soon as a false value is found, without counting all set bits.
Null values are not counted as false. Returns false for empty arrays.
Sourcepub unsafe fn value_unchecked(&self, i: usize) -> bool
pub unsafe fn value_unchecked(&self, i: usize) -> bool
Sourcepub fn take_iter<'a>(
&'a self,
indexes: impl Iterator<Item = Option<usize>> + 'a,
) -> impl Iterator<Item = Option<bool>> + 'a
pub fn take_iter<'a>( &'a self, indexes: impl Iterator<Item = Option<usize>> + 'a, ) -> impl Iterator<Item = Option<bool>> + 'a
Returns an iterator that returns the values of array.value(i) for an iterator with each element i
Sourcepub unsafe fn take_iter_unchecked<'a>(
&'a self,
indexes: impl Iterator<Item = Option<usize>> + 'a,
) -> impl Iterator<Item = Option<bool>> + 'a
pub unsafe fn take_iter_unchecked<'a>( &'a self, indexes: impl Iterator<Item = Option<usize>> + 'a, ) -> impl Iterator<Item = Option<bool>> + 'a
Returns an iterator that returns the values of array.value(i) for an iterator with each element i
§Safety
caller must ensure that the offsets in the iterator are less than the array len()
Sourcepub fn from_unary<T: ArrayAccessor, F>(left: T, op: F) -> Self
pub fn from_unary<T: ArrayAccessor, F>(left: T, op: F) -> Self
Create a BooleanArray by evaluating the operation for
each element of the provided array
let array = Int32Array::from(vec![1, 2, 3, 4, 5]);
let r = BooleanArray::from_unary(&array, |x| x > 2);
assert_eq!(&r, &BooleanArray::from(vec![false, false, true, true, true]));Sourcepub fn from_binary<T: ArrayAccessor, S: ArrayAccessor, F>(
left: T,
right: S,
op: F,
) -> Self
pub fn from_binary<T: ArrayAccessor, S: ArrayAccessor, F>( left: T, right: S, op: F, ) -> Self
Create a BooleanArray by evaluating the binary operation for
each element of the provided arrays
let a = Int32Array::from(vec![1, 2, 3, 4, 5]);
let b = Int32Array::from(vec![1, 2, 0, 2, 5]);
let r = BooleanArray::from_binary(&a, &b, |a, b| a == b);
assert_eq!(&r, &BooleanArray::from(vec![true, true, false, false, true]));§Panics
This function panics if left and right are not the same length
Sourcepub fn bitwise_unary<F>(&self, op: F) -> BooleanArray
pub fn bitwise_unary<F>(&self, op: F) -> BooleanArray
Apply a bitwise operation to this array’s values using u64 operations,
returning a new BooleanArray.
The null buffer is preserved unchanged.
See [BooleanBuffer::from_bitwise_unary_op] for details on the operation.
§Example
let array = BooleanArray::from(vec![true, false, true]);
let result = array.bitwise_unary(|x| !x);
assert_eq!(result, BooleanArray::from(vec![false, true, false]));Sourcepub fn bitwise_unary_mut<F>(self, op: F) -> Result<BooleanArray, BooleanArray>
pub fn bitwise_unary_mut<F>(self, op: F) -> Result<BooleanArray, BooleanArray>
Try to apply a bitwise operation to this array’s values in place using u64 operations.
If the underlying buffer is uniquely owned, the operation is applied
in place and Ok is returned. If the buffer is shared, Err(self) is
returned so the caller can fall back to bitwise_unary.
The null buffer is preserved unchanged.
§Example
let array = BooleanArray::from(vec![true, false, true]);
let result = array.bitwise_unary_mut(|x| !x).unwrap();
assert_eq!(result, BooleanArray::from(vec![false, true, false]));Sourcepub fn bitwise_unary_mut_or_clone<F>(self, op: F) -> BooleanArray
pub fn bitwise_unary_mut_or_clone<F>(self, op: F) -> BooleanArray
Apply a bitwise operation to this array’s values in place if the buffer is uniquely owned, or clone and apply if shared.
This is a convenience wrapper around bitwise_unary_mut
that falls back to bitwise_unary when the buffer is shared.
The null buffer is preserved unchanged.
§Example
let array = BooleanArray::from(vec![true, false, true]);
let result = array.bitwise_unary_mut_or_clone(|x| !x);
assert_eq!(result, BooleanArray::from(vec![false, true, false]));Sourcefn try_bitwise_unary_in_place<F>(
self,
op: F,
) -> Result<BooleanArray, (BooleanArray, F)>
fn try_bitwise_unary_in_place<F>( self, op: F, ) -> Result<BooleanArray, (BooleanArray, F)>
Try to apply a unary op in place. Returns op back on failure so
callers can fall back to an allocating path without requiring F: Clone.
Sourcepub fn bitwise_bin_op<F>(&self, rhs: &BooleanArray, op: F) -> BooleanArray
pub fn bitwise_bin_op<F>(&self, rhs: &BooleanArray, op: F) -> BooleanArray
Apply a bitwise binary operation to this array and rhs using u64
operations, returning a new BooleanArray.
Null buffers are unioned: the result is null where either input is null.
See [BooleanBuffer::from_bitwise_binary_op] for details on the operation.
§Panics
Panics if self and rhs have different lengths.
§Example
let a = BooleanArray::from(vec![true, false, true, true]);
let b = BooleanArray::from(vec![true, true, false, true]);
let result = a.bitwise_bin_op(&b, |a, b| a & b);
assert_eq!(result, BooleanArray::from(vec![true, false, false, true]));Sourcepub fn bitwise_bin_op_mut<F>(
self,
rhs: &BooleanArray,
op: F,
) -> Result<BooleanArray, BooleanArray>
pub fn bitwise_bin_op_mut<F>( self, rhs: &BooleanArray, op: F, ) -> Result<BooleanArray, BooleanArray>
Try to apply a bitwise binary operation to this array and rhs in
place using u64 operations.
If this array’s underlying buffer is uniquely owned, the operation is
applied in place and Ok is returned. If the buffer is shared,
Err(self) is returned so the caller can fall back to
bitwise_bin_op.
Null buffers are unioned: the result is null where either input is null.
§Panics
Panics if self and rhs have different lengths.
§Example
let a = BooleanArray::from(vec![true, false, true, true]);
let b = BooleanArray::from(vec![true, true, false, true]);
let result = a.bitwise_bin_op_mut(&b, |a, b| a & b).unwrap();
assert_eq!(result, BooleanArray::from(vec![true, false, false, true]));Sourcepub fn bitwise_bin_op_mut_or_clone<F>(
self,
rhs: &BooleanArray,
op: F,
) -> BooleanArray
pub fn bitwise_bin_op_mut_or_clone<F>( self, rhs: &BooleanArray, op: F, ) -> BooleanArray
Apply a bitwise binary operation to this array and rhs in place if the
buffer is uniquely owned, or clone and apply if shared.
This is a convenience wrapper around bitwise_bin_op_mut
that falls back to bitwise_bin_op when the buffer is shared.
Null buffers are unioned: the result is null where either input is null.
§Panics
Panics if self and rhs have different lengths.
§Example
let a = BooleanArray::from(vec![true, false, true, true]);
let b = BooleanArray::from(vec![true, true, false, true]);
let result = a.bitwise_bin_op_mut_or_clone(&b, |a, b| a & b);
assert_eq!(result, BooleanArray::from(vec![true, false, false, true]));Sourcefn try_bitwise_bin_op_in_place<F>(
self,
rhs: &BooleanArray,
op: F,
) -> Result<BooleanArray, (BooleanArray, F)>
fn try_bitwise_bin_op_in_place<F>( self, rhs: &BooleanArray, op: F, ) -> Result<BooleanArray, (BooleanArray, F)>
Try to apply a binary op in place. Returns op back on failure so
callers can fall back to an allocating path without requiring F: Clone.
Sourcepub fn into_parts(self) -> (BooleanBuffer, Option<NullBuffer>)
pub fn into_parts(self) -> (BooleanBuffer, Option<NullBuffer>)
Deconstruct this array into its constituent parts
Source§impl<'a> BooleanArray
impl<'a> BooleanArray
Sourcepub fn iter(&'a self) -> BooleanIter<'a>
pub fn iter(&'a self) -> BooleanIter<'a>
constructs a new iterator
Source§impl BooleanArray
impl BooleanArray
Sourcepub unsafe fn from_trusted_len_iter<I, P>(iter: I) -> Self
pub unsafe fn from_trusted_len_iter<I, P>(iter: I) -> Self
Creates a BooleanArray from an iterator of trusted length.
§Safety
The iterator must be TrustedLen.
I.e. that size_hint().1 correctly reports its length. Note that this is a stronger
guarantee that ExactSizeIterator provides which could still report a wrong length.
§Panics
Panics if the iterator does not report an upper bound on size_hint().
Trait Implementations§
Source§impl Array for BooleanArray
SAFETY: Correctly implements the contract of Arrow Arrays
impl Array for BooleanArray
SAFETY: Correctly implements the contract of Arrow Arrays
Source§fn data_type(&self) -> &DataType
fn data_type(&self) -> &DataType
DataType] of this array. Read moreSource§fn slice(&self, offset: usize, length: usize) -> ArrayRef
fn slice(&self, offset: usize, length: usize) -> ArrayRef
Source§fn shrink_to_fit(&mut self)
fn shrink_to_fit(&mut self)
Source§fn offset(&self) -> usize
fn offset(&self) -> usize
0. Read moreSource§fn nulls(&self) -> Option<&NullBuffer>
fn nulls(&self) -> Option<&NullBuffer>
Source§fn logical_null_count(&self) -> usize
fn logical_null_count(&self) -> usize
Source§fn get_buffer_memory_size(&self) -> usize
fn get_buffer_memory_size(&self) -> usize
Source§fn get_array_memory_size(&self) -> usize
fn get_array_memory_size(&self) -> usize
get_buffer_memory_size() and
includes the overhead of the data structures that contain the pointers to the various buffers.Source§fn claim(&self, pool: &dyn MemoryPool)
fn claim(&self, pool: &dyn MemoryPool)
Source§fn logical_nulls(&self) -> Option<NullBuffer>
fn logical_nulls(&self) -> Option<NullBuffer>
NullBuffer] that represents the logical
null values of this array, if any. Read moreSource§fn null_count(&self) -> usize
fn null_count(&self) -> usize
Source§fn is_nullable(&self) -> bool
fn is_nullable(&self) -> bool
false if the array is guaranteed to not contain any logical nulls Read moreSource§impl ArrayAccessor for &BooleanArray
impl ArrayAccessor for &BooleanArray
Source§impl Clone for BooleanArray
impl Clone for BooleanArray
Source§fn clone(&self) -> BooleanArray
fn clone(&self) -> BooleanArray
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more