Repository navigation
Commit 81824e8
authored
fix: report OneOf signature mismatches as planning errors (#26329)
## Which issue does this PR close?
Part of #20501.
This is a deliberately narrow slice of that issue, and it is the slice a
maintainer previously asked for: #21032 attempted this fix as a large
change (it also reworked `sum`/`avg` diagnostics and the public
`first_value`/`last_value`/`nth_value` arity contracts), was asked to be
split up, and then went stale. This PR is **one behaviour change and
nothing else**.
## Rationale for this change
`get_valid_types_with_udf` reports "no `OneOf` branch matched" with
`internal_err!`. Every alternative signature failing means the *caller*
passed the wrong number or types of arguments — a user mistake — yet the
user is told:
> This issue was likely caused by a bug in DataFusion's code. Please
help us to resolve this by filing a bug report in our issue tracker: ...
So an ordinary SQL typo invites a bug report, and the failure surfaces
as `Internal error: ...` even though nothing internal went wrong. The
maintainer comment on #20070 named exactly this ("Can try to fix the
display + internal error reference").
### Before / after
`SELECT substr(1, 2)`
Before:
```text
Error during planning: Internal error: Function 'substr' failed to match any signature, errors: Error during planning: Function 'substr' requires String, but received Int64 (DataType: Int64).,Error during planning: Function 'substr' expects 3 arguments but received 2.
This issue was likely caused by a bug in DataFusion's code. Please help us to resolve this by filing a bug report in our issue tracker: https://github.com/apache/datafusion/issues
```
After:
```text
Error during planning: Function 'substr' failed to match any signature, errors: Error during planning: Function 'substr' requires String, but received Int64 (DataType: Int64).,Error during planning: Function 'substr' expects 3 arguments but received 2.
```
The message body, the candidate signatures, and the trailing "No
function matches the given name and argument types ... You might need to
add explicit type casts." line are all unchanged. Only the `Internal
error` kind and the bug-report boilerplate are gone.
## What changes are included in this PR?
- `datafusion/expr/src/type_coercion/functions.rs`: return `plan_err!`
instead of `internal_err!` when every `OneOf` branch rejects the
arguments. One line of behaviour change.
- A unit test covering that failure. It mirrors `substr`'s real
signature, so one branch fails on the argument type and the other on the
arity.
- Ten `sqllogictest` expectations that asserted the old user-visible
text, in `array/array_range.slt`, `spark/math/round.slt`, `errors.slt`
and `math.slt`.
## Are these changes tested?
Yes.
- The new unit test fails on `main` and passes with the change; `cargo
test -p datafusion-expr --lib` is 282 passed, 0 failed.
- `cargo fmt --all --check` is clean.
- I audited every other expectation of this message. The remaining ones
— `functions.slt`, `aggregate.slt`, `string_literal.slt`,
`named_arguments.slt`, and one assertion in
`datafusion/optimizer/src/analyzer/type_coercion.rs` — match on a
substring that does not include the removed prefix, so they are
unaffected. No `sqllogictest` file asserted the "This issue was likely
caused by a bug..." boilerplate.
I could not run the full `sqllogictest` suite locally (it needs a full
`datafusion-core` build), so CI is the verification for the four updated
`.slt` files.
## Scope
Deliberately left out, to keep this reviewable:
- the message is still verbose and still prefixes every branch error
with `Error during planning:` — that is #19004;
- `errors.join(",")` still runs the branch errors together without a
separator, which is why the after-message reads `...(DataType:
Int64).,Error during planning: ...`;
- the arity phrasing suggested on #20070 (`log expects 1 to 2 arguments,
got 3`) is a separate improvement.
Happy to follow up on any of those in separate PRs.1 parent 9f4b005 commit 81824e8
5 files changed
Lines changed: 16 additions & 12 deletions
File tree
- datafusion
- expr/src/type_coercion
- sqllogictest/test_files
- array
- spark/math
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
559 | 559 | | |
560 | 560 | | |
561 | 561 | | |
562 | | - | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
563 | 567 | | |
564 | | - | |
| 568 | + | |
565 | 569 | | |
566 | 570 | | |
567 | 571 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | | - | |
| 247 | + | |
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
251 | | - | |
| 251 | + | |
252 | 252 | | |
253 | 253 | | |
254 | | - | |
| 254 | + | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
| 181 | + | |
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
593 | 593 | | |
594 | 594 | | |
595 | 595 | | |
596 | | - | |
| 596 | + | |
597 | 597 | | |
598 | 598 | | |
599 | 599 | | |
600 | | - | |
| 600 | + | |
601 | 601 | | |
602 | 602 | | |
603 | 603 | | |
604 | | - | |
| 604 | + | |
605 | 605 | | |
0 commit comments