apache / apache/datafusion

Improve error message for wrong argument type in operators

Open
#11,250 8 comments 2 reactions 1 assignee Claimed by @Acfboy View on GitHub
enhancement help wanted
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 input arguments of unsupported type, scalar functions will return user-friendly error message:
```
> select abs(1,2,3);
Error during planning: Error during planning: The function expected 1 arguments but received 3 No function matches the given name and argument types 'abs(Int64, Int64, Int64)'. You might need to add explicit type casts.
Candidate functions:
abs(Any)
> select round(3.14, 2.5);
Error during planning: Error during planning: Coercion from [Float64, Float64] to the signature OneOf([Exact([Float64, Int64]), Exact([Float32, Int64]), Exact([Float64]), Exact([Float32])]) failed. No function matches the given name and argument types 'round(Float64, Float64)'. You might need to add explicit type casts.
Candidate functions:
round(Float64, Int64)
round(Float32, Int64)
round(Float64)
round(Float32)
```

But operators don't support it: but operators' behaviour is similar to scalar function, they both take several input argument, and return some value, maybe it's possible to also support better error message for [operators](https://datafusion.apache.org/user-guide/sql/operators.html)
```
> select NOT 1.5;
type_coercion
caused by
Error during planning: Cannot infer common argument type for comparison operation Float64 IS DISTINCT FROM Boolean
> select 2.0 << 3.5;
Internal error: Data type Float64 not supported for binary operation 'bitwise_shift_left' on dyn arrays.
This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker
```
`DuckDB` seems to (partly..) unify their implementation, and the error message is very informative
```
duckdb> select 2.0 << 3.5;
Binder Error: No function matches the given name and argument types '<<(DECIMAL(2,1), DECIMAL(2,1))'. You might need to add explicit type casts.
Candidate functions:
<<(TINYINT, TINYINT) -> TINYINT
<<(SMALLINT, SMALLINT) -> SMALLINT
<<(INTEGER, INTEGER) -> INTEGER
<<(BIGINT, BIGINT) -> BIGINT
<<(HUGEINT, HUGEINT) -> HUGEINT
<<(UTINYINT, UTINYINT) -> UTINYINT
<<(USMALLINT, USMALLINT) -> USMALLINT
<<(UINTEGER, UINTEGER) -> UINTEGER
<<(UBIGINT, UBIGINT) -> UBIGINT
<<(UHUGEINT, UHUGEINT) -> UHUGEINT
<<(BIT, INTEGER) -> BIT

LINE 1: select 2.0 << 3.5;
```

A reference implementation for functions' error message: https://github.com/apache/datafusion/issues/6396

### Describe the solution you'd like

_No response_

### 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.