From 88de0520ff7c61251627f1f770700b4e5c8e8147 Mon Sep 17 00:00:00 2001 From: Shicong Date: Thu, 9 Jan 2025 21:44:18 +0800 Subject: [PATCH 1/3] minor fix --- datafusion/expr/src/type_coercion/functions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datafusion/expr/src/type_coercion/functions.rs b/datafusion/expr/src/type_coercion/functions.rs index 96bb5c4b2d8f..2e65ee37f1ef 100644 --- a/datafusion/expr/src/type_coercion/functions.rs +++ b/datafusion/expr/src/type_coercion/functions.rs @@ -440,13 +440,13 @@ fn get_valid_types( fn function_length_check(length: usize, expected_length: usize) -> Result<()> { if length < 1 { return plan_err!( - "The signature expected at least one argument but received {expected_length}" + "The signature expected at least one argument but received {length}" ); } if length != expected_length { return plan_err!( - "The signature expected {length} arguments but received {expected_length}" + "The signature expected {expected_length} arguments but received {length}" ); } From f477bf928cb4800f88aee8b56604d41a65381e58 Mon Sep 17 00:00:00 2001 From: Shicong Date: Thu, 9 Jan 2025 21:54:48 +0800 Subject: [PATCH 2/3] add ut --- .../expr/src/type_coercion/functions.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/datafusion/expr/src/type_coercion/functions.rs b/datafusion/expr/src/type_coercion/functions.rs index 2e65ee37f1ef..008b40126bba 100644 --- a/datafusion/expr/src/type_coercion/functions.rs +++ b/datafusion/expr/src/type_coercion/functions.rs @@ -939,6 +939,7 @@ mod tests { use super::*; use arrow::datatypes::Field; + use datafusion_common::assert_contains; #[test] fn test_string_conversion() { @@ -1027,6 +1028,29 @@ mod tests { Ok(()) } + #[test] + fn test_get_valid_types_length_check() -> Result<()> { + let signature = TypeSignature::Numeric(1); + + let err = get_valid_types(&signature, &[]).unwrap_err(); + assert_contains!( + err.to_string(), + "The signature expected at least one argument but received 0" + ); + + let err = get_valid_types( + &signature, + &[DataType::Int32, DataType::Int32, DataType::Int32], + ) + .unwrap_err(); + assert_contains!( + err.to_string(), + "The signature expected 1 arguments but received 3" + ); + + Ok(()) + } + #[test] fn test_fixed_list_wildcard_coerce() -> Result<()> { let inner = Arc::new(Field::new_list_field(DataType::Int32, false)); From f7064f18662cb33ab1964ba9ccc7c56c37fd7372 Mon Sep 17 00:00:00 2001 From: Shicong Date: Fri, 10 Jan 2025 10:25:29 +0800 Subject: [PATCH 3/3] remove check for 0 arg --- datafusion/expr/src/type_coercion/functions.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/datafusion/expr/src/type_coercion/functions.rs b/datafusion/expr/src/type_coercion/functions.rs index 008b40126bba..5294cc526d38 100644 --- a/datafusion/expr/src/type_coercion/functions.rs +++ b/datafusion/expr/src/type_coercion/functions.rs @@ -438,18 +438,11 @@ fn get_valid_types( } fn function_length_check(length: usize, expected_length: usize) -> Result<()> { - if length < 1 { - return plan_err!( - "The signature expected at least one argument but received {length}" - ); - } - if length != expected_length { return plan_err!( "The signature expected {expected_length} arguments but received {length}" ); } - Ok(()) } @@ -1035,7 +1028,7 @@ mod tests { let err = get_valid_types(&signature, &[]).unwrap_err(); assert_contains!( err.to_string(), - "The signature expected at least one argument but received 0" + "The signature expected 1 arguments but received 0" ); let err = get_valid_types(