fix: avoid internal errors for OneOf signature mismatches#21032
fix: avoid internal errors for OneOf signature mismatches#21032myandpr wants to merge 2 commits intoapache:mainfrom
Conversation
|
fixed ci |
f13570a to
8866d95
Compare
|
The current CI failures are due to an outdated The failing That was fixed in #21050. I have rebased this branch onto the latest |
|
Hi @martin-g, just a gentle ping on this PR when you have a chance. Thanks! |
| ); | ||
|
|
||
| let err = fields_with_udf(¤t_fields, &MockUdf(signature)).unwrap_err(); | ||
| let err = err.to_string(); |
There was a problem hiding this comment.
You can assert that the Err type is DataFusionError::Plan before calling .to_string() on it.
| ); | ||
|
|
||
| let err = fields_with_udf(¤t_fields, &MockUdf(signature)).unwrap_err(); | ||
| let err = err.to_string(); |
|
|
||
| let err = | ||
| fields_with_udf(¤t_fields, &AlwaysExecErrUdf(signature)).unwrap_err(); | ||
|
|
There was a problem hiding this comment.
Here you can assert that err is DataFusionError::Exec
| 776F726C64 | ||
|
|
||
| statement error Function 'hex' expects 1 arguments but received 2 | ||
| statement error DataFusion error: Error during planning: Function 'hex' failed to match any signature |
There was a problem hiding this comment.
IMO the previous error was more actionable by the user.
Now the user will need to consult with the documentation of hex and compare it against the way (s)he tries to use it.
There was a problem hiding this comment.
Hi @martin-g I agree the previous hex(1, 2) error was more actionable.
The current change intentionally fixes the Internal error path in TypeSignature::OneOf, but it does make some overload failures fall back to a more generic planning error. I avoided surfacing a branch-specific OneOf error directly because that turned out to be incorrect in other cases, for example mixed-arity overloads like nth_value(c5, 2, 3) or mixed-type overloads like sum(bool_col).
Do you think we should try to preserve more actionable planner diagnostics for cases like this in the current PR, or handle that in a follow-up by choosing the best OneOf planning error?
Let me know if you have any preference. Thanks!
There was a problem hiding this comment.
I do understand the reason for this PR!
Let's see what others think.
There was a problem hiding this comment.
Do you think we should try to preserve more actionable planner diagnostics for cases like this in the current PR, or handle that in a follow-up by choosing the best OneOf planning error?
It would be nice to avoid a regression in error messages, even if temporarily
How hard is it to get the old behavior back?
|
Hey @timsaucer @alamb, would appreciate another look at this PR when you have a chance. Thanks! |
Jefffrey
left a comment
There was a problem hiding this comment.
Do we have a clear example of the before & after error messages of this change? The tests only match a subset of the error message so it's hard to understand how this actually displays to the user.
I'll also link my thoughts on an approach from my previous PR: #20070 (comment)
33cf7ab to
3845631
Compare
Signed-off-by: yaommen <myanstu@163.com>
3845631 to
2ddec30
Compare
|
@alamb @Jefffrey sorry for the delayed reply. I spent some time digging into this further and also looked through the discussion in #20070. I updated the implementation to keep the The current approach is:
I also put together a few representative before/after examples from actual runs on
Would appreciate another look. Thanks. |
Which issue does this PR close?
Rationale for this change
After #18769, unsupported calls such as
SUM(Boolean)started producing misleading internal errors.The immediate problem is that
TypeSignature::OneOfaggregates branch failures into anInternal error, which then becomes visible during planning together with internalTypeSignatureClass::...details.This PR fixes that path in the shared coercion logic, while preserving more actionable diagnostics where they can be determined reliably.
This PR is still narrower than #20070: it focuses on
TypeSignature::OneOferror selection and the affected public function contracts, rather than changing the broader error-formatting flow.What changes are included in this PR?
In
datafusion/expr/src/type_coercion/functions.rs:OneOfbranch matchesOneOfresolution into anInternal errorarityerrors instead of falling back to a generic mismatchBinary -> Stringcast hintCoerciblemismatches into a concrete type error instead of falling back to a generic onePlanerrors only when no matching branch succeeds and no better planner diagnostic is availableFor aggregate functions that need semantic diagnostics beyond what the generic
OneOflogic can express:sum(Boolean)andavg(Boolean)For shared window-function implementations:
signature()offirst_value,last_value, andnth_valueso validation, candidate signatures, and introspection all reflect the real public arity contractAre these changes tested?
Yes.
Added or updated unit tests covering:
OneOfmismatches no longer returningInternal errorOneOfarity mismatches restoring concrete planning errorsCoerciblemismatches combining into a concrete type errorsum(Boolean)/avg(Boolean)Updated sqllogictests for affected user-visible errors, including:
sum(Boolean)avg(Boolean)nth_value(...)first_value(...)last_value(...)substr(...)hex(...)generate_series(...)Are there any user-facing changes?
Yes.
For failed
TypeSignature::OneOffunction calls, DataFusion now returns normal planning errors instead of anInternal error, while preserving more specific diagnostics where possible, including:Sum not supported for BooleanFor
first_value,last_value, andnth_value, the advertised candidate signatures now match the real public arity contract.