Skip to content

Improve error message for wrong argument type in operators #11250

@2010YOUY01

Description

@2010YOUY01

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

> 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: #6396

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions