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