vortex_array/arrays/chunked/compute/
is_constant.rs

1use vortex_error::{VortexExpect, VortexResult};
2
3use crate::arrays::{ChunkedArray, ChunkedEncoding};
4use crate::compute::{IsConstantFn, IsConstantOpts, is_constant_opts, scalar_at};
5
6impl IsConstantFn<&ChunkedArray> for ChunkedEncoding {
7    fn is_constant(
8        &self,
9        array: &ChunkedArray,
10        opts: &IsConstantOpts,
11    ) -> VortexResult<Option<bool>> {
12        let mut chunks = array.chunks().iter();
13
14        let first_chunk = chunks.next().vortex_expect("Must have at least one value");
15
16        if !is_constant_opts(first_chunk, opts)? {
17            return Ok(Some(false));
18        }
19
20        let first_value = scalar_at(first_chunk, 0)?.into_nullable();
21
22        for chunk in chunks {
23            if !is_constant_opts(chunk, opts)? {
24                return Ok(Some(false));
25            }
26
27            if first_value != scalar_at(chunk, 0)?.into_nullable() {
28                return Ok(Some(false));
29            }
30        }
31
32        Ok(Some(true))
33    }
34}