apache / apache/datafusion

Allow UDFs to return custom `Diagnostic`

Open
#15,276 15 comments 1 reaction 1 assignee Claimed by @jsai28 View on GitHub
enhancement
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

### Is your feature request related to a problem or challenge?

When implementing `ScalarUDFImpl`, `AggregateUDFImpl`, or `WindowUDFImpl`, it would be very cool to have the chance to return a custom `Diagnostic` either during the planning phase or the execution phase. Currently, you can return errors e.g. in `ScalarUDFImpl::return_type_from_args` or `ScalarUDFImpl::invoke`, but no `Span`s are available there so there's no way to construct a `Diagnostic` that highlights the call expression, or a specific argument of the function, for instance.

### Describe the solution you'd like

Add a `FnCallSpans` types that bundles:

- The `Span` for the whole call expression
- The `Span` for just the function identifier
- A `Vec`, one for each argument

Add a `diagnose` trait function (defaults to doing nothing) which is called during logical planning and is given the types of the arguments for a particular callsite, as well as an instance of `FnCallSpans`. The implementor can here construct a `Diagnostic` and return an errors that contains it. The logical planner would bubble up the error.

Also add a `FnCallSpans` field to `ScalarFunctionArgs` (and equivalently for aggregate and window functions) so the implementor, in `ScalarUDFImpl::invoke_with_args`, can create `Diagnostic`s for a particular execution as well. This shouldn't be too big of a breaking change, unless users are using struct destruction syntax with `ScalarFunctionArgs`.

### Describe alternatives you've considered

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.