Skip to main content

filter

Function filter 

Source
pub fn filter(
    values: &dyn Array,
    predicate: &BooleanArray,
) -> Result<ArrayRef, ArrowError>
Expand description

Returns a filtered values [Array] where the corresponding elements of predicate are true.

predicate may be shorter than values. Rows beyond the end of predicate are not selected.

If multiple arrays (or record batches) need to be filtered using the same predicate array, consider using FilterBuilder to create a single FilterPredicate and then calling FilterPredicate::filter_record_batch.

In contrast to this function, it is then the responsibility of the caller to use FilterBuilder::optimize if appropriate.

If the number of rows that predicate selects is already known, FilterBuilder::with_count avoids counting them again.

§See also

§Example

let array = Int32Array::from(vec![5, 6, 7, 8, 9]);
// Rows beyond the end of the predicate are not selected.
let filter_array = BooleanArray::from(vec![true, false, true]);
let c = filter(&array, &filter_array).unwrap();
let c = c.as_any().downcast_ref::<Int32Array>().unwrap();
assert_eq!(c, &Int32Array::from(vec![5, 7]));