Skip to content

Commit a730194

Browse files
committed
test: add tests for error formatting during planning
1 parent 1173a0e commit a730194

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

datafusion/optimizer/src/analyzer/type_coercion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ mod test {
13571357

13581358
let err = Projection::try_new(vec![udaf], empty).err().unwrap();
13591359
assert!(
1360-
err.strip_backtrace().starts_with("Error during planning: Error during planning: Failed to coerce arguments to satisfy a call to MY_AVG function: coercion from [Utf8] to the signature Uniform(1, [Float64]) failed")
1360+
err.strip_backtrace().starts_with("Error during planning: Failed to coerce arguments to satisfy a call to MY_AVG function: coercion from [Utf8] to the signature Uniform(1, [Float64]) failed")
13611361
);
13621362
Ok(())
13631363
}
@@ -1407,7 +1407,7 @@ mod test {
14071407
.err()
14081408
.unwrap()
14091409
.strip_backtrace();
1410-
assert!(err.starts_with("Error during planning: Error during planning: Failed to coerce arguments to satisfy a call to avg function: coercion from [Utf8] to the signature Uniform(1, [Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64]) failed."));
1410+
assert!(err.starts_with("Error during planning: Failed to coerce arguments to satisfy a call to avg function: coercion from [Utf8] to the signature Uniform(1, [Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64]) failed."));
14111411
Ok(())
14121412
}
14131413

datafusion/sql/tests/sql_integration.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4500,3 +4500,55 @@ fn test_custom_type_plan() -> Result<()> {
45004500

45014501
Ok(())
45024502
}
4503+
4504+
fn error_message_test(sql: &str, err_msg_starts_with: &str) {
4505+
let err = logical_plan(sql).expect_err("query should have failed");
4506+
assert!(
4507+
err.strip_backtrace().starts_with(err_msg_starts_with),
4508+
"Expected error to start with '{}', but got: '{}'",
4509+
err_msg_starts_with,
4510+
err.strip_backtrace(),
4511+
);
4512+
}
4513+
4514+
#[test]
4515+
fn test_error_message_invalid_scalar_function_signature() {
4516+
error_message_test(
4517+
"select sqrt()",
4518+
"Error during planning: sqrt does not support zero arguments",
4519+
);
4520+
error_message_test(
4521+
"select sqrt(1, 2)",
4522+
"Error during planning: Failed to coerce arguments",
4523+
);
4524+
}
4525+
4526+
#[test]
4527+
fn test_error_message_invalid_aggregate_function_signature() {
4528+
error_message_test(
4529+
"select sum()",
4530+
"Error during planning: sum does not support zero arguments",
4531+
);
4532+
// We keep two different prefixes because they clarify each other.
4533+
// It might be incorrect, and we should consider keeping only one.
4534+
error_message_test(
4535+
"select max(9, 3)",
4536+
"Error during planning: Execution error: User-defined coercion failed",
4537+
);
4538+
}
4539+
4540+
#[test]
4541+
fn test_error_message_invalid_window_function_signature() {
4542+
error_message_test(
4543+
"select rank(1) over()",
4544+
"Error during planning: The function expected zero argument but received 1",
4545+
);
4546+
}
4547+
4548+
#[test]
4549+
fn test_error_message_invalid_window_aggregate_function_signature() {
4550+
error_message_test(
4551+
"select sum() over()",
4552+
"Error during planning: sum does not support zero arguments",
4553+
);
4554+
}

0 commit comments

Comments
 (0)