pub fn list_contains(
array: &dyn Array,
value: &dyn Array,
) -> VortexResult<ArrayRef>
Expand description
Compute a Bool
-typed array the same length as array
where elements is true
if the list
item contains the value
, false
otherwise.
§Null scalar handling
If the value
or array
is null
at any index the result at that index is null
.
§Format semantics
list_contains(list, elem)
==> (!is_null(list) or NULL) and (!is_null(elem) or NULL) and any({elem = elem_i | elem_i in list}),
§Example
use vortex_array::{Array, IntoArray, ToCanonical};
use vortex_array::arrays::{ConstantArray, ListArray, VarBinArray};
use vortex_array::compute::list_contains;
use vortex_array::validity::Validity;
use vortex_buffer::buffer;
use vortex_dtype::DType;
use vortex_scalar::Scalar;
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(), ConstantArray::new(Scalar::from("b"), list_array.len()).as_ref()).unwrap();
let to_vec: Vec<bool> = matches.to_bool().unwrap().boolean_buffer().iter().collect();
assert_eq!(to_vec, vec![false, true, false]);