Skip to main content

vortex_onpair/compute/
slice.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3//
4//! Slicing an `OnPairArray` reuses the same dictionary blob, the full
5//! `codes` child, and the full `dict_offsets` child. Only the
6//! `codes_offsets` child (narrowed to `[start, end + 1)`), the
7//! `uncompressed_lengths` child (narrowed to `[start, end)`) and the
8//! optional validity child change. No decode, no re-training.
9
10use std::ops::Range;
11
12use vortex_array::ArrayRef;
13use vortex_array::ArrayView;
14use vortex_array::IntoArray;
15use vortex_array::arrays::slice::SliceReduce;
16use vortex_error::VortexResult;
17
18use crate::OnPair;
19use crate::OnPairArrayExt;
20use crate::OnPairArraySlotsExt;
21
22impl SliceReduce for OnPair {
23    fn slice(array: ArrayView<'_, Self>, range: Range<usize>) -> VortexResult<Option<ArrayRef>> {
24        let codes_offsets = array.codes_offsets().slice(range.start..range.end + 1)?;
25        let uncompressed_lengths = array.uncompressed_lengths().slice(range.clone())?;
26        let validity = array.array_validity().slice(range)?;
27        Ok(Some(
28            unsafe {
29                OnPair::new_unchecked(
30                    array.dtype().clone(),
31                    array.dict_bytes_handle().clone(),
32                    array.dict_offsets().clone(),
33                    array.codes().clone(),
34                    codes_offsets,
35                    uncompressed_lengths,
36                    validity,
37                    array.bits(),
38                )
39            }
40            .into_array(),
41        ))
42    }
43}