|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +// SPDX-FileCopyrightText: Copyright the Vortex contributors |
| 3 | + |
| 4 | +//! A borrowed execution view passed to one row-kernel invocation. |
| 5 | +
|
| 6 | +use vortex_error::VortexResult; |
| 7 | +use vortex_error::vortex_err; |
| 8 | + |
| 9 | +use crate::ArrayRef; |
| 10 | +use crate::dtype::DType; |
| 11 | +use crate::scalar_fn::ExecutionArgs; |
| 12 | + |
| 13 | +/// A borrowed [`ExecutionArgs`] view with the planning metadata selected for its row kernel. |
| 14 | +/// |
| 15 | +/// `arrays` may be filtered or sliced, while `dtypes` and `output_dtype` always describe the |
| 16 | +/// original planned batch. Keeping them together prevents an execution path from pairing an input |
| 17 | +/// view with unrelated planning metadata. |
| 18 | +#[derive(Clone, Copy)] |
| 19 | +pub(in crate::scalar_fn::unstable::row) struct BorrowedExecutionArgs<'a> { |
| 20 | + /// The input arrays for this kernel invocation. |
| 21 | + arrays: &'a [ArrayRef], |
| 22 | + |
| 23 | + /// The number of rows in this kernel invocation. |
| 24 | + row_count: usize, |
| 25 | + |
| 26 | + /// The original input dtypes used to select the row implementation. |
| 27 | + dtypes: &'a [DType], |
| 28 | + |
| 29 | + /// The non-nullable dtype built by the selected output capability. |
| 30 | + output_dtype: &'a DType, |
| 31 | +} |
| 32 | + |
| 33 | +impl<'a> BorrowedExecutionArgs<'a> { |
| 34 | + /// Pair one input view with the planning metadata selected for its batch. |
| 35 | + pub(in crate::scalar_fn::unstable::row) fn new( |
| 36 | + arrays: &'a [ArrayRef], |
| 37 | + row_count: usize, |
| 38 | + dtypes: &'a [DType], |
| 39 | + output_dtype: &'a DType, |
| 40 | + ) -> Self { |
| 41 | + Self { |
| 42 | + arrays, |
| 43 | + row_count, |
| 44 | + dtypes, |
| 45 | + output_dtype, |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + /// Return the concrete arrays used by encoding-aware execution. |
| 50 | + pub(in crate::scalar_fn::unstable::row) fn arrays(&self) -> &'a [ArrayRef] { |
| 51 | + self.arrays |
| 52 | + } |
| 53 | + |
| 54 | + /// Return the original input dtypes used to select the row implementation. |
| 55 | + pub(in crate::scalar_fn::unstable::row) fn dtypes(&self) -> &'a [DType] { |
| 56 | + self.dtypes |
| 57 | + } |
| 58 | + |
| 59 | + /// Return the non-nullable dtype built by the selected output capability. |
| 60 | + pub(in crate::scalar_fn::unstable::row) fn output_dtype(&self) -> &'a DType { |
| 61 | + self.output_dtype |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +impl ExecutionArgs for BorrowedExecutionArgs<'_> { |
| 66 | + fn get(&self, index: usize) -> VortexResult<ArrayRef> { |
| 67 | + self.arrays.get(index).cloned().ok_or_else(|| { |
| 68 | + vortex_err!( |
| 69 | + "row-function input index must be less than {}, got {index}", |
| 70 | + self.arrays.len(), |
| 71 | + ) |
| 72 | + }) |
| 73 | + } |
| 74 | + |
| 75 | + fn num_inputs(&self) -> usize { |
| 76 | + self.arrays.len() |
| 77 | + } |
| 78 | + |
| 79 | + fn row_count(&self) -> usize { |
| 80 | + self.row_count |
| 81 | + } |
| 82 | +} |
0 commit comments