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/11/29 10:26:47 UTC

[I] Allow to unparse `UNNEST` plan back to a table function SQL text [datafusion]

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: 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] Allow to unparse `UNNEST` plan back to a table function SQL text [datafusion]

Posted by "goldmedal (via GitHub)" <gi...@apache.org>.
goldmedal closed issue #13601: Allow to unparse `UNNEST` plan back to a table function SQL text
URL: https://github.com/apache/datafusion/issues/13601


-- 
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


Re: [I] Allow to unparse `UNNEST` plan back to a table function SQL text [datafusion]

Posted by "goldmedal (via GitHub)" <gi...@apache.org>.
goldmedal commented on issue #13601:
URL: https://github.com/apache/datafusion/issues/13601#issuecomment-2519510217

   Hi @jatin510
   Have you started working on this issue? I noticed you’ve taken on other tasks, and I’m unsure of your priorities. If not, I’d like to take over since I need this feature for my downstream project.


-- 
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


Re: [I] Allow to unparse `UNNEST` plan back to a table function SQL text [datafusion]

Posted by "jatin510 (via GitHub)" <gi...@apache.org>.
jatin510 commented on issue #13601:
URL: https://github.com/apache/datafusion/issues/13601#issuecomment-2520183310

   please go ahead @goldmedal 


-- 
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


Re: [I] Allow to unparse `UNNEST` plan back to a table function SQL text [datafusion]

Posted by "jatin510 (via GitHub)" <gi...@apache.org>.
jatin510 commented on issue #13601:
URL: https://github.com/apache/datafusion/issues/13601#issuecomment-2507913083

   take


-- 
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