Skip to content

Commit f677e59

Browse files
committed
Implement RowFn batch execution
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent be53543 commit f677e59

20 files changed

Lines changed: 2559 additions & 10 deletions

File tree

‎vortex-array/src/scalar_fn/mod.rs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
//! implementations. Expressions ([`crate::expr::Expression`]) reference scalar functions
88
//! at each node.
99
//!
10-
//! `unstable::row` defines experimental contracts for strict functions whose natural kernel
11-
//! computes one row at a time. This API requires the `unstable_row_fns` feature and has no
12-
//! compatibility guarantees.
10+
//! Use `unstable::row::RowFn` for strict functions whose natural kernel computes one row at a
11+
//! time. It derives decoding, constant handling, null propagation, output construction, and
12+
//! validity. This experimental API requires the `unstable_row_fns` feature and has no compatibility
13+
//! guarantees. Implement [`ScalarFnVTable`] directly when the natural kernel is columnar, aliases
14+
//! an input, or may produce null from otherwise valid inputs.
1315
1416
use vortex_session::registry::Id;
1517

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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

Comments
 (0)