diff --git a/datafusion-examples/examples/advanced_udf.rs b/datafusion-examples/examples/advanced_udf.rs index aee3be6c9285..ae35cff6facf 100644 --- a/datafusion-examples/examples/advanced_udf.rs +++ b/datafusion-examples/examples/advanced_udf.rs @@ -27,9 +27,11 @@ use arrow::record_batch::RecordBatch; use datafusion::error::Result; use datafusion::logical_expr::Volatility; use datafusion::prelude::*; -use datafusion_common::{internal_err, ScalarValue}; +use datafusion_common::{exec_err, internal_err, ScalarValue}; use datafusion_expr::sort_properties::{ExprProperties, SortProperties}; -use datafusion_expr::{ColumnarValue, ScalarUDF, ScalarUDFImpl, Signature}; +use datafusion_expr::{ + ColumnarValue, ScalarFunctionArgs, ScalarUDF, ScalarUDFImpl, Signature, +}; /// This example shows how to use the full ScalarUDFImpl API to implement a user /// defined function. As in the `simple_udf.rs` example, this struct implements @@ -83,23 +85,27 @@ impl ScalarUDFImpl for PowUdf { Ok(DataType::Float64) } - /// This is the function that actually calculates the results. + /// This function actually calculates the results of the scalar function. + /// + /// This is the same way that functions provided with DataFusion are invoked, + /// which permits important special cases: /// - /// This is the same way that functions built into DataFusion are invoked, - /// which permits important special cases when one or both of the arguments - /// are single values (constants). For example `pow(a, 2)` + ///1. When one or both of the arguments are single values (constants). + /// For example `pow(a, 2)` + /// 2. When the input arrays can be reused (avoid allocating a new output array) /// /// However, it also means the implementation is more complex than when /// using `create_udf`. - fn invoke_batch( - &self, - args: &[ColumnarValue], - _number_rows: usize, - ) -> Result { + fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result { + // The other fields of the `args` struct are used for more specialized + // uses, and are not needed in this example + let ScalarFunctionArgs { mut args, .. } = args; // DataFusion has arranged for the correct inputs to be passed to this // function, but we check again to make sure assert_eq!(args.len(), 2); - let (base, exp) = (&args[0], &args[1]); + // take ownership of arguments by popping in reverse order + let exp = args.pop().unwrap(); + let base = args.pop().unwrap(); assert_eq!(base.data_type(), DataType::Float64); assert_eq!(exp.data_type(), DataType::Float64); @@ -118,7 +124,7 @@ impl ScalarUDFImpl for PowUdf { ) => { // compute the output. Note DataFusion treats `None` as NULL. let res = match (base, exp) { - (Some(base), Some(exp)) => Some(base.powf(*exp)), + (Some(base), Some(exp)) => Some(base.powf(exp)), // one or both arguments were NULL _ => None, }; @@ -140,31 +146,33 @@ impl ScalarUDFImpl for PowUdf { // kernel creates very fast "vectorized" code and // handles things like null values for us. let res: Float64Array = - compute::unary(base_array, |base| base.powf(*exp)); + compute::unary(base_array, |base| base.powf(exp)); Arc::new(res) } }; Ok(ColumnarValue::Array(result_array)) } - // special case if the base is a constant (note this code is quite - // similar to the previous case, so we omit comments) + // special case if the base is a constant. + // + // Note this case is very similar to the previous case, so we could + // use the same pattern. However, for this case we demonstrate an + // even more advanced pattern to potentially avoid allocating a new array ( ColumnarValue::Scalar(ScalarValue::Float64(base)), ColumnarValue::Array(exp_array), ) => { let res = match base { None => new_null_array(exp_array.data_type(), exp_array.len()), - Some(base) => { - let exp_array = exp_array.as_primitive::(); - let res: Float64Array = - compute::unary(exp_array, |exp| base.powf(exp)); - Arc::new(res) - } + Some(base) => maybe_pow_in_place(base, exp_array)?, }; Ok(ColumnarValue::Array(res)) } - // Both arguments are arrays so we have to perform the calculation for every row + // Both arguments are arrays so we have to perform the calculation + // for every row + // + // Note this could also be done in place using `binary_mut` as + // is done in `maybe_pow_in_place` but here we use binary for simplicity (ColumnarValue::Array(base_array), ColumnarValue::Array(exp_array)) => { let res: Float64Array = compute::binary( base_array.as_primitive::(), @@ -191,6 +199,52 @@ impl ScalarUDFImpl for PowUdf { } } +/// Evaluate `base ^ exp` *without* allocating a new array, if possible +fn maybe_pow_in_place(base: f64, exp_array: ArrayRef) -> Result { + // Calling `unary` creates a new array for the results. Avoiding + // allocations is a common optimization in performance critical code. + // arrow-rs allows this optimization via the `unary_mut` + // and `binary_mut` kernels in certain cases + // + // These kernels can only be used if there are no other references to + // the arrays (exp_array has to be the last remaining reference). + let owned_array = exp_array + // as in the previous example, we first downcast to &Float64Array + .as_primitive::() + // non-obviously, we call clone here to get an owned `Float64Array`. + // Calling clone() is relatively inexpensive as it increments + // some ref counts but doesn't clone the data) + // + // Once we have the owned Float64Array we can drop the original + // exp_array (untyped) reference + .clone(); + + // We *MUST* drop the reference to `exp_array` explicitly so that + // owned_array is the only reference remaining in this function. + // + // Note that depending on the query there may still be other references + // to the underlying buffers, which would prevent reuse. The only way to + // know for sure is the result of `compute::unary_mut` + drop(exp_array); + + // If we have the only reference, compute the result directly into the same + // allocation as was used for the input array + match compute::unary_mut(owned_array, |exp| base.powf(exp)) { + Err(_orig_array) => { + // unary_mut will return the original array if there are other + // references into the underling buffer (and thus reuse is + // impossible) + // + // In a real implementation, this case should fall back to + // calling `unary` and allocate a new array; In this example + // we will return an error for demonstration purposes + exec_err!("Could not reuse array for maybe_pow_in_place") + } + // a result of OK means the operation was run successfully + Ok(res) => Ok(Arc::new(res)), + } +} + /// In this example we register `PowUdf` as a user defined function /// and invoke it via the DataFrame API and SQL #[tokio::main] @@ -215,9 +269,29 @@ async fn main() -> Result<()> { // print the results df.show().await?; - // You can also invoke both pow(2, 10) and its alias my_pow(a, b) using SQL - let sql_df = ctx.sql("SELECT pow(2, 10), my_pow(a, b) FROM t").await?; - sql_df.show().await?; + // You can also invoke both pow(2, 10) and its alias my_pow(a, b) using SQL + ctx.sql("SELECT pow(2, 10), my_pow(a, b) FROM t") + .await? + .show() + .await?; + + // You can also invoke pow_in_place by passing a constant base and a + // column `a` as the exponent . If there is only a single + // reference to `a` the code works well + ctx.sql("SELECT pow(2, a) FROM t").await?.show().await?; + + // However, if there are multiple references to `a` in the evaluation + // the array storage can not be reused + let err = ctx + .sql("SELECT pow(2, a), pow(3, a) FROM t") + .await? + .show() + .await + .unwrap_err(); + assert_eq!( + err.to_string(), + "Execution error: Could not reuse array for maybe_pow_in_place" + ); Ok(()) } diff --git a/datafusion/expr/src/udf.rs b/datafusion/expr/src/udf.rs index bf9c9f407eff..809c78f30eff 100644 --- a/datafusion/expr/src/udf.rs +++ b/datafusion/expr/src/udf.rs @@ -326,13 +326,15 @@ where } } +/// Arguments passed to [`ScalarUDFImpl::invoke_with_args`] when invoking a +/// scalar function. pub struct ScalarFunctionArgs<'a> { - // The evaluated arguments to the function - pub args: &'a [ColumnarValue], - // The number of rows in record batch being evaluated + /// The evaluated arguments to the function + pub args: Vec, + /// 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`) - // when creating the physical expression from the logical expression + /// The return type of the scalar function returned (from `return_type` or `return_type_from_exprs`) + /// when creating the physical expression from the logical expression pub return_type: &'a DataType, } @@ -539,7 +541,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, 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/to_local_time.rs b/datafusion/functions/src/datetime/to_local_time.rs index eaa91d1140ba..9f95b780ea4f 100644 --- a/datafusion/functions/src/datetime/to_local_time.rs +++ b/datafusion/functions/src/datetime/to_local_time.rs @@ -562,7 +562,7 @@ mod tests { fn test_to_local_time_helper(input: ScalarValue, expected: ScalarValue) { let res = ToLocalTimeFunc::new() .invoke_with_args(ScalarFunctionArgs { - args: &[ColumnarValue::Scalar(input)], + args: vec![ColumnarValue::Scalar(input)], number_rows: 1, return_type: &expected.data_type(), }) diff --git a/datafusion/functions/src/string/ascii.rs b/datafusion/functions/src/string/ascii.rs index 4f615b5b2c58..f366329b4f86 100644 --- a/datafusion/functions/src/string/ascii.rs +++ b/datafusion/functions/src/string/ascii.rs @@ -157,7 +157,7 @@ mod tests { ($INPUT:expr, $EXPECTED:expr) => { test_function!( AsciiFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8($INPUT))], + vec![ColumnarValue::Scalar(ScalarValue::Utf8($INPUT))], $EXPECTED, i32, Int32, @@ -166,7 +166,7 @@ mod tests { test_function!( AsciiFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::LargeUtf8($INPUT))], + vec![ColumnarValue::Scalar(ScalarValue::LargeUtf8($INPUT))], $EXPECTED, i32, Int32, @@ -175,7 +175,7 @@ mod tests { test_function!( AsciiFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View($INPUT))], + vec![ColumnarValue::Scalar(ScalarValue::Utf8View($INPUT))], $EXPECTED, i32, Int32, diff --git a/datafusion/functions/src/string/btrim.rs b/datafusion/functions/src/string/btrim.rs index ae79bb59f9c7..298d64f04ae9 100644 --- a/datafusion/functions/src/string/btrim.rs +++ b/datafusion/functions/src/string/btrim.rs @@ -152,9 +152,9 @@ mod tests { // String view cases for checking normal logic test_function!( BTrimFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8View(Some( String::from("alphabet ") - ))),], + )))], Ok(Some("alphabet")), &str, Utf8View, @@ -162,7 +162,7 @@ mod tests { ); test_function!( BTrimFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8View(Some( String::from(" alphabet ") ))),], Ok(Some("alphabet")), @@ -172,7 +172,7 @@ mod tests { ); test_function!( BTrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "alphabet" )))), @@ -185,7 +185,7 @@ mod tests { ); test_function!( BTrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "alphabet" )))), @@ -200,7 +200,7 @@ mod tests { ); test_function!( BTrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "alphabet" )))), @@ -214,7 +214,7 @@ mod tests { // Special string view case for checking unlined output(len > 12) test_function!( BTrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "xxxalphabetalphabetxxx" )))), @@ -228,7 +228,7 @@ mod tests { // String cases test_function!( BTrimFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8(Some( String::from("alphabet ") ))),], Ok(Some("alphabet")), @@ -238,7 +238,7 @@ mod tests { ); test_function!( BTrimFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8(Some( String::from("alphabet ") ))),], Ok(Some("alphabet")), @@ -248,7 +248,7 @@ mod tests { ); test_function!( BTrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("alphabet")))), ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("t")))), ], @@ -259,7 +259,7 @@ mod tests { ); test_function!( BTrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("alphabet")))), ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("alphabe")))), ], @@ -270,7 +270,7 @@ mod tests { ); test_function!( BTrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("alphabet")))), ColumnarValue::Scalar(ScalarValue::Utf8(None)), ], diff --git a/datafusion/functions/src/string/concat.rs b/datafusion/functions/src/string/concat.rs index 576c891ce467..895a7cdbf308 100644 --- a/datafusion/functions/src/string/concat.rs +++ b/datafusion/functions/src/string/concat.rs @@ -388,7 +388,7 @@ mod tests { fn test_functions() -> Result<()> { test_function!( ConcatFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("aa")), ColumnarValue::Scalar(ScalarValue::from("bb")), ColumnarValue::Scalar(ScalarValue::from("cc")), @@ -400,7 +400,7 @@ mod tests { ); test_function!( ConcatFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("aa")), ColumnarValue::Scalar(ScalarValue::Utf8(None)), ColumnarValue::Scalar(ScalarValue::from("cc")), @@ -412,7 +412,7 @@ mod tests { ); test_function!( ConcatFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8(None))], + vec![ColumnarValue::Scalar(ScalarValue::Utf8(None))], Ok(Some("")), &str, Utf8, @@ -420,7 +420,7 @@ mod tests { ); test_function!( ConcatFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("aa")), ColumnarValue::Scalar(ScalarValue::Utf8View(None)), ColumnarValue::Scalar(ScalarValue::LargeUtf8(None)), @@ -433,7 +433,7 @@ mod tests { ); test_function!( ConcatFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("aa")), ColumnarValue::Scalar(ScalarValue::LargeUtf8(None)), ColumnarValue::Scalar(ScalarValue::from("cc")), @@ -445,7 +445,7 @@ mod tests { ); test_function!( ConcatFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some("aa".to_string()))), ColumnarValue::Scalar(ScalarValue::Utf8(Some("cc".to_string()))), ], diff --git a/datafusion/functions/src/string/concat_ws.rs b/datafusion/functions/src/string/concat_ws.rs index 610c4f0be697..7db8dbec4a71 100644 --- a/datafusion/functions/src/string/concat_ws.rs +++ b/datafusion/functions/src/string/concat_ws.rs @@ -404,7 +404,7 @@ mod tests { fn test_functions() -> Result<()> { test_function!( ConcatWsFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("|")), ColumnarValue::Scalar(ScalarValue::from("aa")), ColumnarValue::Scalar(ScalarValue::from("bb")), @@ -417,7 +417,7 @@ mod tests { ); test_function!( ConcatWsFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("|")), ColumnarValue::Scalar(ScalarValue::Utf8(None)), ], @@ -428,7 +428,7 @@ mod tests { ); test_function!( ConcatWsFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(None)), ColumnarValue::Scalar(ScalarValue::from("aa")), ColumnarValue::Scalar(ScalarValue::from("bb")), @@ -441,7 +441,7 @@ mod tests { ); test_function!( ConcatWsFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("|")), ColumnarValue::Scalar(ScalarValue::from("aa")), ColumnarValue::Scalar(ScalarValue::Utf8(None)), diff --git a/datafusion/functions/src/string/ends_with.rs b/datafusion/functions/src/string/ends_with.rs index fc7fc04f4363..1632fdd9943e 100644 --- a/datafusion/functions/src/string/ends_with.rs +++ b/datafusion/functions/src/string/ends_with.rs @@ -138,7 +138,7 @@ mod tests { fn test_functions() -> Result<()> { test_function!( EndsWithFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from("alph")), ], @@ -149,7 +149,7 @@ mod tests { ); test_function!( EndsWithFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from("bet")), ], @@ -160,7 +160,7 @@ mod tests { ); test_function!( EndsWithFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(None)), ColumnarValue::Scalar(ScalarValue::from("alph")), ], @@ -171,7 +171,7 @@ mod tests { ); test_function!( EndsWithFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::Utf8(None)), ], diff --git a/datafusion/functions/src/string/initcap.rs b/datafusion/functions/src/string/initcap.rs index a9090b0a6f43..338a89091d29 100644 --- a/datafusion/functions/src/string/initcap.rs +++ b/datafusion/functions/src/string/initcap.rs @@ -163,7 +163,7 @@ mod tests { fn test_functions() -> Result<()> { test_function!( InitcapFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::from("hi THOMAS"))], + vec![ColumnarValue::Scalar(ScalarValue::from("hi THOMAS"))], Ok(Some("Hi Thomas")), &str, Utf8, @@ -171,7 +171,7 @@ mod tests { ); test_function!( InitcapFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::from(""))], + vec![ColumnarValue::Scalar(ScalarValue::from(""))], Ok(Some("")), &str, Utf8, @@ -179,7 +179,7 @@ mod tests { ); test_function!( InitcapFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::from(""))], + vec![ColumnarValue::Scalar(ScalarValue::from(""))], Ok(Some("")), &str, Utf8, @@ -187,7 +187,7 @@ mod tests { ); test_function!( InitcapFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8(None))], + vec![ColumnarValue::Scalar(ScalarValue::Utf8(None))], Ok(None), &str, Utf8, @@ -195,7 +195,7 @@ mod tests { ); test_function!( InitcapFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8View(Some( "hi THOMAS".to_string() )))], Ok(Some("Hi Thomas")), @@ -205,7 +205,7 @@ mod tests { ); test_function!( InitcapFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8View(Some( "hi THOMAS wIth M0re ThAN 12 ChaRs".to_string() )))], Ok(Some("Hi Thomas With M0re Than 12 Chars")), @@ -215,7 +215,7 @@ mod tests { ); test_function!( InitcapFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8View(Some( "".to_string() )))], Ok(Some("")), @@ -225,7 +225,7 @@ mod tests { ); test_function!( InitcapFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View(None))], + vec![ColumnarValue::Scalar(ScalarValue::Utf8View(None))], Ok(None), &str, Utf8, diff --git a/datafusion/functions/src/string/ltrim.rs b/datafusion/functions/src/string/ltrim.rs index e0e83d1b01e3..b3e7f0bf007d 100644 --- a/datafusion/functions/src/string/ltrim.rs +++ b/datafusion/functions/src/string/ltrim.rs @@ -148,7 +148,7 @@ mod tests { // String view cases for checking normal logic test_function!( LtrimFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8View(Some( String::from("alphabet ") ))),], Ok(Some("alphabet ")), @@ -158,7 +158,7 @@ mod tests { ); test_function!( LtrimFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8View(Some( String::from(" alphabet ") ))),], Ok(Some("alphabet ")), @@ -168,7 +168,7 @@ mod tests { ); test_function!( LtrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "alphabet" )))), @@ -181,7 +181,7 @@ mod tests { ); test_function!( LtrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "alphabet" )))), @@ -196,7 +196,7 @@ mod tests { ); test_function!( LtrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "alphabet" )))), @@ -210,7 +210,7 @@ mod tests { // Special string view case for checking unlined output(len > 12) test_function!( LtrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "xxxalphabetalphabet" )))), @@ -224,7 +224,7 @@ mod tests { // String cases test_function!( LtrimFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8(Some( String::from("alphabet ") ))),], Ok(Some("alphabet ")), @@ -234,7 +234,7 @@ mod tests { ); test_function!( LtrimFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8(Some( String::from("alphabet ") ))),], Ok(Some("alphabet ")), @@ -244,7 +244,7 @@ mod tests { ); test_function!( LtrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("alphabet")))), ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("t")))), ], @@ -255,7 +255,7 @@ mod tests { ); test_function!( LtrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("alphabet")))), ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("alphabe")))), ], @@ -266,7 +266,7 @@ mod tests { ); test_function!( LtrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("alphabet")))), ColumnarValue::Scalar(ScalarValue::Utf8(None)), ], diff --git a/datafusion/functions/src/string/octet_length.rs b/datafusion/functions/src/string/octet_length.rs index 2dbfa6746d61..26355556ff07 100644 --- a/datafusion/functions/src/string/octet_length.rs +++ b/datafusion/functions/src/string/octet_length.rs @@ -140,7 +140,7 @@ mod tests { fn test_functions() -> Result<()> { test_function!( OctetLengthFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Int32(Some(12)))], + vec![ColumnarValue::Scalar(ScalarValue::Int32(Some(12)))], exec_err!( "The OCTET_LENGTH function can only accept strings, but got Int32." ), @@ -150,7 +150,7 @@ mod tests { ); test_function!( OctetLengthFunc::new(), - &[ColumnarValue::Array(Arc::new(StringArray::from(vec![ + vec![ColumnarValue::Array(Arc::new(StringArray::from(vec![ String::from("chars"), String::from("chars2"), ])))], @@ -161,7 +161,7 @@ mod tests { ); test_function!( OctetLengthFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("chars")))), ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("chars")))) ], @@ -172,7 +172,7 @@ mod tests { ); test_function!( OctetLengthFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8(Some( String::from("chars") )))], Ok(Some(5)), @@ -182,7 +182,7 @@ mod tests { ); test_function!( OctetLengthFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8(Some( String::from("josé") )))], Ok(Some(5)), @@ -192,7 +192,7 @@ mod tests { ); test_function!( OctetLengthFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8(Some( String::from("") )))], Ok(Some(0)), @@ -202,7 +202,7 @@ mod tests { ); test_function!( OctetLengthFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8(None))], + vec![ColumnarValue::Scalar(ScalarValue::Utf8(None))], Ok(None), i32, Int32, @@ -210,7 +210,7 @@ mod tests { ); test_function!( OctetLengthFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8View(Some( String::from("joséjoséjoséjosé") )))], Ok(Some(20)), @@ -220,7 +220,7 @@ mod tests { ); test_function!( OctetLengthFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8View(Some( String::from("josé") )))], Ok(Some(5)), @@ -230,7 +230,7 @@ mod tests { ); test_function!( OctetLengthFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8View(Some( String::from("") )))], Ok(Some(0)), diff --git a/datafusion/functions/src/string/repeat.rs b/datafusion/functions/src/string/repeat.rs index 4140a9b913ff..d16508c6af5a 100644 --- a/datafusion/functions/src/string/repeat.rs +++ b/datafusion/functions/src/string/repeat.rs @@ -171,7 +171,7 @@ mod tests { fn test_functions() -> Result<()> { test_function!( RepeatFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("Pg")))), ColumnarValue::Scalar(ScalarValue::Int64(Some(4))), ], @@ -182,7 +182,7 @@ mod tests { ); test_function!( RepeatFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(None)), ColumnarValue::Scalar(ScalarValue::Int64(Some(4))), ], @@ -193,7 +193,7 @@ mod tests { ); test_function!( RepeatFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("Pg")))), ColumnarValue::Scalar(ScalarValue::Int64(None)), ], @@ -205,7 +205,7 @@ mod tests { test_function!( RepeatFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from("Pg")))), ColumnarValue::Scalar(ScalarValue::Int64(Some(4))), ], @@ -216,7 +216,7 @@ mod tests { ); test_function!( RepeatFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(None)), ColumnarValue::Scalar(ScalarValue::Int64(Some(4))), ], @@ -227,7 +227,7 @@ mod tests { ); test_function!( RepeatFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from("Pg")))), ColumnarValue::Scalar(ScalarValue::Int64(None)), ], diff --git a/datafusion/functions/src/string/replace.rs b/datafusion/functions/src/string/replace.rs index 2439799f96d7..9b71d3871ea8 100644 --- a/datafusion/functions/src/string/replace.rs +++ b/datafusion/functions/src/string/replace.rs @@ -157,7 +157,7 @@ mod tests { fn test_functions() -> Result<()> { test_function!( ReplaceFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("aabbdqcbb")))), ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("bb")))), ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("ccc")))), @@ -170,7 +170,7 @@ mod tests { test_function!( ReplaceFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::LargeUtf8(Some(String::from( "aabbb" )))), @@ -185,7 +185,7 @@ mod tests { test_function!( ReplaceFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "aabbbcw" )))), diff --git a/datafusion/functions/src/string/rtrim.rs b/datafusion/functions/src/string/rtrim.rs index b4fe8d432432..ff8430f1530e 100644 --- a/datafusion/functions/src/string/rtrim.rs +++ b/datafusion/functions/src/string/rtrim.rs @@ -151,7 +151,7 @@ mod tests { // String view cases for checking normal logic test_function!( RtrimFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8View(Some( String::from("alphabet ") ))),], Ok(Some("alphabet")), @@ -161,7 +161,7 @@ mod tests { ); test_function!( RtrimFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8View(Some( String::from(" alphabet ") ))),], Ok(Some(" alphabet")), @@ -171,7 +171,7 @@ mod tests { ); test_function!( RtrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "alphabet" )))), @@ -184,7 +184,7 @@ mod tests { ); test_function!( RtrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "alphabet" )))), @@ -199,7 +199,7 @@ mod tests { ); test_function!( RtrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "alphabet" )))), @@ -213,7 +213,7 @@ mod tests { // Special string view case for checking unlined output(len > 12) test_function!( RtrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "alphabetalphabetxxx" )))), @@ -227,7 +227,7 @@ mod tests { // String cases test_function!( RtrimFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8(Some( String::from("alphabet ") ))),], Ok(Some("alphabet")), @@ -237,7 +237,7 @@ mod tests { ); test_function!( RtrimFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8(Some( + vec![ColumnarValue::Scalar(ScalarValue::Utf8(Some( String::from(" alphabet ") ))),], Ok(Some(" alphabet")), @@ -247,7 +247,7 @@ mod tests { ); test_function!( RtrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("alphabet")))), ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("t ")))), ], @@ -258,7 +258,7 @@ mod tests { ); test_function!( RtrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("alphabet")))), ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("alphabe")))), ], @@ -269,7 +269,7 @@ mod tests { ); test_function!( RtrimFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("alphabet")))), ColumnarValue::Scalar(ScalarValue::Utf8(None)), ], diff --git a/datafusion/functions/src/string/split_part.rs b/datafusion/functions/src/string/split_part.rs index e55325db756d..40bdd3ad01b2 100644 --- a/datafusion/functions/src/string/split_part.rs +++ b/datafusion/functions/src/string/split_part.rs @@ -270,7 +270,7 @@ mod tests { fn test_functions() -> Result<()> { test_function!( SplitPartFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from( "abc~@~def~@~ghi" )))), @@ -284,7 +284,7 @@ mod tests { ); test_function!( SplitPartFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from( "abc~@~def~@~ghi" )))), @@ -298,7 +298,7 @@ mod tests { ); test_function!( SplitPartFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from( "abc~@~def~@~ghi" )))), @@ -312,7 +312,7 @@ mod tests { ); test_function!( SplitPartFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from( "abc~@~def~@~ghi" )))), diff --git a/datafusion/functions/src/string/starts_with.rs b/datafusion/functions/src/string/starts_with.rs index 36dbd8167b4e..7354fda09584 100644 --- a/datafusion/functions/src/string/starts_with.rs +++ b/datafusion/functions/src/string/starts_with.rs @@ -159,7 +159,7 @@ mod tests { for (args, expected) in test_cases { test_function!( StartsWithFunc::new(), - &args, + args, Ok(expected), bool, Boolean, diff --git a/datafusion/functions/src/unicode/character_length.rs b/datafusion/functions/src/unicode/character_length.rs index 726822a8f887..822bdca9aca8 100644 --- a/datafusion/functions/src/unicode/character_length.rs +++ b/datafusion/functions/src/unicode/character_length.rs @@ -176,7 +176,7 @@ mod tests { ($INPUT:expr, $EXPECTED:expr) => { test_function!( CharacterLengthFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8($INPUT))], + vec![ColumnarValue::Scalar(ScalarValue::Utf8($INPUT))], $EXPECTED, i32, Int32, @@ -185,7 +185,7 @@ mod tests { test_function!( CharacterLengthFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::LargeUtf8($INPUT))], + vec![ColumnarValue::Scalar(ScalarValue::LargeUtf8($INPUT))], $EXPECTED, i64, Int64, @@ -194,7 +194,7 @@ mod tests { test_function!( CharacterLengthFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View($INPUT))], + vec![ColumnarValue::Scalar(ScalarValue::Utf8View($INPUT))], $EXPECTED, i32, Int32, diff --git a/datafusion/functions/src/unicode/left.rs b/datafusion/functions/src/unicode/left.rs index ef2802340b14..e583523d84a0 100644 --- a/datafusion/functions/src/unicode/left.rs +++ b/datafusion/functions/src/unicode/left.rs @@ -188,7 +188,7 @@ mod tests { fn test_functions() -> Result<()> { test_function!( LeftFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("abcde")), ColumnarValue::Scalar(ScalarValue::from(2i64)), ], @@ -199,7 +199,7 @@ mod tests { ); test_function!( LeftFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("abcde")), ColumnarValue::Scalar(ScalarValue::from(200i64)), ], @@ -210,7 +210,7 @@ mod tests { ); test_function!( LeftFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("abcde")), ColumnarValue::Scalar(ScalarValue::from(-2i64)), ], @@ -221,7 +221,7 @@ mod tests { ); test_function!( LeftFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("abcde")), ColumnarValue::Scalar(ScalarValue::from(-200i64)), ], @@ -232,7 +232,7 @@ mod tests { ); test_function!( LeftFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("abcde")), ColumnarValue::Scalar(ScalarValue::from(0i64)), ], @@ -243,7 +243,7 @@ mod tests { ); test_function!( LeftFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(None)), ColumnarValue::Scalar(ScalarValue::from(2i64)), ], @@ -254,7 +254,7 @@ mod tests { ); test_function!( LeftFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("abcde")), ColumnarValue::Scalar(ScalarValue::Int64(None)), ], @@ -265,7 +265,7 @@ mod tests { ); test_function!( LeftFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("joséésoj")), ColumnarValue::Scalar(ScalarValue::from(5i64)), ], @@ -276,7 +276,7 @@ mod tests { ); test_function!( LeftFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("joséésoj")), ColumnarValue::Scalar(ScalarValue::from(-3i64)), ], diff --git a/datafusion/functions/src/unicode/lpad.rs b/datafusion/functions/src/unicode/lpad.rs index 6c8a4ec97bb0..f1750d2277ca 100644 --- a/datafusion/functions/src/unicode/lpad.rs +++ b/datafusion/functions/src/unicode/lpad.rs @@ -298,7 +298,7 @@ mod tests { ($INPUT:expr, $LENGTH:expr, $EXPECTED:expr) => { test_function!( LPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8($INPUT)), ColumnarValue::Scalar($LENGTH) ], @@ -310,7 +310,7 @@ mod tests { test_function!( LPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::LargeUtf8($INPUT)), ColumnarValue::Scalar($LENGTH) ], @@ -322,7 +322,7 @@ mod tests { test_function!( LPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View($INPUT)), ColumnarValue::Scalar($LENGTH) ], @@ -337,7 +337,7 @@ mod tests { // utf8, utf8 test_function!( LPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8($INPUT)), ColumnarValue::Scalar($LENGTH), ColumnarValue::Scalar(ScalarValue::Utf8($REPLACE)) @@ -350,7 +350,7 @@ mod tests { // utf8, largeutf8 test_function!( LPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8($INPUT)), ColumnarValue::Scalar($LENGTH), ColumnarValue::Scalar(ScalarValue::LargeUtf8($REPLACE)) @@ -363,7 +363,7 @@ mod tests { // utf8, utf8view test_function!( LPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8($INPUT)), ColumnarValue::Scalar($LENGTH), ColumnarValue::Scalar(ScalarValue::Utf8View($REPLACE)) @@ -377,7 +377,7 @@ mod tests { // largeutf8, utf8 test_function!( LPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::LargeUtf8($INPUT)), ColumnarValue::Scalar($LENGTH), ColumnarValue::Scalar(ScalarValue::Utf8($REPLACE)) @@ -390,7 +390,7 @@ mod tests { // largeutf8, largeutf8 test_function!( LPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::LargeUtf8($INPUT)), ColumnarValue::Scalar($LENGTH), ColumnarValue::Scalar(ScalarValue::LargeUtf8($REPLACE)) @@ -403,7 +403,7 @@ mod tests { // largeutf8, utf8view test_function!( LPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::LargeUtf8($INPUT)), ColumnarValue::Scalar($LENGTH), ColumnarValue::Scalar(ScalarValue::Utf8View($REPLACE)) @@ -417,7 +417,7 @@ mod tests { // utf8view, utf8 test_function!( LPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View($INPUT)), ColumnarValue::Scalar($LENGTH), ColumnarValue::Scalar(ScalarValue::Utf8($REPLACE)) @@ -430,7 +430,7 @@ mod tests { // utf8view, largeutf8 test_function!( LPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View($INPUT)), ColumnarValue::Scalar($LENGTH), ColumnarValue::Scalar(ScalarValue::LargeUtf8($REPLACE)) @@ -443,7 +443,7 @@ mod tests { // utf8view, utf8view test_function!( LPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View($INPUT)), ColumnarValue::Scalar($LENGTH), ColumnarValue::Scalar(ScalarValue::Utf8View($REPLACE)) diff --git a/datafusion/functions/src/unicode/reverse.rs b/datafusion/functions/src/unicode/reverse.rs index 38c1f23cbd5a..8e3cf8845f98 100644 --- a/datafusion/functions/src/unicode/reverse.rs +++ b/datafusion/functions/src/unicode/reverse.rs @@ -151,7 +151,7 @@ mod tests { ($INPUT:expr, $EXPECTED:expr) => { test_function!( ReverseFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8($INPUT))], + vec![ColumnarValue::Scalar(ScalarValue::Utf8($INPUT))], $EXPECTED, &str, Utf8, @@ -160,7 +160,7 @@ mod tests { test_function!( ReverseFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::LargeUtf8($INPUT))], + vec![ColumnarValue::Scalar(ScalarValue::LargeUtf8($INPUT))], $EXPECTED, &str, LargeUtf8, @@ -169,7 +169,7 @@ mod tests { test_function!( ReverseFunc::new(), - &[ColumnarValue::Scalar(ScalarValue::Utf8View($INPUT))], + vec![ColumnarValue::Scalar(ScalarValue::Utf8View($INPUT))], $EXPECTED, &str, Utf8, diff --git a/datafusion/functions/src/unicode/right.rs b/datafusion/functions/src/unicode/right.rs index 1586e23eb8aa..4e414fbae5cb 100644 --- a/datafusion/functions/src/unicode/right.rs +++ b/datafusion/functions/src/unicode/right.rs @@ -192,7 +192,7 @@ mod tests { fn test_functions() -> Result<()> { test_function!( RightFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("abcde")), ColumnarValue::Scalar(ScalarValue::from(2i64)), ], @@ -203,7 +203,7 @@ mod tests { ); test_function!( RightFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("abcde")), ColumnarValue::Scalar(ScalarValue::from(200i64)), ], @@ -214,7 +214,7 @@ mod tests { ); test_function!( RightFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("abcde")), ColumnarValue::Scalar(ScalarValue::from(-2i64)), ], @@ -225,7 +225,7 @@ mod tests { ); test_function!( RightFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("abcde")), ColumnarValue::Scalar(ScalarValue::from(-200i64)), ], @@ -236,7 +236,7 @@ mod tests { ); test_function!( RightFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("abcde")), ColumnarValue::Scalar(ScalarValue::from(0i64)), ], @@ -247,7 +247,7 @@ mod tests { ); test_function!( RightFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(None)), ColumnarValue::Scalar(ScalarValue::from(2i64)), ], @@ -258,7 +258,7 @@ mod tests { ); test_function!( RightFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("abcde")), ColumnarValue::Scalar(ScalarValue::Int64(None)), ], @@ -269,7 +269,7 @@ mod tests { ); test_function!( RightFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("joséésoj")), ColumnarValue::Scalar(ScalarValue::from(5i64)), ], @@ -280,7 +280,7 @@ mod tests { ); test_function!( RightFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("joséésoj")), ColumnarValue::Scalar(ScalarValue::from(-3i64)), ], diff --git a/datafusion/functions/src/unicode/rpad.rs b/datafusion/functions/src/unicode/rpad.rs index 6e6bde3e177c..d5a0079c72aa 100644 --- a/datafusion/functions/src/unicode/rpad.rs +++ b/datafusion/functions/src/unicode/rpad.rs @@ -319,7 +319,7 @@ mod tests { fn test_functions() -> Result<()> { test_function!( RPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("josé")), ColumnarValue::Scalar(ScalarValue::from(5i64)), ], @@ -330,7 +330,7 @@ mod tests { ); test_function!( RPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("hi")), ColumnarValue::Scalar(ScalarValue::from(5i64)), ], @@ -341,7 +341,7 @@ mod tests { ); test_function!( RPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("hi")), ColumnarValue::Scalar(ScalarValue::from(0i64)), ], @@ -352,7 +352,7 @@ mod tests { ); test_function!( RPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("hi")), ColumnarValue::Scalar(ScalarValue::Int64(None)), ], @@ -363,7 +363,7 @@ mod tests { ); test_function!( RPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(None)), ColumnarValue::Scalar(ScalarValue::from(5i64)), ], @@ -374,7 +374,7 @@ mod tests { ); test_function!( RPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("hi")), ColumnarValue::Scalar(ScalarValue::from(5i64)), ColumnarValue::Scalar(ScalarValue::from("xy")), @@ -386,7 +386,7 @@ mod tests { ); test_function!( RPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("hi")), ColumnarValue::Scalar(ScalarValue::from(21i64)), ColumnarValue::Scalar(ScalarValue::from("abcdef")), @@ -398,7 +398,7 @@ mod tests { ); test_function!( RPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("hi")), ColumnarValue::Scalar(ScalarValue::from(5i64)), ColumnarValue::Scalar(ScalarValue::from(" ")), @@ -410,7 +410,7 @@ mod tests { ); test_function!( RPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("hi")), ColumnarValue::Scalar(ScalarValue::from(5i64)), ColumnarValue::Scalar(ScalarValue::from("")), @@ -422,7 +422,7 @@ mod tests { ); test_function!( RPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(None)), ColumnarValue::Scalar(ScalarValue::from(5i64)), ColumnarValue::Scalar(ScalarValue::from("xy")), @@ -434,7 +434,7 @@ mod tests { ); test_function!( RPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("hi")), ColumnarValue::Scalar(ScalarValue::Int64(None)), ColumnarValue::Scalar(ScalarValue::from("xy")), @@ -446,7 +446,7 @@ mod tests { ); test_function!( RPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("hi")), ColumnarValue::Scalar(ScalarValue::from(5i64)), ColumnarValue::Scalar(ScalarValue::Utf8(None)), @@ -458,7 +458,7 @@ mod tests { ); test_function!( RPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("josé")), ColumnarValue::Scalar(ScalarValue::from(10i64)), ColumnarValue::Scalar(ScalarValue::from("xy")), @@ -470,7 +470,7 @@ mod tests { ); test_function!( RPadFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("josé")), ColumnarValue::Scalar(ScalarValue::from(10i64)), ColumnarValue::Scalar(ScalarValue::from("éñ")), diff --git a/datafusion/functions/src/unicode/strpos.rs b/datafusion/functions/src/unicode/strpos.rs index 5d1986e44c92..569af87a4b50 100644 --- a/datafusion/functions/src/unicode/strpos.rs +++ b/datafusion/functions/src/unicode/strpos.rs @@ -218,7 +218,7 @@ mod tests { ($lhs:literal, $rhs:literal -> $result:literal; $t1:ident $t2:ident $t3:ident $t4:ident $t5:ident) => { test_function!( StrposFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::$t1(Some($lhs.to_owned()))), ColumnarValue::Scalar(ScalarValue::$t2(Some($rhs.to_owned()))), ], diff --git a/datafusion/functions/src/unicode/substr.rs b/datafusion/functions/src/unicode/substr.rs index 0ac050c707bf..141984cf2674 100644 --- a/datafusion/functions/src/unicode/substr.rs +++ b/datafusion/functions/src/unicode/substr.rs @@ -523,7 +523,7 @@ mod tests { fn test_functions() -> Result<()> { test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(None)), ColumnarValue::Scalar(ScalarValue::from(1i64)), ], @@ -534,7 +534,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "alphabet" )))), @@ -547,7 +547,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "this és longer than 12B" )))), @@ -561,7 +561,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "this is longer than 12B" )))), @@ -574,7 +574,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "joséésoj" )))), @@ -587,7 +587,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "alphabet" )))), @@ -601,7 +601,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::from( "alphabet" )))), @@ -615,7 +615,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from(0i64)), ], @@ -626,7 +626,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("joséésoj")), ColumnarValue::Scalar(ScalarValue::from(5i64)), ], @@ -637,7 +637,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("joséésoj")), ColumnarValue::Scalar(ScalarValue::from(-5i64)), ], @@ -648,7 +648,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from(1i64)), ], @@ -659,7 +659,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from(2i64)), ], @@ -670,7 +670,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from(3i64)), ], @@ -681,7 +681,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from(-3i64)), ], @@ -692,7 +692,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from(30i64)), ], @@ -703,7 +703,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::Int64(None)), ], @@ -714,7 +714,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from(3i64)), ColumnarValue::Scalar(ScalarValue::from(2i64)), @@ -726,7 +726,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from(3i64)), ColumnarValue::Scalar(ScalarValue::from(20i64)), @@ -738,7 +738,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from(0i64)), ColumnarValue::Scalar(ScalarValue::from(5i64)), @@ -751,7 +751,7 @@ mod tests { // starting from 5 (10 + -5) test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from(-5i64)), ColumnarValue::Scalar(ScalarValue::from(10i64)), @@ -764,7 +764,7 @@ mod tests { // starting from -1 (4 + -5) test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from(-5i64)), ColumnarValue::Scalar(ScalarValue::from(4i64)), @@ -777,7 +777,7 @@ mod tests { // starting from 0 (5 + -5) test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from(-5i64)), ColumnarValue::Scalar(ScalarValue::from(5i64)), @@ -789,7 +789,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::Int64(None)), ColumnarValue::Scalar(ScalarValue::from(20i64)), @@ -801,7 +801,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from(3i64)), ColumnarValue::Scalar(ScalarValue::Int64(None)), @@ -813,7 +813,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("alphabet")), ColumnarValue::Scalar(ScalarValue::from(1i64)), ColumnarValue::Scalar(ScalarValue::from(-1i64)), @@ -825,7 +825,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("joséésoj")), ColumnarValue::Scalar(ScalarValue::from(5i64)), ColumnarValue::Scalar(ScalarValue::from(2i64)), @@ -851,7 +851,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("abc")), ColumnarValue::Scalar(ScalarValue::from(-9223372036854775808i64)), ], @@ -862,7 +862,7 @@ mod tests { ); test_function!( SubstrFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("overflow")), ColumnarValue::Scalar(ScalarValue::from(-9223372036854775808i64)), ColumnarValue::Scalar(ScalarValue::from(1i64)), diff --git a/datafusion/functions/src/unicode/substrindex.rs b/datafusion/functions/src/unicode/substrindex.rs index 825666b0455e..61cd989bb964 100644 --- a/datafusion/functions/src/unicode/substrindex.rs +++ b/datafusion/functions/src/unicode/substrindex.rs @@ -253,7 +253,7 @@ mod tests { fn test_functions() -> Result<()> { test_function!( SubstrIndexFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("www.apache.org")), ColumnarValue::Scalar(ScalarValue::from(".")), ColumnarValue::Scalar(ScalarValue::from(1i64)), @@ -265,7 +265,7 @@ mod tests { ); test_function!( SubstrIndexFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("www.apache.org")), ColumnarValue::Scalar(ScalarValue::from(".")), ColumnarValue::Scalar(ScalarValue::from(2i64)), @@ -277,7 +277,7 @@ mod tests { ); test_function!( SubstrIndexFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("www.apache.org")), ColumnarValue::Scalar(ScalarValue::from(".")), ColumnarValue::Scalar(ScalarValue::from(-2i64)), @@ -289,7 +289,7 @@ mod tests { ); test_function!( SubstrIndexFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("www.apache.org")), ColumnarValue::Scalar(ScalarValue::from(".")), ColumnarValue::Scalar(ScalarValue::from(-1i64)), @@ -301,7 +301,7 @@ mod tests { ); test_function!( SubstrIndexFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("www.apache.org")), ColumnarValue::Scalar(ScalarValue::from(".")), ColumnarValue::Scalar(ScalarValue::from(0i64)), @@ -313,7 +313,7 @@ mod tests { ); test_function!( SubstrIndexFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("")), ColumnarValue::Scalar(ScalarValue::from(".")), ColumnarValue::Scalar(ScalarValue::from(1i64)), @@ -325,7 +325,7 @@ mod tests { ); test_function!( SubstrIndexFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("www.apache.org")), ColumnarValue::Scalar(ScalarValue::from("")), ColumnarValue::Scalar(ScalarValue::from(1i64)), diff --git a/datafusion/functions/src/unicode/translate.rs b/datafusion/functions/src/unicode/translate.rs index 780603777133..9257b0b04e61 100644 --- a/datafusion/functions/src/unicode/translate.rs +++ b/datafusion/functions/src/unicode/translate.rs @@ -201,7 +201,7 @@ mod tests { fn test_functions() -> Result<()> { test_function!( TranslateFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("12345")), ColumnarValue::Scalar(ScalarValue::from("143")), ColumnarValue::Scalar(ScalarValue::from("ax")) @@ -213,7 +213,7 @@ mod tests { ); test_function!( TranslateFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::Utf8(None)), ColumnarValue::Scalar(ScalarValue::from("143")), ColumnarValue::Scalar(ScalarValue::from("ax")) @@ -225,7 +225,7 @@ mod tests { ); test_function!( TranslateFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("12345")), ColumnarValue::Scalar(ScalarValue::Utf8(None)), ColumnarValue::Scalar(ScalarValue::from("ax")) @@ -237,7 +237,7 @@ mod tests { ); test_function!( TranslateFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("12345")), ColumnarValue::Scalar(ScalarValue::from("143")), ColumnarValue::Scalar(ScalarValue::Utf8(None)) @@ -249,7 +249,7 @@ mod tests { ); test_function!( TranslateFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("é2íñ5")), ColumnarValue::Scalar(ScalarValue::from("éñí")), ColumnarValue::Scalar(ScalarValue::from("óü")), @@ -262,7 +262,7 @@ mod tests { #[cfg(not(feature = "unicode_expressions"))] test_function!( TranslateFunc::new(), - &[ + vec![ ColumnarValue::Scalar(ScalarValue::from("12345")), ColumnarValue::Scalar(ScalarValue::from("143")), ColumnarValue::Scalar(ScalarValue::from("ax")), diff --git a/datafusion/physical-expr/src/scalar_function.rs b/datafusion/physical-expr/src/scalar_function.rs index 45f77325eea3..e312d5de59fb 100644 --- a/datafusion/physical-expr/src/scalar_function.rs +++ b/datafusion/physical-expr/src/scalar_function.rs @@ -134,20 +134,20 @@ impl PhysicalExpr for ScalarFunctionExpr { } fn evaluate(&self, batch: &RecordBatch) -> Result { - let inputs = self + let args = self .args .iter() .map(|e| e.evaluate(batch)) .collect::>>()?; - let input_empty = inputs.is_empty(); - let input_all_scalar = inputs + let input_empty = args.is_empty(); + let input_all_scalar = args .iter() .all(|arg| matches!(arg, ColumnarValue::Scalar(_))); // evaluate the function let output = self.fun.invoke_with_args(ScalarFunctionArgs { - args: inputs.as_slice(), + args, number_rows: batch.num_rows(), return_type: &self.return_type, })?;