-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Attach Diagnostic
to "wrong number of arguments" error
#14432
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
Comments
Diagnostic
to "wrong number of arguments" error
take |
I think this is a good first issue as the need is clear and the tests in https://github.com/apache/datafusion/blob/85fbde2661bdb462fc498dc18f055c44f229604c/datafusion/sql/tests/cases/diagnostic.rs are well structured for extension. |
Hey @Chen-Yuan-Lai how is it going with this ticket :) Can I help with anything? |
Hi @eliaperantoni sorry for the long delay. I’ve been taking some time to familiarize myself with this issue. I found that the "wrong number of argument" error may occur in different places depending on what function is called. For example,
Should I:
Another stupid question is how to test the queries above correctly because I always get "expected diagnostic" error even though I have attached return plan_err!(
"Function '{function_name}' expects {expected_length} arguments but received {length}"
).map_err(|err| {
err.with_diagnostic(
Diagnostic::new_error(
format!("Function '{function_name}' expects {expected_length} arguments but received {length}"),
None,
)
)
}); Is something wrong with this or do I need to do something else? These are problems I met in this issue, I am looking forward to some hints or ideas, thanks so mush! |
Hey @Chen-Yuan-Lai, absolutely no problem! Was checking in to see if you needed any help 😊. I see, that's a bit unfortunate. It seems like the first message is produced by a function called I see that Then the problem would be to get the
That probably has something to do with the implementation of |
@eliaperantoni thanks for the advice! I will try that as soon as possible |
Hi @eliaperantoni I found that
Once the error macro (ex. This is the [datafusion/expr/src/type_coercion/functions.rs:304:17] &e = Diagnostic(
Diagnostic {
kind: Error,
message: "Wrong number of arguments for sum function call",
span: None,
notes: [],
helps: [],
},
Execution(
"sum function requires 1 argument, got 2",
),
)
[datafusion/expr/src/expr_schema.rs:166:25] &err = Execution(
"Function 'sum' user-defined coercion failed with \"Execution error: sum function requires 1 argument, got 2\"",
)
[datafusion/sql/tests/cases/diagnostic.rs:52:17] &err = Plan(
"Execution error: Function 'sum' user-defined coercion failed with \"Execution error: sum function requires 1 argument, got 2\" No function matches the given name and argument types 'sum(Int64, Int64)'. You might need to add explicit type casts.\n\tCandidate functions:\n\tsum(UserDefined)",
) I think there are two solutions:
But 1. seems to have a large effect on the codebase, I'm not sure which one is better. I hope to get some suggestions or other best practices, thx so much!! |
Hey @Chen-Yuan-Lai, thank you so much for your contributions 🙏 That is indeed an annoying issue. It seems like some of the error macros "flatten" the inner error to a string. I think I'm in favour of option 2, in hope that there are not too many places where this flattening happens. I wouldn't go for option 1 because, as you say, it would change all existing macro invocations. Perhaps we want is a
i.e. then you would do: let err1 = exec_err!("need to download more RAM");
let err2 = err1.with_diagnostic(...);
let err3 = err2.map_diagnosticed_err(|err|
plan_err!("that went wrong {}", err);
); And now I'm not sure if this would work or make for a good implementation, but I hope it can help in any way :) |
Hi! I'm currently preparing my GSoC 2025 application and would love to contribute to this issue as a warm-up task. I understand this one involves attaching a I saw the previous discussion and understand there are some challenges with layered errors, but I'm happy to give it a try and ask questions as I go. Would it be okay if I start working on this? Thanks in advance! |
Sorry, @prowang01. I have already been working on it, but if you have a more comprehensive implementation, feel free to work on it :) |
@eliaperantoni, sorry for the long delay. I pushed a rough implementation for the issue, I noticed that you are working on the Would it make sense to wait for that implementation to be completed? :) |
This approach sounds great! but in this case, I still need to get argument numbers in the |
@Chen-Yuan-Lai I only filed the ticket, but it's @jsai28 working on that feature :) You're definitely right though: these two tickets do have some overlap and we should make sure the resulting API makes sense overall. In my personal view, #15276 is more about giving custom functions the ability to optionally implement a But I think Datafusion should be able to return For example, the The goal of this ticket is to make similar errors I think this ticket actually overlaps more with #14431 than with #15276 so perhaps you and @dentiny could align on it? 😊 The difficulty lies in Proposal:
Does that make sense? Sorry I realize that this must be very confusing. In general it's going to be a bit difficult to map the concept of "arguments don't match any of the available signatures" to a nicer user message. My proposal is not really a complete plan but more of a spark to ignite a discussion together with @Chen-Yuan-Lai and @dentiny so we can find a good solution ❤️ |
Thank you for the care ❤️ |
Hi @eliaperantoni, I spent some time investigating additional locations in the codebase where argument numbers for most SQL functions are checked. I've roughly classified them into four categories:
Based on these findings, I've discovered that the same argument checking logic is redundantly implemented in many places. Furthermore, some of these checks might never be triggered. For example, Therefore, I propose creating a new function to integrate checking logic for all signature variants in a single place. This approach offers several benefits:
Regarding your proposal:
I believe this new function can also handle the case of I've nearly completed this function in my draft PR, but I'd like your feedback on whether this approach makes sense. I'm happy to discuss more details or explore alternatives. Thanks! |
Is your feature request related to a problem or challenge?
For a query like:
The only message that the end user of an application built atop of DataFusion sees is:
We want to provide a richer message that references and highlights locations in the original SQL query, and contextualises and helps the user understand the error. In the end, it would be possible to display errors in a fashion akin to what was enabled by #13664 for some errors:
See #14429 for more information.
Describe the solution you'd like
Attach a well crafted
Diagnostic
to theDataFusionError
, building on top of the foundations laid in #13664. See #14429 for more information.Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: