1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use vortex_dtype::match_each_native_ptype;
use vortex_error::VortexResult;
use vortex_scalar::Scalar;

use crate::array::primitive::PrimitiveArray;
use crate::array::PrimitiveEncoding;
use crate::compute::ScalarAtFn;
use crate::variants::PrimitiveArrayTrait;
use crate::ArrayDType;

impl ScalarAtFn<PrimitiveArray> for PrimitiveEncoding {
    fn scalar_at(&self, array: &PrimitiveArray, index: usize) -> VortexResult<Scalar> {
        Ok(match_each_native_ptype!(array.ptype(), |$T| {
            Scalar::primitive(array.maybe_null_slice::<$T>()[index], array.dtype().nullability())
        }))
    }
}