Skip to content

Commit

Permalink
Add SimpleScalarUDF::new_with_signature (#13592)
Browse files Browse the repository at this point in the history
* Add SimpleScalarUDF::new_with_signature

This is helpful for simple function implementations or function stubs,
when `Signature::exact` is not desired.

* Add/update doc strings
  • Loading branch information
findepi authored Nov 30, 2024
1 parent 8ae36b7 commit 523a455
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions datafusion/expr/src/expr_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,24 @@ impl SimpleScalarUDF {
volatility: Volatility,
fun: ScalarFunctionImplementation,
) -> Self {
let name = name.into();
let signature = Signature::exact(input_types, volatility);
Self {
Self::new_with_signature(
name,
Signature::exact(input_types, volatility),
return_type,
fun,
)
}

/// Create a new `SimpleScalarUDF` from a name, signature, return type and
/// implementation. Implementing [`ScalarUDFImpl`] allows more flexibility
pub fn new_with_signature(
name: impl Into<String>,
signature: Signature,
return_type: DataType,
fun: ScalarFunctionImplementation,
) -> Self {
Self {
name: name.into(),
signature,
return_type,
fun,
Expand Down Expand Up @@ -519,7 +533,7 @@ impl Debug for SimpleAggregateUDF {
}

impl SimpleAggregateUDF {
/// Create a new `AggregateUDFImpl` from a name, input types, return type, state type and
/// Create a new `SimpleAggregateUDF` from a name, input types, return type, state type and
/// implementation. Implementing [`AggregateUDFImpl`] allows more flexibility
pub fn new(
name: impl Into<String>,
Expand All @@ -540,6 +554,8 @@ impl SimpleAggregateUDF {
}
}

/// Create a new `SimpleAggregateUDF` from a name, signature, return type, state type and
/// implementation. Implementing [`AggregateUDFImpl`] allows more flexibility
pub fn new_with_signature(
name: impl Into<String>,
signature: Signature,
Expand Down

0 comments on commit 523a455

Please sign in to comment.