vortex_array/execution/
batch.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5use vortex_vector::Vector;
6
7use crate::ArrayRef;
8
9/// Type-alias for heap-allocated batch execution kernels.
10pub type BatchKernelRef = Box<dyn BatchKernel>;
11
12/// Trait for batch execution kernels that produce a vector result.
13pub trait BatchKernel: 'static + Send {
14    fn execute(self: Box<Self>) -> VortexResult<Vector>;
15}
16
17/// Adapter to create a batch kernel from a closure.
18pub struct BatchKernelAdapter<F>(F);
19impl<F: FnOnce() -> VortexResult<Vector> + Send + 'static> BatchKernel for BatchKernelAdapter<F> {
20    fn execute(self: Box<Self>) -> VortexResult<Vector> {
21        self.0()
22    }
23}
24
25/// Create a batch execution kernel from the given closure.
26#[inline(always)]
27pub fn kernel<F: FnOnce() -> VortexResult<Vector> + Send + 'static>(f: F) -> BatchKernelRef {
28    Box::new(BatchKernelAdapter(f))
29}
30
31/// Context for binding batch execution kernels.
32///
33/// By binding child arrays through this context, we can perform common subtree elimination and
34/// share canonicalized results across multiple kernels.
35pub trait BindCtx {
36    /// Bind the given array and optional selection to produce a batch kernel, possibly reusing
37    /// previously bound results from this context.
38    fn bind(
39        &mut self,
40        array: &ArrayRef,
41        selection: Option<&ArrayRef>,
42    ) -> VortexResult<BatchKernelRef>;
43}