@@ -262,25 +262,33 @@ impl LambdaArgument {
262262 /// `args` should evaluate to the value of each parameter
263263 /// of the correspondent lambda returned in [HigherOrderUDF::lambda_parameters].
264264 ///
265- /// `adjust` should adjust the captured columns of this
266- /// lambda, if any, relative to it's parameters
265+ /// `spread_captures` is responsible for transforming the captured column arrays
266+ /// so they align with the evaluation batch. Captures are snapshotted from the
267+ /// outer batch at construction time, giving one value per outer row, but the
268+ /// function may evaluate the lambda body over a batch with a different number
269+ /// of rows. It is the function responsibility to provide the appropriate `spread_captures`
270+ /// closure to expand (or otherwise reshape) the captures to match.
271+ /// Function working on lists, for example `array_transform(arr, v -> v + 1)`
272+ /// flattens all list elements into a single batch, duplicating captured
273+ /// values for rows with multiple elements and dropping them for empty lists.
274+ /// If the lambda has no captures, `spread_captures` is never called.
267275 pub fn evaluate (
268276 & self ,
269277 args : & [ & dyn Fn ( ) -> Result < ArrayRef > ] ,
270- adjust : impl FnOnce ( & [ ArrayRef ] ) -> Result < Vec < ArrayRef > > ,
278+ spread_captures : impl FnOnce ( & [ ArrayRef ] ) -> Result < Vec < ArrayRef > > ,
271279 ) -> Result < ColumnarValue > {
272- let adjusted_captures = self
280+ let spread_captures = self
273281 . captures
274282 . as_ref ( )
275283 . map ( |captures| {
276- let adjusted_columns = adjust ( captures. columns ( ) ) ?;
284+ let spread_columns = spread_captures ( captures. columns ( ) ) ?;
277285
278- RecordBatch :: try_new ( captures. schema ( ) , adjusted_columns )
286+ RecordBatch :: try_new ( captures. schema ( ) , spread_columns )
279287 } )
280288 . transpose ( ) ?;
281289
282290 let merged = merge_captures_with_variables (
283- adjusted_captures . as_ref ( ) ,
291+ spread_captures . as_ref ( ) ,
284292 Arc :: clone ( & self . schema ) ,
285293 & self . params ,
286294 args,
0 commit comments