vortex_fsst/
ops.rs

1use vortex_array::arrays::{VarBinVTable, varbin_scalar};
2use vortex_array::vtable::OperationsVTable;
3use vortex_array::{Array, ArrayRef, IntoArray};
4use vortex_buffer::ByteBuffer;
5use vortex_error::{VortexResult, vortex_err};
6use vortex_scalar::Scalar;
7
8use crate::{FSSTArray, FSSTVTable};
9
10impl OperationsVTable<FSSTVTable> for FSSTVTable {
11    fn slice(array: &FSSTArray, start: usize, stop: usize) -> VortexResult<ArrayRef> {
12        // Slicing an FSST array leaves the symbol table unmodified,
13        // only slicing the `codes` array.
14        Ok(FSSTArray::try_new(
15            array.dtype().clone(),
16            array.symbols().clone(),
17            array.symbol_lengths().clone(),
18            array
19                .codes()
20                .slice(start, stop)?
21                .as_::<VarBinVTable>()
22                .clone(),
23            array.uncompressed_lengths().slice(start, stop)?,
24        )?
25        .into_array())
26    }
27
28    fn scalar_at(array: &FSSTArray, index: usize) -> VortexResult<Scalar> {
29        let compressed = array.codes().scalar_at(index)?;
30        let binary_datum = compressed
31            .as_binary()
32            .value()
33            .ok_or_else(|| vortex_err!("expected null to already be handled"))?;
34
35        let decoded_buffer =
36            ByteBuffer::from(array.decompressor().decompress(binary_datum.as_slice()));
37        Ok(varbin_scalar(decoded_buffer, array.dtype()))
38    }
39}