Struct arrow_array::array::BooleanArray
source · pub struct BooleanArray { /* private fields */ }
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)])
Implementations§
source§impl BooleanArray
impl BooleanArray
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
null
in 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
null
in the constructedBooleanArray
; - the length of the constructed
BooleanArray
is 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
sourcepub fn true_count(&self) -> usize
pub fn true_count(&self) -> usize
Returns the number of non null, true values within this array
sourcepub fn false_count(&self) -> usize
pub fn false_count(&self) -> usize
Returns the number of non null, false values within this array
sourcepub unsafe fn value_unchecked(&self, i: usize) -> bool
pub unsafe fn value_unchecked(&self, i: usize) -> bool
Returns the boolean value at index i
.
§Safety
This doesn’t check bounds, the caller must ensure that index < self.len()
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 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
Trait Implementations§
source§impl Array for BooleanArray
impl Array for BooleanArray
source§fn slice(&self, offset: usize, length: usize) -> ArrayRef
fn slice(&self, offset: usize, length: usize) -> ArrayRef
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 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 moresource§impl Debug for BooleanArray
impl Debug for BooleanArray
source§impl From<ArrayData> for BooleanArray
impl From<ArrayData> for BooleanArray
source§impl From<BooleanArray> for ArrayData
impl From<BooleanArray> for ArrayData
source§fn from(array: BooleanArray) -> Self
fn from(array: BooleanArray) -> Self
source§impl From<BooleanBuffer> for BooleanArray
impl From<BooleanBuffer> for BooleanArray
source§fn from(values: BooleanBuffer) -> Self
fn from(values: BooleanBuffer) -> Self
source§impl<Ptr: Borrow<Option<bool>>> FromIterator<Ptr> for BooleanArray
impl<Ptr: Borrow<Option<bool>>> FromIterator<Ptr> for BooleanArray
source§fn from_iter<I: IntoIterator<Item = Ptr>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = Ptr>>(iter: I) -> Self
source§impl<'a> IntoIterator for &'a BooleanArray
impl<'a> IntoIterator for &'a BooleanArray
source§impl PartialEq for BooleanArray
impl PartialEq for BooleanArray
Auto Trait Implementations§
impl Freeze for BooleanArray
impl RefUnwindSafe for BooleanArray
impl Send for BooleanArray
impl Sync for BooleanArray
impl Unpin for BooleanArray
impl UnwindSafe for BooleanArray
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)