Skip to main content

vortex_onpair/compute/
byte_length.rs

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