Skip to content

Commit

Permalink
update naming
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-isaacs committed Nov 13, 2024
1 parent f0a2bf5 commit 3fc9775
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
8 changes: 3 additions & 5 deletions datafusion/expr/src/udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ impl ScalarUDF {
self.inner.is_nullable(args, schema)
}

/// Invoke the function with `args` and number of rows, returning the appropriate result.
///
/// See [`ScalarUDFImpl::invoke_batch`] for more details.
#[deprecated(since = "43.0.0", note = "Use `invoke_batch` instead")]
pub fn invoke_batch(
&self,
args: &[ColumnarValue],
Expand All @@ -226,7 +224,7 @@ impl ScalarUDF {

/// Invoke the function on `args`, returning the appropriate result.
///
/// See [`ScalarUDFImpl::invoke_batch`] for more details.
/// See [`ScalarUDFImpl::invoke_with_args`] for more details.
pub fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
self.inner.invoke_with_args(args)
}
Expand Down Expand Up @@ -330,7 +328,7 @@ where

pub struct ScalarFunctionArgs<'a> {
// The evaluated arguments to the function
pub args: &'a Vec<ColumnarValue>,
pub args: &'a [ColumnarValue],
// The number of rows in record batch being evaluated
pub number_rows: usize,
// The return type of the scalar function returned (from `return_type` or `return_type_from_exprs`)
Expand Down
8 changes: 6 additions & 2 deletions datafusion/functions/src/datetime/to_local_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ mod tests {
use arrow::datatypes::{DataType, TimeUnit};
use chrono::NaiveDateTime;
use datafusion_common::ScalarValue;
use datafusion_expr::{ColumnarValue, ScalarUDFImpl};
use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl};

use super::{adjust_to_local_time, ToLocalTimeFunc};

Expand Down Expand Up @@ -558,7 +558,11 @@ mod tests {

fn test_to_local_time_helper(input: ScalarValue, expected: ScalarValue) {
let res = ToLocalTimeFunc::new()
.invoke_batch(&[ColumnarValue::Scalar(input)], 1)
.invoke_with_args(ScalarFunctionArgs {
args: &vec![ColumnarValue::Scalar(input)],
number_rows: 1,
return_type: &expected.data_type(),
})
.unwrap();
match res {
ColumnarValue::Scalar(res) => {
Expand Down
1 change: 1 addition & 0 deletions datafusion/functions/src/math/signum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ mod test {
f32::NEG_INFINITY,
]));
let batch_size = array.len();
#[allow(deprecated)] // TODO: migrate to invoke_with_args
let result = SignumFunc::new()
.invoke_batch(&[ColumnarValue::Array(array)], batch_size)
.expect("failed to initialize function signum");
Expand Down
8 changes: 5 additions & 3 deletions datafusion/functions/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ pub mod test {
match expected {
Ok(expected) => {
assert_eq!(return_type.is_ok(), true);
assert_eq!(return_type.unwrap(), $EXPECTED_DATA_TYPE);
let return_type = return_type.unwrap();
assert_eq!(return_type, $EXPECTED_DATA_TYPE);

let result = func.invoke_batch($ARGS, cardinality);
let result = func.invoke_with_args(datafusion_expr::ScalarFunctionArgs{args: $ARGS, number_rows: cardinality, return_type: &return_type});
assert_eq!(result.is_ok(), true, "function returned an error: {}", result.unwrap_err());

let result = result.unwrap().clone().into_array(cardinality).expect("Failed to convert to array");
Expand All @@ -169,7 +170,7 @@ pub mod test {
}
else {
// invoke is expected error - cannot use .expect_err() due to Debug not being implemented
match func.invoke_batch($ARGS, cardinality) {
match func.invoke_with_args(datafusion_expr::ScalarFunctionArgs{args: $ARGS, number_rows: cardinality, return_type: &return_type.unwrap()}) {
Ok(_) => assert!(false, "expected error"),
Err(error) => {
assert!(expected_error.strip_backtrace().starts_with(&error.strip_backtrace()));
Expand All @@ -182,6 +183,7 @@ pub mod test {
}

use arrow::datatypes::DataType;
use datafusion_expr::ScalarFunctionArgs;
#[allow(unused_imports)]
pub(crate) use test_function;

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 = self.fun.invoke_with_args(ScalarFunctionArgs {
args: &inputs,
args: inputs.as_slice(),
number_rows: batch.num_rows(),
return_type: &self.return_type,
})?;
Expand Down

0 comments on commit 3fc9775

Please sign in to comment.