Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for ScalarUDFImpl::invoke_with_return_type where the invoke is passed the return type created for the udf instance #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions datafusion/expr/src/udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ impl ScalarUDF {
/// Invoke the function on `args`, returning the appropriate result.
///
/// See [`ScalarUDFImpl::invoke`] for more details.
pub fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {
self.inner.invoke(args)
pub fn invoke_with_return_type(&self, args: &[ColumnarValue], return_type: &DataType) -> Result<ColumnarValue>{
self.inner.invoke_with_return_type(args, return_type)
}

pub fn is_nullable(&self, args: &[Expr], schema: &dyn ExprSchema) -> bool {
Expand Down Expand Up @@ -439,6 +439,12 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
/// [invoke_no_args]: ScalarUDFImpl::invoke_no_args
fn invoke(&self, _args: &[ColumnarValue]) -> Result<ColumnarValue>;

/// This function will be called with the evaluated children as in `invoke` however, the value
/// returned previously from `ScalarUDFImpl::return_type` for this expr will be passed in.
fn invoke_with_return_type(&self, args: &[ColumnarValue], _return_type: &DataType) -> Result<ColumnarValue>{
self.invoke(args)
}

/// Invoke the function without `args`, instead the number of rows are provided,
/// returning the appropriate result.
fn invoke_no_args(&self, _number_rows: usize) -> Result<ColumnarValue> {
Expand Down
2 changes: 1 addition & 1 deletion datafusion/physical-expr/src/scalar_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl PhysicalExpr for ScalarFunctionExpr {
// evaluate the function
let output = match self.args.is_empty() {
true => self.fun.invoke_no_args(batch.num_rows()),
false => self.fun.invoke(&inputs),
false => self.fun.invoke_with_return_type(&inputs, &self.return_type),
}?;

if let ColumnarValue::Array(array) = &output {
Expand Down