Skip to content

unnest on struct and alias results in "struct_allowed: unnest on struct can only be applied at the root level of select expression." #19689

@alamb

Description

@alamb

Describe the bug

I got an internal error when running a that unnests a struct and tries to add an alais

> select unnest(unnest(column1)) as "a" from t;
Internal error: Assertion failed: struct_allowed: unnest on struct can only be applied at the root level of select expression.
This issue was likely caused by a bug in DataFusion's code. Please help us to resolve this by filing a bug report in our issue tracker: https://github.com/apache/datafusion/issues

To Reproduce

> create or replace table t as values ({foo: 1, bar:2});
0 row(s) fetched.
Elapsed 0.007 seconds.

Unnesting works great

> select unnest(column1) from t;
+-------------------------------------+-------------------------------------+
| __unnest_placeholder(t.column1).foo | __unnest_placeholder(t.column1).bar |
+-------------------------------------+-------------------------------------+
| 1                                   | 2                                   |
+-------------------------------------+-------------------------------------+
1 row(s) fetched.
Elapsed 0.008 seconds.

Unnesting with an alias results in an internal error

> select unnest(column1) as "a" from t;
Internal error: Assertion failed: struct_allowed: unnest on struct can only be applied at the root level of select expression.
This issue was likely caused by a bug in DataFusion's code. Please help us to resolve this by filing a bug report in our issue tracker: https://github.com/apache/datafusion/issues

Expected behavior

There should not be an internal error. Testing with duckdb seems to show the alias is ignored

andrewlamb@Andrews-MacBook-Pro-3:~/Software/datafusion2$ duckdb
DuckDB v1.4.3 (Andium) d1dc88f950
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
D create or replace table t as values ({foo: 1, bar:2});

D select unnest(col0) from t;
┌───────┬───────┐
│  foo  │  bar  │
│ int32 │ int32 │
├───────┼───────┤
│   12   │
└───────┴───────┘
D select unnest(col0) as "a"  from t;
┌───────┬───────┐
│  foo  │  bar  │
│ int32 │ int32 │
├───────┼───────┤
│   12   │
└───────┴───────┘


### Additional context

_No response_

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions