Nested coalesce
- 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?
`coalsece` currently does not support structs. If it would however, I think it should only consider top-level NULLs, so `coalsece(NULL, {a: 1, b: NULL}, {a: 2, b: 3}) = {a: 1, b: NULL}`. However sometimes it would be handy to fill in fields recursively. So `coalsece_nested(NULL, {a: 1, b: NULL}, {a: 2, b: 3}) = {a: 1, b: 3}`
### Describe the solution you'd like
Have a `coalesce` variant that supports structs by traversing them recursively. So:
```sql
coalesce_nested(
NULL,
{
a: 1,
b: NULL,
c: NULL,
d: NULL,
},
{
a: 2,
b: NULL,
c: {a: NULL},
d: {a: 2, b: NULL},
},
{
a: 3,
b: NULL,
c: NULL,
d: {a: 3, b: 3},
},
)
=
{
a: 1,
b: NULL,
c: {a: NULL},
d: {a: 2, b: 3},
}
```
### Describe alternatives you've considered
\-
### Additional context
A user that fully knows the type could manually construct this using `coalesce` and `named_struct` (proposed in #5861).
#### Prior art:
- [PostgresQL `pg_rowalesce` extension](https://pgxn.org/dist/pg_rowalesce/)
Contributor guide
Research direction
Start by tracing the existing coalesce function and the named_struct functionality referenced in the issue, then inspect how DataFusion represents and evaluates struct values. Use the SQL examples as behavioral checks; done means a coalesce variant recursively fills NULL struct fields while preserving the shown top-level and nested results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, sql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100