goldmedal opened a new issue, #13601:
URL: https://github.com/apache/datafusion/issues/13601
### Is your feature request related to a problem or challenge?
Given a SQL:
```SQL
select * from unnest([1,2,3]) as t(c1)
```
DataFusion plans the unnest to `Projection/Unnest/Projection` pattern like
```
Projection: *
SubqueryAlias: t
Projection: UNNEST(make_array(Int64(1),Int64(2),Int64(3))) AS c1
Projection:
unnest_placeholder(make_array(Int64(1),Int64(2),Int64(3)),depth=1) AS
UNNEST(make_array(Int64(1),Int64(2),Int64(3)))
Unnest:
lists[unnest_placeholder(make_array(Int64(1),Int64(2),Int64(3)))|depth=1]
structs[]
Projection: make_array(Int64(1), Int64(2), Int64(3)) AS
unnest_placeholder(make_array(Int64(1),Int64(2),Int64(3)))
EmptyRelation
```
If we try to unparse the plan back to the SQL, the result is
```
SELECT * FROM (SELECT UNNEST([1, 2, 3]) AS
"UNNEST(make_array(Int64(1),Int64(2),Int64(3)))") AS t (c1)
```
However, some databases (e.g.
[BigQuery](https://cloud.google.com/bigquery/docs/arrays#querying_nested_arrays)),
only support using `UNNEST` as a table function.
### Describe the solution you'd like
We can introduce a new option for the unparser `Dialect`
```rust
pub trait Dialect: Send + Sync {
...
/// Allow to unparse the unnest plan as a table function.
fn unnest_as_table_function(&self) -> bool {
false
}
...
}
```
If we found the pattern of plan like `Projection/Unnest/Projection`, we can
try to unparse it to an `ast::query::TableFactor::UNNEST`.
### Describe alternatives you've considered
_No response_
### Additional context
We may need to ignore other instances of `UNNEST` usage, such as:
```sql
SELECT UNNEST(column1), UNNEST(column2) FROM (SELECT column1, column2 FROM
xxx);
```
This issue aims to enable a roundtrip for the `UNNEST` table function.
--
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]