Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add detailed error for sum::coerce_type #14710

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dentiny
Copy link

@dentiny dentiny commented Feb 17, 2025

Which issue does this PR close?

What changes are included in this PR?

This PR integrates Diagnostic into Sum::coerce_type.

Reading through the code, there're quite a few function worth updating for "invalid function argument type" category, this PR only updates one particular function.

@github-actions github-actions bot added logical-expr Logical plan and expressions functions labels Feb 17, 2025
@github-actions github-actions bot added sql SQL Planner common Related to common crate labels Feb 17, 2025
@dentiny dentiny changed the title Add detailed error for sum::coerce_type chore: Add detailed error for sum::coerce_type Feb 17, 2025
@alamb
Copy link
Contributor

alamb commented Feb 17, 2025

Fyi @eliaperantoni -- can you give this PR a review?

Copy link
Contributor

@eliaperantoni eliaperantoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I don't quite think this is the correct approach. You're adding Diagnostic in one function implementation provided by datafusion::functions_aggregate. This won't work with custom UDFs that are registered in the SessionState by third party applications using DataFusion.

I would prefer if we enriched with diagnostics the errors that DataFusion already returns in a generic way for all functions, even those that are not provided in datafusion::function*, leveraging DataFusion's type system.

Comment on lines +170 to +175
let diagnostic = Diagnostic::new_error(
format!(
"Coercion only supports integer and floating point values"
),
sum.spans().first(),
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "Coercion only supports integer and floating point values" is a message that an end user of an application built on DataFusion can understand. Perhaps something like 'sum' only works on numeric values?

Comment on lines +283 to +291
#[test]
fn test_sum_coerce_type() -> Result<()> {
let mut sum = Sum::new();
let span = Span::new(Location::new(1, 1), Location::new(2, 1));
let span_for_test = span;
sum.spans_mut().add_span(span);
let datatype_vec = vec![DataType::Date64];
let res = sum.coerce_types(&datatype_vec);
let err = res.expect_err("Expected an error, but got success");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the same setup as other tests in this file? e.g. get_spans, run_query, etc.

@alamb
Copy link
Contributor

alamb commented Feb 20, 2025

Thank you @dentiny !

Looks like this PR has some good comments from @eliaperantoni and needs a fix for cargo clippy to get a clean CI run, but otherwise is 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Related to common crate functions logical-expr Logical plan and expressions sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attach Diagnostic to "invalid function argument types" error
3 participants