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: [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]

Reply via email to