Skip to content

Commit 268df42

Browse files
authored
fix: incorrect error message of function_length_check (#14056)
* minor fix * add ut * remove check for 0 arg
1 parent 300c2af commit 268df42

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

datafusion/expr/src/type_coercion/functions.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,18 +438,11 @@ fn get_valid_types(
438438
}
439439

440440
fn function_length_check(length: usize, expected_length: usize) -> Result<()> {
441-
if length < 1 {
442-
return plan_err!(
443-
"The signature expected at least one argument but received {expected_length}"
444-
);
445-
}
446-
447441
if length != expected_length {
448442
return plan_err!(
449-
"The signature expected {length} arguments but received {expected_length}"
443+
"The signature expected {expected_length} arguments but received {length}"
450444
);
451445
}
452-
453446
Ok(())
454447
}
455448

@@ -939,6 +932,7 @@ mod tests {
939932

940933
use super::*;
941934
use arrow::datatypes::Field;
935+
use datafusion_common::assert_contains;
942936

943937
#[test]
944938
fn test_string_conversion() {
@@ -1027,6 +1021,29 @@ mod tests {
10271021
Ok(())
10281022
}
10291023

1024+
#[test]
1025+
fn test_get_valid_types_length_check() -> Result<()> {
1026+
let signature = TypeSignature::Numeric(1);
1027+
1028+
let err = get_valid_types(&signature, &[]).unwrap_err();
1029+
assert_contains!(
1030+
err.to_string(),
1031+
"The signature expected 1 arguments but received 0"
1032+
);
1033+
1034+
let err = get_valid_types(
1035+
&signature,
1036+
&[DataType::Int32, DataType::Int32, DataType::Int32],
1037+
)
1038+
.unwrap_err();
1039+
assert_contains!(
1040+
err.to_string(),
1041+
"The signature expected 1 arguments but received 3"
1042+
);
1043+
1044+
Ok(())
1045+
}
1046+
10301047
#[test]
10311048
fn test_fixed_list_wildcard_coerce() -> Result<()> {
10321049
let inner = Arc::new(Field::new_list_field(DataType::Int32, false));

0 commit comments

Comments
 (0)