pub struct LambdaArgument { /* private fields */ }Expand description
A lambda argument to a HigherOrderFunction
Implementations§
Source§impl LambdaArgument
impl LambdaArgument
pub fn new( params: Vec<FieldRef>, body: Arc<dyn PhysicalExpr>, captures: Option<RecordBatch>, ) -> Self
Sourcepub fn evaluate(
&self,
args: &[&dyn Fn() -> Result<ArrayRef>],
spread_captures: impl FnOnce(&[ArrayRef]) -> Result<Vec<ArrayRef>>,
) -> Result<ColumnarValue>
pub fn evaluate( &self, args: &[&dyn Fn() -> Result<ArrayRef>], spread_captures: impl FnOnce(&[ArrayRef]) -> Result<Vec<ArrayRef>>, ) -> Result<ColumnarValue>
Evaluate this lambda
args should evaluate to the value of each parameter
of the correspondent lambda returned in HigherOrderUDFImpl::lambda_parameters.
spread_captures is responsible for transforming the captured column arrays
so they align with the evaluation batch. Captures are snapshotted from the
outer batch at construction time, giving one value per outer row, but the
function may evaluate the lambda body over a batch with a different number
of rows. It is the function’s responsibility to provide the appropriate
spread_captures closure to expand (or otherwise reshape) the captures
to match.
Taking as an example the following table:
CREATE TABLE t (arr INT[], a INT) AS VALUES
([1, 2, 3], 10),
([], 20),
([4], 30);SELECT array_transform(arr, v -> v + a) from t would execute over three outer rows:
arr (ListArray): [[1, 2, 3], [], [4]] -- 3 outer rows, 4 total elements
a (captured): [10, 20, 30] -- one value per outer rowarray_transform flattens the list elements into a single batch of 4 rows,
so spread_captures must repeat/drop captured values to match:
v (flattened args): [1, 2, 3, 4]
a (spread): [10, 10, 10, 30] -- 10 repeated for 3 elements in row 0,
-- 20 dropped for the empty sublist in row 1,
-- 30 once for the single element in row 2The lambda body v + a then evaluates element-wise over these 4-row arrays,
producing [11, 12, 13, 34], which array_transform reassembles into [[11, 12, 13], [], [34]].
If the lambda has no captures, spread_captures is never called.
Trait Implementations§
Source§impl Clone for LambdaArgument
impl Clone for LambdaArgument
Source§fn clone(&self) -> LambdaArgument
fn clone(&self) -> LambdaArgument
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for LambdaArgument
impl !UnwindSafe for LambdaArgument
impl Freeze for LambdaArgument
impl Send for LambdaArgument
impl Sync for LambdaArgument
impl Unpin for LambdaArgument
impl UnsafeUnpin for LambdaArgument
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more