Skip to content

Commit

Permalink
Added support for ScalarUDFImpl::invoke_with_return_type where the …
Browse files Browse the repository at this point in the history
…invoke is passed the return type created for the udf instance
  • Loading branch information
joseph-isaacs committed Nov 7, 2024
1 parent b0b6e44 commit de67c44
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions datafusion/expr/src/udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ impl ScalarUDF {
self.inner.simplify(args, info)
}

/// Invoke the function on `args`, returning the appropriate result.
///
/// See [`ScalarUDFImpl::invoke`] for more details.
#[deprecated(since = "42.1.0", note = "Use `invoke_batch` instead")]
pub fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {
#[allow(deprecated)]
Expand All @@ -227,6 +224,19 @@ impl ScalarUDF {
self.inner.invoke_batch(args, number_rows)
}

/// Invoke the function on `args`, returning the appropriate result.
///
/// See [`ScalarUDFImpl::invoke_batch`] for more details.
pub fn invoke_with_return_type(
&self,
args: &[ColumnarValue],
number_rows: usize,
return_type: &DataType,
) -> Result<ColumnarValue> {
self.inner
.invoke_batch_with_return_type(args, number_rows, return_type)
}

/// Invoke the function without `args` but number of rows, returning the appropriate result.
///
/// See [`ScalarUDFImpl::invoke_no_args`] for more details.
Expand Down Expand Up @@ -356,7 +366,7 @@ where
/// }
/// }
/// }
///
///
/// static DOCUMENTATION: OnceLock<Documentation> = OnceLock::new();
///
/// fn get_doc() -> &'static Documentation {
Expand Down Expand Up @@ -537,6 +547,17 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
}
}

/// 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_batch_with_return_type(
&self,
args: &[ColumnarValue],
number_rows: usize,
_return_type: &DataType,
) -> Result<ColumnarValue> {
self.invoke_batch(args, number_rows)
}

/// Invoke the function without `args`, instead the number of rows are provided,
/// returning the appropriate result.
#[deprecated(since = "42.1.0", note = "Use `invoke_batch` instead")]
Expand Down

0 comments on commit de67c44

Please sign in to comment.