apache / apache/datafusion

Be able to cast struct to have non-nullable inner field

Open
#22,709 2 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?

these work:

```sql
> select arrow_cast(struct(10), 'Struct("c0": nullable Int64)');
+--------------------------------------------------------------------+
| arrow_cast(struct(Int64(10)),Utf8("Struct("c0": nullable Int64)")) |
+--------------------------------------------------------------------+
| {c0: 10} |
+--------------------------------------------------------------------+
1 row(s) fetched.
Elapsed 0.065 seconds.

> select arrow_cast(10, 'List(non-null Int64)');
+----------------------------------------------------+
| arrow_cast(Int64(10),Utf8("List(non-null Int64)")) |
+----------------------------------------------------+
| [10] |
+----------------------------------------------------+
1 row(s) fetched.
Elapsed 0.010 seconds.
```

this doesn't work, when field is specified to be non-nullable inside a struct:

```sql
> select arrow_cast(struct(10), 'Struct("c0": non-null Int64)');
Optimizer rule 'simplify_expressions' failed
caused by
This feature is not implemented: Unsupported CAST from Struct("c0": Int64) to Struct("c0": non-null Int64)
```

### Describe the solution you'd like

see if its possible to implement this support? it seems to work for lists but not structs, so not sure if this is a limitation or theres a valid reason to not allow this

### Describe alternatives you've considered

_No response_

### Additional context

i think somewhere around here in the codebase?

https://github.com/apache/datafusion/blob/5c92390921d8d667aa7cb7d56276a59ba36926f4/datafusion/physical-expr/src/expressions/cast.rs#L384-L416

Contributor guide

Open the contributing guide

Research direction

Start in datafusion/physical-expr/src/expressions/cast.rs around lines 384-416, where the issue identifies struct casting behavior. Trace how nullable and non-nullable list casts are handled, then determine the corresponding struct path. Done means the shown arrow_cast(struct(10), 'Struct("c0": non-null Int64)') expression succeeds without the unsupported-cast error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.