@@ -203,9 +203,6 @@ impl ScalarUDF {
203
203
self . inner . simplify ( args, info)
204
204
}
205
205
206
- /// Invoke the function on `args`, returning the appropriate result.
207
- ///
208
- /// See [`ScalarUDFImpl::invoke`] for more details.
209
206
#[ deprecated( since = "42.1.0" , note = "Use `invoke_batch` instead" ) ]
210
207
pub fn invoke ( & self , args : & [ ColumnarValue ] ) -> Result < ColumnarValue > {
211
208
#[ allow( deprecated) ]
@@ -216,17 +213,23 @@ impl ScalarUDF {
216
213
self . inner . is_nullable ( args, schema)
217
214
}
218
215
219
- /// Invoke the function with `args` and number of rows, returning the appropriate result.
220
- ///
221
- /// See [`ScalarUDFImpl::invoke_batch`] for more details.
216
+ #[ deprecated( since = "43.0.0" , note = "Use `invoke_batch` instead" ) ]
222
217
pub fn invoke_batch (
223
218
& self ,
224
219
args : & [ ColumnarValue ] ,
225
220
number_rows : usize ,
226
221
) -> Result < ColumnarValue > {
222
+ #[ allow( deprecated) ]
227
223
self . inner . invoke_batch ( args, number_rows)
228
224
}
229
225
226
+ /// Invoke the function on `args`, returning the appropriate result.
227
+ ///
228
+ /// See [`ScalarUDFImpl::invoke_with_args`] for more details.
229
+ pub fn invoke_with_args ( & self , args : ScalarFunctionArgs ) -> Result < ColumnarValue > {
230
+ self . inner . invoke_with_args ( args)
231
+ }
232
+
230
233
/// Invoke the function without `args` but number of rows, returning the appropriate result.
231
234
///
232
235
/// See [`ScalarUDFImpl::invoke_no_args`] for more details.
@@ -324,6 +327,16 @@ where
324
327
}
325
328
}
326
329
330
+ pub struct ScalarFunctionArgs < ' a > {
331
+ // The evaluated arguments to the function
332
+ pub args : & ' a [ ColumnarValue ] ,
333
+ // The number of rows in record batch being evaluated
334
+ pub number_rows : usize ,
335
+ // The return type of the scalar function returned (from `return_type` or `return_type_from_exprs`)
336
+ // when creating the physical expression from the logical expression
337
+ pub return_type : & ' a DataType ,
338
+ }
339
+
327
340
/// Trait for implementing [`ScalarUDF`].
328
341
///
329
342
/// This trait exposes the full API for implementing user defined functions and
@@ -356,7 +369,7 @@ where
356
369
/// }
357
370
/// }
358
371
/// }
359
- ///
372
+ ///
360
373
/// static DOCUMENTATION: OnceLock<Documentation> = OnceLock::new();
361
374
///
362
375
/// fn get_doc() -> &'static Documentation {
@@ -518,6 +531,7 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
518
531
///
519
532
/// [`ColumnarValue::values_to_arrays`] can be used to convert the arguments
520
533
/// to arrays, which will likely be simpler code, but be slower.
534
+ #[ deprecated( since = "43.0.0" , note = "Use `invoke_with_args` instead" ) ]
521
535
fn invoke_batch (
522
536
& self ,
523
537
args : & [ ColumnarValue ] ,
@@ -537,6 +551,23 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
537
551
}
538
552
}
539
553
554
+ /// Invoke the function with `args: ScalarFunctionArgs` returning the appropriate result.
555
+ ///
556
+ /// The function will be invoked with a struct `ScalarFunctionArgs`
557
+ ///
558
+ /// # Performance
559
+ ///
560
+ /// For the best performance, the implementations should handle the common case
561
+ /// when one or more of their arguments are constant values (aka
562
+ /// [`ColumnarValue::Scalar`]).
563
+ ///
564
+ /// [`ColumnarValue::values_to_arrays`] can be used to convert the arguments
565
+ /// to arrays, which will likely be simpler code, but be slower.
566
+ fn invoke_with_args ( & self , args : ScalarFunctionArgs ) -> Result < ColumnarValue > {
567
+ #[ allow( deprecated) ]
568
+ self . invoke_batch ( args. args , args. number_rows )
569
+ }
570
+
540
571
/// Invoke the function without `args`, instead the number of rows are provided,
541
572
/// returning the appropriate result.
542
573
#[ deprecated( since = "42.1.0" , note = "Use `invoke_batch` instead" ) ]
@@ -767,6 +798,7 @@ impl ScalarUDFImpl for AliasedScalarUDFImpl {
767
798
args : & [ ColumnarValue ] ,
768
799
number_rows : usize ,
769
800
) -> Result < ColumnarValue > {
801
+ #[ allow( deprecated) ]
770
802
self . inner . invoke_batch ( args, number_rows)
771
803
}
772
804
0 commit comments