vortex_functions/list_contains/
chunked.rs1use vortex_array::ArrayRef;
5use vortex_array::ArrayView;
6use vortex_array::IntoArray;
7use vortex_array::arrays::Chunked;
8use vortex_array::arrays::ChunkedArray;
9use vortex_array::arrays::chunked::ChunkedArrayExt;
10use vortex_array::dtype::DType;
11use vortex_error::VortexResult;
12
13use crate::list_contains::ListContains;
14use crate::list_contains::ListContainsElementReduce;
15use crate::list_contains::ListContainsOptions;
16use crate::list_contains::PreparedSet;
17
18impl ListContainsElementReduce for Chunked {
23 fn list_contains(
24 list: &ArrayRef,
25 needles: ArrayView<'_, Chunked>,
26 options: &ListContainsOptions,
27 ) -> VortexResult<Option<ArrayRef>> {
28 if PreparedSet::set_of(list).is_none() {
29 return Ok(None);
30 }
31
32 let mut offset = 0;
33 let chunks = needles
34 .iter_chunks()
35 .map(|chunk| {
36 let set = list.slice(offset..offset + chunk.len())?;
37 offset += chunk.len();
38 Ok(ListContains::try_new_opts(set, chunk.clone(), *options)?.into_array())
39 })
40 .collect::<VortexResult<Vec<_>>>()?;
41
42 let dtype = DType::Bool(options.result_nullability(list.dtype(), needles.dtype()));
43
44 Ok(Some(
47 unsafe { ChunkedArray::new_unchecked(chunks, dtype) }.into_array(),
48 ))
49 }
50}