jleibs opened a new issue, #11419:
URL: https://github.com/apache/datafusion/issues/11419
### Is your feature request related to a problem or challenge?
We frequently work with tables made up of "batch" data, which is in turn
represented via structs.
For example:
```
+--------------------------------------+
| example.MyPoints |
+--------------------------------------+
| [{x: 1.0, y: 2.0}, {x: 3.0, y: 4.0}] |
| [{x: 5.0, y: 6.0}] |
+--------------------------------------+
```
I want to be able to restructure this so the inner fields of the struct
array become their own columns:
```
+------------+------------+
| X | Y |
+------------+------------+
| [1.0, 3.0] | [2.0, 4.0] |
| [5.0] | [6.0] |
+------------+------------+
```
### Describe the solution you'd like
I would like to be able to do this from SQL.
For example:
```
SELECT array_field(\"example.MyPoint\", "X") as X,
array_field(\"example.MyPoint\", "Y") FROM custom_table
```
### Describe alternatives you've considered
I've tried to come up with some way to use `unnest` to achieve this but
can't figure out how to preserve the list.
Example:
```
> CREATE TABLE example_table AS
SELECT * FROM (
VALUES
(ARRAY[NAMED_STRUCT('x', 1.0, 'y', 2.0), NAMED_STRUCT('x', 3.0, 'y',
4.0)]),
(ARRAY[NAMED_STRUCT('x', 5.0, 'y', 6.0)])
) as example_table(mypoints);
> select make_array(px) from (select p.x as px from (select unnest(mypoints)
as p from example_table));
+----------------+
| make_array(px) |
+----------------+
| [1.0] |
| [3.0] |
| [5.0] |
+----------------+
```
### Additional context
_No response_
--
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]