datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

Attach `Diagnostic` to "invalid function argument types" error

Open eliaperantoni opened this issue 1 year ago • 18 comments

Is your feature request related to a problem or challenge?

For a query like:

SELECT sum('a')

The only message that the end user of an application built atop of DataFusion sees is:

Error during planning: Execution error: User-defined coercion failed with Execution("Sum not supported for Utf8") No function matches the given name and argument types 'sum(Utf8)'. You might need to add explicit type casts.
        Candidate functions:
        sum(UserDefined)

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 the DataFusionError, 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

eliaperantoni avatar Feb 03 '25 12:02 eliaperantoni

Hi I'm interested in this ticket. Could you please assign it to me?

If you think my progress slow, feel free to ping me any time, I will try to prioritize and expedite. Thank you!

dentiny avatar Feb 04 '25 14:02 dentiny

@dentiny Absolutely! Though I don't have the permissions to assign it to you, you can write take and the GitHub bot will

eliaperantoni avatar Feb 04 '25 14:02 eliaperantoni

take

dentiny avatar Feb 04 '25 14:02 dentiny

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.

alamb avatar Feb 04 '25 16:02 alamb

Hey @dentiny how is it going with this ticket :) Can I help with anything?

eliaperantoni avatar Feb 13 '25 15:02 eliaperantoni

Hi @eliaperantoni thanks for checking! I'm still playing around df these days, should be able to get sth by EOW, do you think it's ok for you?

dentiny avatar Feb 14 '25 03:02 dentiny

Hi @eliaperantoni thanks for checking! I'm still playing around df these days, should be able to get sth by EOW, do you think it's ok for you?

Absolutely! I'm here if you need any help :)

eliaperantoni avatar Feb 14 '25 07:02 eliaperantoni

Checking the code, I found for "invalid argument type" error there're quite a few places we need to update; I update only one of them in the PR, mainly want to make sure I don't mis-understand, could followup with other PRs later on.

dentiny avatar Feb 17 '25 06:02 dentiny

@eliaperantoni I was planning to work on this, I have already made progress, my inital plan is:

  • Add span storage to ScalarFunction/AggregateFunction and plumb it from the SQL parser to the coercion layer.
  • Adjust pattern matches/constructors across planner/optimizer/unparser to compile with the new fields.
  • Wrap the coercion errors with diagnostics using those spans and add tests for both scalar and aggregate cases.

My only question was making all these changes will require touching several files, would that be appropriate for this issue. Because Without adding spans to function expressions, we’d be guessing locations and couldn’t meet the goal of highlighting the SQL source.

Let me know if you have any other feedback.

@alamb if you're available for feedback on this.

kumarUjjawal avatar Dec 13 '25 10:12 kumarUjjawal

Has this issue been solved?

RSAgr avatar Jan 02 '26 17:01 RSAgr

I don't think so

I don't think @eliaperantoni is actively working on this area any more

I am not sure if @kumarUjjawal is doing so either

alamb avatar Jan 05 '26 17:01 alamb

I was looking into it few weeks ago but currently it is not in my plans. Feel free to take a look @RSAgr

kumarUjjawal avatar Jan 06 '26 05:01 kumarUjjawal

Hi! I'm looking to make my first contribution to DataFusion, and this issue looks like a great starting point.

Is anyone currently working on this? If not, I'd love to take it on. I've already started exploring the codebase and have a rough plan for the implementation.

Thanks!

choplin avatar Jun 08 '26 09:06 choplin

Hi @choplin Thank you for the interest. I don't think anyone is working on this at the moment. Feel free to take. If you need any help let me know.

Assigned!

kumarUjjawal avatar Jun 08 '26 09:06 kumarUjjawal

Hi @choplin, are you still working on this? If it’s available, I’d love to pick it up as my first contribution to DataFusion.

aruadecarvalho avatar Oct 19 '26 12:10 aruadecarvalho

@aruadecarvalho Thank you. I've been too busy for a while to work on this, so please feel free to take it. I have already opened #23063 for this issue, but the problem is that it requires a breaking change—adding a new field to a struct to keep a span—so what we have to do is to align with the release schedule to merge the breaking change. JFYI.

choplin avatar Oct 21 '26 01:10 choplin

Thanks for the context! I’ll take this and review #23063. I’ll check with @alamb the breaking change and release timing before proceeding.

aruadecarvalho avatar Oct 21 '26 02:10 aruadecarvalho

take

aruadecarvalho avatar Oct 21 '26 02:10 aruadecarvalho