Skip to main content

vortex_array/arrays/struct_/vtable/
operations.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5
6use crate::DynArray;
7use crate::ExecutionCtx;
8use crate::arrays::Struct;
9use crate::arrays::StructArray;
10use crate::scalar::Scalar;
11use crate::vtable::OperationsVTable;
12
13impl OperationsVTable<Struct> for Struct {
14    fn scalar_at(
15        array: &StructArray,
16        index: usize,
17        _ctx: &mut ExecutionCtx,
18    ) -> VortexResult<Scalar> {
19        let field_scalars: VortexResult<Vec<Scalar>> = array
20            .unmasked_fields()
21            .iter()
22            .map(|field| field.scalar_at(index))
23            .collect();
24        // SAFETY: The vtable guarantees index is in-bounds and non-null before this is called.
25        // Each field's scalar_at returns a scalar with the field's own dtype.
26        Ok(unsafe { Scalar::struct_unchecked(array.dtype().clone(), field_scalars?) })
27    }
28}