mod compare;
use vortex_array::array::varbin_scalar;
use vortex_array::compute::{
filter, scalar_at, slice, take, CompareFn, ComputeVTable, FilterFn, FilterMask, ScalarAtFn,
SliceFn, TakeFn,
};
use vortex_array::{ArrayDType, ArrayData, IntoArrayData};
use vortex_buffer::Buffer;
use vortex_error::{vortex_err, VortexResult};
use vortex_scalar::Scalar;
use crate::{FSSTArray, FSSTEncoding};
impl ComputeVTable for FSSTEncoding {
fn compare_fn(&self) -> Option<&dyn CompareFn<ArrayData>> {
Some(self)
}
fn filter_fn(&self) -> Option<&dyn FilterFn<ArrayData>> {
Some(self)
}
fn scalar_at_fn(&self) -> Option<&dyn ScalarAtFn<ArrayData>> {
Some(self)
}
fn slice_fn(&self) -> Option<&dyn SliceFn<ArrayData>> {
Some(self)
}
fn take_fn(&self) -> Option<&dyn TakeFn<ArrayData>> {
Some(self)
}
}
impl SliceFn<FSSTArray> for FSSTEncoding {
fn slice(&self, array: &FSSTArray, start: usize, stop: usize) -> VortexResult<ArrayData> {
Ok(FSSTArray::try_new(
array.dtype().clone(),
array.symbols(),
array.symbol_lengths(),
slice(array.codes(), start, stop)?,
slice(array.uncompressed_lengths(), start, stop)?,
)?
.into_array())
}
}
impl TakeFn<FSSTArray> for FSSTEncoding {
fn take(&self, array: &FSSTArray, indices: &ArrayData) -> VortexResult<ArrayData> {
Ok(FSSTArray::try_new(
array.dtype().clone(),
array.symbols(),
array.symbol_lengths(),
take(array.codes(), indices)?,
take(array.uncompressed_lengths(), indices)?,
)?
.into_array())
}
}
impl ScalarAtFn<FSSTArray> for FSSTEncoding {
fn scalar_at(&self, array: &FSSTArray, index: usize) -> VortexResult<Scalar> {
let compressed = scalar_at(array.codes(), index)?;
let binary_datum = compressed
.as_binary()
.value()
.ok_or_else(|| vortex_err!("expected null to already be handled"))?;
array.with_decompressor(|decompressor| {
let decoded_buffer: Buffer = decompressor.decompress(binary_datum.as_slice()).into();
Ok(varbin_scalar(decoded_buffer, array.dtype()))
})
}
}
impl FilterFn<FSSTArray> for FSSTEncoding {
fn filter(&self, array: &FSSTArray, mask: FilterMask) -> VortexResult<ArrayData> {
Ok(FSSTArray::try_new(
array.dtype().clone(),
array.symbols(),
array.symbol_lengths(),
filter(&array.codes(), mask.clone())?,
filter(&array.uncompressed_lengths(), mask)?,
)?
.into_array())
}
}