apache / apache/datafusion

Improve error messages when coercion fails

Open
#19,004 10 comments 0 reactions 1 assignee Claimed by @saadtajwar 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?

After https://github.com/apache/datafusion/pull/18820 is merged, running this query:

```sql
select array_slice(arrow_cast(make_array(1, 2, 3, 4, 5), 'ListView(Int64)'), 0, 6),
array_slice(arrow_cast(make_array('h', 'e', 'l', 'l', 'o'), 'ListView(Utf8)'), 0, 5);
```

Results in a very hard to interpret error message:

> DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to 'array_slice' function: coercion from ListView(Int64), Int64, Int64 to the signature OneOf([ArraySignature(Array { arguments: [Array, Index, Index], array_coercion: Some(FixedSizedListToList) }), ArraySignature(Array { arguments: [Array, Index, Index, Index], array_coercion: Some(FixedSizedListToList) })]) failed No function matches the given name and argument types 'array_slice(ListView(Int64), Int64, Int64)'. You might need to add explicit type casts.

As a user I would be pretty hard pressed to understand the actual problem is that array_slice doesn't support the `ListView` type

### Describe the solution you'd like

I would like the error message to be more human readable

### Describe alternatives you've considered

The error message for array_reverse seems much easier to understand:
```sql
> select array_reverse(arrow_cast(make_array(1, 2, 3, 4, 5), 'ListView(Int64)'));

Error during planning: array_reverse does not support type ListView(Int64) No function matches the given name and argument types 'array_reverse(ListView(Int64))'. You might need to add explicit type casts.
Candidate functions:
array_reverse(array)```
```

Perhaps something like

```sql
DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to 'array_slice' function. You might need to add explicit type casts.
Candidate functions:
array_slice(array, index, index)
array_slice(array index, index, index)
```

I am not really sure how to work in the information that "Array" in this context means ListArray, LargeListArray or FixedSizeListArray

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