apache / apache/datafusion

Conditional expressions should only evaluate "else" predicate if "if" predicate is false

Open
#5,093 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

**Describe the bug**

For conditional expressions, we currently evaluate both the true and false expressions, which can lead to correctness issues.

For example, we cannot run this valid query.

```
❯ select case when x is null then 42 else x * x end from (select null as x);
ArrowError(ExternalError(Internal("Data type Null not supported for binary operation 'multiply' on primitive arrays")))
```

**To Reproduce**

**Expected behavior**

**Additional context**

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided SELECT CASE query and trace DataFusion's conditional-expression evaluation to find where both branches are evaluated. Done means the query returns 42 without the invalid multiplication error, with regression coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
databases
Issue type
Bug
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.