goldmedal opened a new pull request, #20648: URL: https://github.com/apache/datafusion/pull/20648
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #. ## Rationale for this change DataFusion's SQL unparser lacked Snowflake dialect support for UNNEST in the FROM clause. Snowflake does not have a native UNNEST table factor — instead it uses the [FLATTEN](https://docs.snowflake.com/en/sql-reference/functions/flatten#syntax) table function to expand arrays. Without this support, logical plans containing Unnest nodes could not be round-tripped to valid Snowflake SQL. The Datafusion SQL: ```sql SELECT * FROM UNNEST([1,2,3]) t(a) ``` It can be transpiled to the equivalent SQL in Snowfalke dialect: ```sql SELECT "t"."a" FROM TABLE(FLATTEN([1, 2, 3], '', false, false, 'ARRAY')) AS "t" ("SEQ", "KEY", "PATH", "INDEX", "a", "THIS") ``` <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> ## What changes are included in this PR? - Added two new Dialect trait methods: - unparse_unnest_table_factor — lets a dialect convert an Unnest plan node into a dialect-specific TableFactor (e.g. TABLE(FLATTEN(...)) for Snowflake) - relation_alias_overrides — lets a dialect intercept and rewrite the alias applied to a relation builder, used here to patch the VALUE column name in the FLATTEN alias list - Add `SnowflakeDialect` with the `unparse_unnest_table_factor` implementation to show how to use it. - Fix the quoted identifier issue for the `subquery_alias_inner_query_and_columns` method. <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? yes. Wren AI has been using it in production for a while. https://github.com/Canner/datafusion/pull/9 <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? yes, new method for the unparser dialect. <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> -- 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]
