apache / apache/datafusion

The functions in `type_coercion` should return `Result`, not `Option`

Open
#4,165 0 comments 0 reactions 0 assignees 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? Please describe what you are trying to do.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
(This section helps Arrow developers understand the context and *why* for this feature, in addition to the *what*)
Currently, in the `type_coercion` mod, we have some pub functions returning `Result`, such as
```rust
pub fn coerce_types(
lhs_type: &DataType,
op: &Operator,
rhs_type: &DataType,
) -> Result {
```
, and others returning `Option`:
```rust
pub fn comparison_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option {
```

We should let all of them to return `Result` so that we can find the error as early as possible. Currently, we do the conversion from `None` to `Error` in the downstream code:
```rust
let case_when_coerce_type =
get_coerce_type_for_case_when(&then_types, &else_type);
match case_when_coerce_type {
None => Err(DataFusionError::Internal(format!(
"Failed to coerce then ({:?}) and else ({:?}) to common types in CASE WHEN expression",
then_types, else_type
))),
```
, which should be avoided.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.

Contributor guide

Open the contributing guide

Research direction

Start at the `type_coercion` module and inventory its public functions that return `Option`, including `comparison_coercion`. Trace callers such as `get_coerce_type_for_case_when` and the CASE WHEN conversion shown in the issue; done means these functions return `Result` and callers propagate their errors instead of converting `None` downstream.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.