vortex_fsst/
ops.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::ops::Range;
5
6use vortex_array::Array;
7use vortex_array::ArrayRef;
8use vortex_array::IntoArray;
9use vortex_array::arrays::VarBinVTable;
10use vortex_array::arrays::varbin_scalar;
11use vortex_array::vtable::OperationsVTable;
12use vortex_buffer::ByteBuffer;
13use vortex_error::VortexExpect;
14use vortex_scalar::Scalar;
15
16use crate::FSSTArray;
17use crate::FSSTVTable;
18
19impl OperationsVTable<FSSTVTable> for FSSTVTable {
20    fn slice(array: &FSSTArray, range: Range<usize>) -> ArrayRef {
21        // SAFETY: slicing the `codes` leaves the symbol table intact
22        unsafe {
23            FSSTArray::new_unchecked(
24                array.dtype().clone(),
25                array.symbols().clone(),
26                array.symbol_lengths().clone(),
27                array
28                    .codes()
29                    .slice(range.clone())
30                    .as_::<VarBinVTable>()
31                    .clone(),
32                array.uncompressed_lengths().slice(range),
33            )
34            .into_array()
35        }
36    }
37
38    fn scalar_at(array: &FSSTArray, index: usize) -> Scalar {
39        let compressed = array.codes().scalar_at(index);
40        let binary_datum = compressed.as_binary().value().vortex_expect("non-null");
41
42        let decoded_buffer =
43            ByteBuffer::from(array.decompressor().decompress(binary_datum.as_slice()));
44        varbin_scalar(decoded_buffer, array.dtype())
45    }
46}