Skip to content

Commit

Permalink
test: add tests for error formatting during planning
Browse files Browse the repository at this point in the history
  • Loading branch information
avkirilishin committed Jan 4, 2025
1 parent 1173a0e commit a730194
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
4 changes: 2 additions & 2 deletions datafusion/optimizer/src/analyzer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ mod test {

let err = Projection::try_new(vec![udaf], empty).err().unwrap();
assert!(
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")
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")
);
Ok(())
}
Expand Down Expand Up @@ -1407,7 +1407,7 @@ mod test {
.err()
.unwrap()
.strip_backtrace();
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."));
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."));
Ok(())
}

Expand Down
52 changes: 52 additions & 0 deletions datafusion/sql/tests/sql_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4500,3 +4500,55 @@ fn test_custom_type_plan() -> Result<()> {

Ok(())
}

fn error_message_test(sql: &str, err_msg_starts_with: &str) {
let err = logical_plan(sql).expect_err("query should have failed");
assert!(
err.strip_backtrace().starts_with(err_msg_starts_with),
"Expected error to start with '{}', but got: '{}'",
err_msg_starts_with,
err.strip_backtrace(),
);
}

#[test]
fn test_error_message_invalid_scalar_function_signature() {
error_message_test(
"select sqrt()",
"Error during planning: sqrt does not support zero arguments",
);
error_message_test(
"select sqrt(1, 2)",
"Error during planning: Failed to coerce arguments",
);
}

#[test]
fn test_error_message_invalid_aggregate_function_signature() {
error_message_test(
"select sum()",
"Error during planning: sum does not support zero arguments",
);
// We keep two different prefixes because they clarify each other.
// It might be incorrect, and we should consider keeping only one.
error_message_test(
"select max(9, 3)",
"Error during planning: Execution error: User-defined coercion failed",
);
}

#[test]
fn test_error_message_invalid_window_function_signature() {
error_message_test(
"select rank(1) over()",
"Error during planning: The function expected zero argument but received 1",
);
}

#[test]
fn test_error_message_invalid_window_aggregate_function_signature() {
error_message_test(
"select sum() over()",
"Error during planning: sum does not support zero arguments",
);
}

0 comments on commit a730194

Please sign in to comment.