pub fn list_contains(array: &dyn Array, value: Scalar) -> VortexResult<ArrayRef>Expand description
Compute a Bool-typed array the same length as array where elements are true if the list
item contains the value, or false otherwise.
If the ListArray is nullable, then the result will contain nulls matching the null mask of the original array.
§Null scalar handling
When the search scalar is NULL, then the resulting array will be a BoolArray containing
true if the list contains any nulls, and false if the list does not contain any nulls,
or NULL for null lists.
§Example
use vortex_array::{Array, IntoArray, ToCanonical};
use vortex_array::arrays::{ListArray, VarBinArray};
use vortex_array::compute::list_contains;
use vortex_array::validity::Validity;
use vortex_buffer::buffer;
use vortex_dtype::DType;
let elements = VarBinArray::from_vec(
vec!["a", "a", "b", "a", "c"], DType::Utf8(false.into())).into_array();
let offsets = buffer![0u32, 1, 3, 5].into_array();
let list_array = ListArray::try_new(elements, offsets, Validity::NonNullable).unwrap();
let matches = list_contains(list_array.as_ref(), "b".into()).unwrap();
let to_vec: Vec<bool> = matches.to_bool().unwrap().boolean_buffer().iter().collect();
assert_eq!(to_vec, vec![false, true, false]);