apache / apache/druid

COALESCE does not work with empty strings as documentation states it would

Open
#9,416 3 comments 0 reactions 0 assignees View on GitHub
Area - SQL Bug
Dominant language
Java
Stars
14.1k
Forks
3.8k
Avg merge
2d 58m
Merged PRs (30d)
233

Description

### Affected Version
0.16.0 and 0.17.0

### Description

COALESCE does NOT work with empty strings

```
SELECT
COALESCE('something', 'fallback') AS tst1,
COALESCE(null, 'fallback') AS tst2,
COALESCE('', 'fallback') AS tst3
```
this yields
"something", "fallback", ""

According to the documentation, the third projection should also yield the output "fallback"
> COALESCE(value1, value2, ...) | Returns the first value that is neither NULL nor empty string.

I would petition to keep the documentation as is and modify the function behaviour to be conformant to the documentation as it would be quite useful if COALESCE could also deal with empty strings.

Contributor guide

Open the contributing guide

Research direction

Reproduce the reported COALESCE query against the affected Druid versions, then locate the COALESCE implementation and its documentation entry. Confirm the intended handling of empty strings and add or update coverage so the query returns "fallback" for the empty-string case.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.