Jeadie opened a new issue, #12162:
URL: https://github.com/apache/datafusion/issues/12162
### Describe the bug
Using a datafusion table with a column (`col`) of type `List[struct[]]`.
Calling
```sql
SELECT unnest(unnest(col)) as col_name
FROM tbl
```
Results in the error
```shell
Internal error: unnest on struct can only be applied at the root level of
select expression.
This was likely caused by a bug in DataFusion's code and we would welcome
that you file an bug report in our issue tracker
```
### To Reproduce
Context
```
sql> describe test_tbl
+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+
| column_name | data_type
| is_nullable |
+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+
| id | Utf8
| YES |
| labels | List(Field { name: "item", data_type: Struct([Field { name:
"name", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false,
metadata: {} }]), nullable: true, dict_id: 0, dict_is_ordered: false, metadata:
{} }) | YES |
+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+
```
Without Alias
```
sql> select unnest(unnest(labels)) from test_tbl limit 3
+-----------------------------------------+
| unnest(unnest(test_tbl.labels)).name |
+-----------------------------------------+
| kind/bug |
| kind/enhancement |
| kind/enhancement |
+-----------------------------------------+
```
With Alias
```
sql> select unnest(unnest(labels)) as a from test_tbl limit 3
Status { code: Internal, message: "Internal error: unnest on struct can only
be applied at the root level of select expression.\nThis was likely caused by a
bug in DataFusion's code and we would welcome that you file an bug report in
our issue tracker", metadata: MetadataMap { headers: {"content-type":
"application/grpc", "date": "Mon, 26 Aug 2024 00:25:51 GMT", "content-length":
"0"} }, source: None }
```
### Expected behavior
```
sql> select unnest(unnest(labels)) as an_alias from test_tbl limit 3
+-----------------------------------------+
| an_alias.name |
+-----------------------------------------+
| kind/bug |
| kind/enhancement |
| kind/enhancement |
+-----------------------------------------+
```
### Additional context
For outputs, using [spiceai](https://github.com/spiceai/spiceai/),
specifically [spice
sql](https://github.com/spiceai/spiceai/tree/trunk/bin/spice).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]