Skip to main content

FilterBuilder

Struct FilterBuilder 

pub struct FilterBuilder {
    filter: BooleanArray,
    count: Option<usize>,
    optimize: bool,
}
Expand description

A builder to construct FilterPredicate

Fields§

§filter: BooleanArray§count: Option<usize>§optimize: bool

Implementations§

§

impl FilterBuilder

pub fn new(filter: &BooleanArray) -> FilterBuilder

Create a new FilterBuilder that can be used to construct a FilterPredicate

pub unsafe fn with_count(self, count: usize) -> FilterBuilder

Set the number of rows that the filter selects, so that Self::build does not have to count them.

Callers that build a mask row by row, or derive it from a validity buffer with a cached null count, often already hold this number.

§Safety

count must equal BooleanArray::true_count of the filter passed to Self::new: the number of true values that are not null.

§Example
let values = Int32Array::from(vec![1, 2, 3, 4]);
let mask = BooleanArray::from(vec![Some(true), None, Some(true), Some(false)]);
// The null is not selected, so the mask selects two rows.
// SAFETY: the count matches the mask.
let predicate = unsafe { FilterBuilder::new(&mask).with_count(2) }.build();
assert_eq!(predicate.count(), 2);
let filtered = predicate.filter(&values).unwrap();
assert_eq!(filtered.as_ref(), &Int32Array::from(vec![1, 3]));

pub fn optimize(self) -> FilterBuilder

Compute an optimized representation of the provided filter mask in Self::build, so that it can be applied to an array more quickly.

When filtering multiple arrays (e.g. a RecordBatch or a StructArray with multiple fields), optimizing the filter can provide significant performance benefits.

However, optimization takes time and can have a larger memory footprint than the original mask, so it is often faster to filter a single array, without filter optimization.

pub fn is_optimize_beneficial(data_type: &DataType) -> bool

Determines if calling FilterBuilder::optimize is beneficial for the given type even when filtering just a single array.

See FilterBuilder::optimize for more details.

pub fn build(self) -> FilterPredicate

Construct the final FilterPredicate

Trait Implementations§

§

impl Debug for FilterBuilder

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Ungil for T
where T: Send,