You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "goldmedal (via GitHub)" <gi...@apache.org> on 2024/12/02 03:59:34 UTC
[I] Unparse `UNION` plan with multiple inputs to SQL text [datafusion]
goldmedal opened a new issue, #13621:
URL: https://github.com/apache/datafusion/issues/13621
### Is your feature request related to a problem or challenge?
Given a SQL like
```sql
WITH vals AS
(
SELECT 1 x, 'a' y UNION ALL
SELECT 1 x, 'b' y UNION ALL
SELECT 2 x, 'a' y UNION ALL
SELECT 2 x, 'c' y
)
SELECT x, y
FROM vals
```
The unoptimized plan is
```
Projection: vals.x, vals.y
SubqueryAlias: vals
Union
Union
Union
Projection: Int64(1) AS x, Utf8("a") AS y
EmptyRelation
Projection: Int64(1) AS x, Utf8("b") AS y
EmptyRelation
Projection: Int64(2) AS x, Utf8("a") AS y
EmptyRelation
Projection: Int64(2) AS x, Utf8("c") AS y
EmptyRelation
```
It's fine for the unparser. However, after `EliminateNestedUnion` optimization rule, the nested union will be flatten to one union like
```
Projection: vals.x, vals.y
SubqueryAlias: vals
Union
Projection: Int64(1) AS x, Utf8("a") AS y
EmptyRelation
Projection: Int64(1) AS x, Utf8("b") AS y
EmptyRelation
Projection: Int64(2) AS x, Utf8("a") AS y
EmptyRelation
Projection: Int64(2) AS x, Utf8("c") AS y
EmptyRelation
```
If we tried to unparse this plan, we will get the error message:
```
Error: This feature is not implemented: UNION ALL expected 2 inputs, but found 4
```
### Describe the solution you'd like
Currently, the unpaser only supports unparsing an union with 2 input
https://github.com/apache/datafusion/blob/172e5573270ae4a3d152d5bf15c5c0008595090e/datafusion/sql/src/unparser/plan.rs#L630-L635
We should support unparsing the union with more 2 inputs for the Unparser.
### Describe alternatives you've considered
_No response_
### 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: github-unsubscribe@datafusion.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Unparse `UNION` plan with multiple inputs to SQL text [datafusion]
Posted by "goldmedal (via GitHub)" <gi...@apache.org>.
goldmedal closed issue #13621: Unparse `UNION` plan with multiple inputs to SQL text
URL: https://github.com/apache/datafusion/issues/13621
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org