vortex_array/arrays/scalar_fn/vtable/
operations.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::ops::Range;
5
6use vortex_error::VortexExpect;
7use vortex_scalar::Scalar;
8use vortex_vector::Datum;
9
10use crate::ArrayRef;
11use crate::IntoArray;
12use crate::arrays::scalar_fn::array::ScalarFnArray;
13use crate::arrays::scalar_fn::vtable::ScalarFnVTable;
14use crate::expr::functions::ExecutionArgs;
15use crate::vtable::OperationsVTable;
16
17impl OperationsVTable<ScalarFnVTable> for ScalarFnVTable {
18    fn slice(array: &ScalarFnArray, range: Range<usize>) -> ArrayRef {
19        let children: Vec<_> = array
20            .children()
21            .iter()
22            .map(|c| c.slice(range.clone()))
23            .collect();
24
25        ScalarFnArray {
26            vtable: array.vtable.clone(),
27            scalar_fn: array.scalar_fn.clone(),
28            dtype: array.dtype.clone(),
29            len: range.len(),
30            children,
31            stats: Default::default(),
32        }
33        .into_array()
34    }
35
36    fn scalar_at(array: &ScalarFnArray, index: usize) -> Scalar {
37        // TODO(ngates): we should evaluate the scalar function over the scalar inputs.
38        let input_datums: Vec<_> = array
39            .children()
40            .iter()
41            .map(|c| c.scalar_at(index))
42            .map(|scalar| Datum::from(scalar.to_vector_scalar()))
43            .collect();
44
45        let ctx = ExecutionArgs::new(
46            1,
47            array.dtype.clone(),
48            array.children().iter().map(|s| s.dtype().clone()).collect(),
49            input_datums,
50        );
51
52        let _result = array
53            .scalar_fn
54            .execute(&ctx)
55            .vortex_expect("Scalar function execution should be fallible")
56            .into_scalar()
57            .vortex_expect("Scalar function execution should return scalar");
58
59        // Convert the vector scalar back into a legacy Scalar for now.
60        todo!("Implement legacy scalar conversion")
61    }
62}