@@ -203,9 +203,6 @@ impl ScalarUDF {
203203 self . inner . simplify ( args, info)
204204 }
205205
206- /// Invoke the function on `args`, returning the appropriate result.
207- ///
208- /// See [`ScalarUDFImpl::invoke`] for more details.
209206 #[ deprecated( since = "42.1.0" , note = "Use `invoke_batch` instead" ) ]
210207 pub fn invoke ( & self , args : & [ ColumnarValue ] ) -> Result < ColumnarValue > {
211208 #[ allow( deprecated) ]
@@ -216,17 +213,23 @@ impl ScalarUDF {
216213 self . inner . is_nullable ( args, schema)
217214 }
218215
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" ) ]
222217 pub fn invoke_batch (
223218 & self ,
224219 args : & [ ColumnarValue ] ,
225220 number_rows : usize ,
226221 ) -> Result < ColumnarValue > {
222+ #[ allow( deprecated) ]
227223 self . inner . invoke_batch ( args, number_rows)
228224 }
229225
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+
230233 /// Invoke the function without `args` but number of rows, returning the appropriate result.
231234 ///
232235 /// See [`ScalarUDFImpl::invoke_no_args`] for more details.
@@ -324,6 +327,16 @@ where
324327 }
325328}
326329
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+
327340/// Trait for implementing [`ScalarUDF`].
328341///
329342/// This trait exposes the full API for implementing user defined functions and
@@ -356,7 +369,7 @@ where
356369/// }
357370/// }
358371/// }
359- ///
372+ ///
360373/// static DOCUMENTATION: OnceLock<Documentation> = OnceLock::new();
361374///
362375/// fn get_doc() -> &'static Documentation {
@@ -518,6 +531,7 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
518531 ///
519532 /// [`ColumnarValue::values_to_arrays`] can be used to convert the arguments
520533 /// to arrays, which will likely be simpler code, but be slower.
534+ #[ deprecated( since = "43.0.0" , note = "Use `invoke_with_args` instead" ) ]
521535 fn invoke_batch (
522536 & self ,
523537 args : & [ ColumnarValue ] ,
@@ -537,6 +551,23 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
537551 }
538552 }
539553
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+
540571 /// Invoke the function without `args`, instead the number of rows are provided,
541572 /// returning the appropriate result.
542573 #[ deprecated( since = "42.1.0" , note = "Use `invoke_batch` instead" ) ]
@@ -767,6 +798,7 @@ impl ScalarUDFImpl for AliasedScalarUDFImpl {
767798 args : & [ ColumnarValue ] ,
768799 number_rows : usize ,
769800 ) -> Result < ColumnarValue > {
801+ #[ allow( deprecated) ]
770802 self . inner . invoke_batch ( args, number_rows)
771803 }
772804
0 commit comments