20
20
use crate :: expr:: schema_name_from_exprs_comma_seperated_without_space;
21
21
use crate :: simplify:: { ExprSimplifyResult , SimplifyInfo } ;
22
22
use crate :: sort_properties:: { ExprProperties , SortProperties } ;
23
- use crate :: {
24
- ColumnarValue , Documentation , Expr , ScalarFunctionImplementation , Signature ,
25
- } ;
23
+ use crate :: { ColumnarValue , Documentation , Expr , Signature } ;
26
24
use arrow:: datatypes:: DataType ;
27
25
use datafusion_common:: { not_impl_err, ExprSchema , Result } ;
28
26
use datafusion_expr_common:: interval_arithmetic:: Interval ;
@@ -203,12 +201,6 @@ impl ScalarUDF {
203
201
self . inner . simplify ( args, info)
204
202
}
205
203
206
- #[ deprecated( since = "42.1.0" , note = "Use `invoke_batch` instead" ) ]
207
- pub fn invoke ( & self , args : & [ ColumnarValue ] ) -> Result < ColumnarValue > {
208
- #[ allow( deprecated) ]
209
- self . inner . invoke ( args)
210
- }
211
-
212
204
pub fn is_nullable ( & self , args : & [ Expr ] , schema : & dyn ExprSchema ) -> bool {
213
205
self . inner . is_nullable ( args, schema)
214
206
}
@@ -225,27 +217,9 @@ impl ScalarUDF {
225
217
226
218
/// Invoke the function on `args`, returning the appropriate result.
227
219
///
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
-
233
- /// Invoke the function without `args` but number of rows, returning the appropriate result.
234
- ///
235
- /// See [`ScalarUDFImpl::invoke_no_args`] for more details.
236
- #[ deprecated( since = "42.1.0" , note = "Use `invoke_batch` instead" ) ]
237
- pub fn invoke_no_args ( & self , number_rows : usize ) -> Result < ColumnarValue > {
238
- #[ allow( deprecated) ]
239
- self . inner . invoke_no_args ( number_rows)
240
- }
241
-
242
- /// Returns a `ScalarFunctionImplementation` that can invoke the function
243
- /// during execution
244
- #[ deprecated( since = "42.0.0" , note = "Use `invoke_batch` instead" ) ]
245
- pub fn fun ( & self ) -> ScalarFunctionImplementation {
246
- let captured = Arc :: clone ( & self . inner ) ;
247
- #[ allow( deprecated) ]
248
- Arc :: new ( move |args| captured. invoke ( args) )
220
+ /// See [`ScalarUDFImpl::invoke`] for more details.
221
+ pub fn invoke ( & self , args : ScalarFunctionArgs ) -> Result < ColumnarValue > {
222
+ self . inner . invoke ( args)
249
223
}
250
224
251
225
/// Get the circuits of inner implementation
@@ -329,7 +303,7 @@ where
329
303
330
304
pub struct ScalarFunctionArgs < ' a > {
331
305
// The evaluated arguments to the function
332
- pub args : & ' a [ ColumnarValue ] ,
306
+ pub args : Vec < ColumnarValue > ,
333
307
// The number of rows in record batch being evaluated
334
308
pub number_rows : usize ,
335
309
// The return type of the scalar function returned (from `return_type` or `return_type_from_exprs`)
@@ -353,7 +327,7 @@ pub struct ScalarFunctionArgs<'a> {
353
327
/// # use std::sync::OnceLock;
354
328
/// # use arrow::datatypes::DataType;
355
329
/// # use datafusion_common::{DataFusionError, plan_err, Result};
356
- /// # use datafusion_expr::{col, ColumnarValue, Documentation, Signature, Volatility};
330
+ /// # use datafusion_expr::{col, ColumnarValue, Documentation, ScalarFunctionArgs, Signature, Volatility};
357
331
/// # use datafusion_expr::{ScalarUDFImpl, ScalarUDF};
358
332
/// # use datafusion_expr::scalar_doc_sections::DOC_SECTION_MATH;
359
333
///
@@ -396,7 +370,7 @@ pub struct ScalarFunctionArgs<'a> {
396
370
/// Ok(DataType::Int32)
397
371
/// }
398
372
/// // The actual implementation would add one to the argument
399
- /// fn invoke(&self, args: &[ColumnarValue] ) -> Result<ColumnarValue> { unimplemented!() }
373
+ /// fn invoke(&self, args: ScalarFunctionArgs ) -> Result<ColumnarValue> { unimplemented!() }
400
374
/// fn documentation(&self) -> Option<&Documentation> {
401
375
/// Some(get_doc())
402
376
/// }
@@ -490,33 +464,6 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
490
464
true
491
465
}
492
466
493
- /// Invoke the function on `args`, returning the appropriate result
494
- ///
495
- /// The function will be invoked passed with the slice of [`ColumnarValue`]
496
- /// (either scalar or array).
497
- ///
498
- /// If the function does not take any arguments, please use [invoke_no_args]
499
- /// instead and return [not_impl_err] for this function.
500
- ///
501
- ///
502
- /// # Performance
503
- ///
504
- /// For the best performance, the implementations of `invoke` should handle
505
- /// the common case when one or more of their arguments are constant values
506
- /// (aka [`ColumnarValue::Scalar`]).
507
- ///
508
- /// [`ColumnarValue::values_to_arrays`] can be used to convert the arguments
509
- /// to arrays, which will likely be simpler code, but be slower.
510
- ///
511
- /// [invoke_no_args]: ScalarUDFImpl::invoke_no_args
512
- #[ deprecated( since = "42.1.0" , note = "Use `invoke_batch` instead" ) ]
513
- fn invoke ( & self , _args : & [ ColumnarValue ] ) -> Result < ColumnarValue > {
514
- not_impl_err ! (
515
- "Function {} does not implement invoke but called" ,
516
- self . name( )
517
- )
518
- }
519
-
520
467
/// Invoke the function with `args` and the number of rows,
521
468
/// returning the appropriate result.
522
469
///
@@ -531,24 +478,15 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
531
478
///
532
479
/// [`ColumnarValue::values_to_arrays`] can be used to convert the arguments
533
480
/// to arrays, which will likely be simpler code, but be slower.
534
- #[ deprecated( since = "43.0.0" , note = "Use `invoke_with_args ` instead" ) ]
481
+ #[ deprecated( since = "43.0.0" , note = "Use `invoke ` instead" ) ]
535
482
fn invoke_batch (
536
483
& self ,
537
- args : & [ ColumnarValue ] ,
538
- number_rows : usize ,
484
+ _args : & [ ColumnarValue ] ,
485
+ _number_rows : usize ,
539
486
) -> Result < ColumnarValue > {
540
- match args. is_empty ( ) {
541
- true =>
542
- {
543
- #[ allow( deprecated) ]
544
- self . invoke_no_args ( number_rows)
545
- }
546
- false =>
547
- {
548
- #[ allow( deprecated) ]
549
- self . invoke ( args)
550
- }
551
- }
487
+ not_impl_err ! (
488
+ "invoke_batch, this method is deprecated implement `invoke` instead"
489
+ )
552
490
}
553
491
554
492
/// Invoke the function with `args: ScalarFunctionArgs` returning the appropriate result.
@@ -563,19 +501,11 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
563
501
///
564
502
/// [`ColumnarValue::values_to_arrays`] can be used to convert the arguments
565
503
/// to arrays, which will likely be simpler code, but be slower.
566
- fn invoke_with_args ( & self , args : ScalarFunctionArgs ) -> Result < ColumnarValue > {
504
+ /// Note that this invoke method replaces the original invoke function deprecated in
505
+ /// version = 42.1.0.
506
+ fn invoke ( & self , args : ScalarFunctionArgs ) -> Result < ColumnarValue > {
567
507
#[ allow( deprecated) ]
568
- self . invoke_batch ( args. args , args. number_rows )
569
- }
570
-
571
- /// Invoke the function without `args`, instead the number of rows are provided,
572
- /// returning the appropriate result.
573
- #[ deprecated( since = "42.1.0" , note = "Use `invoke_batch` instead" ) ]
574
- fn invoke_no_args ( & self , _number_rows : usize ) -> Result < ColumnarValue > {
575
- not_impl_err ! (
576
- "Function {} does not implement invoke_no_args but called" ,
577
- self . name( )
578
- )
508
+ self . invoke_batch ( args. args . as_slice ( ) , args. number_rows )
579
509
}
580
510
581
511
/// Returns any aliases (alternate names) for this function.
0 commit comments