Skip to main content

LambdaArgument

Struct LambdaArgument 

Source
pub struct LambdaArgument { /* private fields */ }
Expand description

A lambda argument to a HigherOrderFunction

Implementations§

Source§

impl LambdaArgument

Source

pub fn new( params: Vec<FieldRef>, body: Arc<dyn PhysicalExpr>, captures: Option<RecordBatch>, ) -> Self

Source

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 row

array_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 2

The 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

Source§

fn clone(&self) -> LambdaArgument

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LambdaArgument

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.