vortex_fsst/
ops.rs

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