diff --git a/datafusion/expr/src/udf.rs b/datafusion/expr/src/udf.rs index 6ef66d3c1231..3c4a98445a2e 100644 --- a/datafusion/expr/src/udf.rs +++ b/datafusion/expr/src/udf.rs @@ -328,7 +328,7 @@ where pub struct ScalarFunctionArgs<'a> { // The evaluated arguments to the function - pub args: Vec, + 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`) @@ -543,7 +543,7 @@ pub trait ScalarUDFImpl: Debug + Send + Sync { /// [`ColumnarValue::values_to_arrays`] can be used to convert the arguments /// to arrays, which will likely be simpler code, but be slower. fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result { - self.invoke_batch(args.args.as_slice(), args.number_rows) + self.invoke_batch(args.args, args.number_rows) } /// Invoke the function without `args`, instead the number of rows are provided, diff --git a/datafusion/functions/src/datetime/date_bin.rs b/datafusion/functions/src/datetime/date_bin.rs index 90731b46d17d..7b4c9c69ee07 100644 --- a/datafusion/functions/src/datetime/date_bin.rs +++ b/datafusion/functions/src/datetime/date_bin.rs @@ -508,7 +508,7 @@ mod tests { use crate::datetime::date_bin::{date_bin_nanos_interval, DateBinFunc}; use arrow::array::types::TimestampNanosecondType; - use arrow::array::{IntervalDayTimeArray, TimestampNanosecondArray}; + use arrow::array::{Array, IntervalDayTimeArray, TimestampNanosecondArray}; use arrow::compute::kernels::cast_utils::string_to_timestamp_nanos; use arrow::datatypes::{DataType, TimeUnit}; @@ -545,10 +545,10 @@ mod tests { milliseconds: 1, }, ))), - ColumnarValue::Array(timestamps), + ColumnarValue::Array(timestamps.clone()), ColumnarValue::Scalar(ScalarValue::TimestampNanosecond(Some(1), None)), ], - 1, + timestamps.len(), ); assert!(res.is_ok()); diff --git a/datafusion/functions/src/datetime/to_local_time.rs b/datafusion/functions/src/datetime/to_local_time.rs index efeef8ae766d..3ee316c28cee 100644 --- a/datafusion/functions/src/datetime/to_local_time.rs +++ b/datafusion/functions/src/datetime/to_local_time.rs @@ -563,7 +563,7 @@ mod tests { fn test_to_local_time_helper(input: ScalarValue, expected: ScalarValue) { let res = ToLocalTimeFunc::new() .invoke_with_args(ScalarFunctionArgs { - args: vec![ColumnarValue::Scalar(input)], + args: &[ColumnarValue::Scalar(input)], number_rows: 1, return_type: &expected.data_type(), }) diff --git a/datafusion/functions/src/utils.rs b/datafusion/functions/src/utils.rs index e0cb48f3e770..8b473500416b 100644 --- a/datafusion/functions/src/utils.rs +++ b/datafusion/functions/src/utils.rs @@ -133,8 +133,6 @@ pub mod test { let expected: Result> = $EXPECTED; let func = $FUNC; - let args_vec = $ARGS.iter().cloned().collect::>(); - let type_array = $ARGS.iter().map(|arg| arg.data_type()).collect::>(); let cardinality = $ARGS .iter() @@ -151,7 +149,7 @@ pub mod test { let return_type = return_type.unwrap(); assert_eq!(return_type, $EXPECTED_DATA_TYPE); - let result = func.invoke_with_args(datafusion_expr::ScalarFunctionArgs{args: args_vec, number_rows: cardinality, return_type: &return_type}); + 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"); @@ -172,7 +170,7 @@ pub mod test { } else { // invoke is expected error - cannot use .expect_err() due to Debug not being implemented - match func.invoke_with_args(datafusion_expr::ScalarFunctionArgs{args: args_vec, number_rows: cardinality, return_type: &return_type.unwrap()}) { + 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())); diff --git a/datafusion/physical-expr/src/scalar_function.rs b/datafusion/physical-expr/src/scalar_function.rs index 31499e2b7733..138774d806f2 100644 --- a/datafusion/physical-expr/src/scalar_function.rs +++ b/datafusion/physical-expr/src/scalar_function.rs @@ -147,7 +147,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, })?;