Skip to main content

vortex_fsst/compute/
byte_length.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3use vortex_array::ArrayRef;
4use vortex_array::ArrayView;
5use vortex_array::ExecutionCtx;
6use vortex_array::IntoArray;
7use vortex_array::ValidityVTable;
8use vortex_array::arrays::ConstantArray;
9use vortex_array::builtins::ArrayBuiltins;
10use vortex_array::dtype::DType;
11use vortex_array::dtype::PType;
12use vortex_array::scalar::Scalar;
13use vortex_array::scalar_fn::fns::byte_length::ByteLengthKernel;
14use vortex_array::validity::Validity;
15use vortex_error::VortexResult;
16
17use crate::FSST;
18use crate::array::FSSTArrayExt;
19
20impl ByteLengthKernel for FSST {
21    fn byte_length(
22        array: ArrayView<'_, Self>,
23        _ctx: &mut ExecutionCtx,
24    ) -> VortexResult<Option<ArrayRef>> {
25        let nullable = array.dtype().nullability();
26        let dtype = DType::Primitive(PType::U64, nullable);
27        // Uncompressed lengths are non-nullable and may be less than u64 each
28        let lengths = array.uncompressed_lengths().cast(dtype.clone())?;
29        Ok(Some(match FSST::validity(array)? {
30            Validity::NonNullable | Validity::AllValid => lengths,
31            Validity::Array(v) => lengths.mask(v)?,
32            Validity::AllInvalid => {
33                ConstantArray::new(Scalar::null(dtype), lengths.len()).into_array()
34            }
35        }))
36    }
37}