Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: support unparsing UNNEST as Snowflake FLATTEN table function#20648

Open
goldmedal wants to merge 8 commits intoapache:mainfrom
goldmedal:feat/unparse-unnest-snowflake
Open

feat: support unparsing UNNEST as Snowflake FLATTEN table function#20648
goldmedal wants to merge 8 commits intoapache:mainfrom
goldmedal:feat/unparse-unnest-snowflake

Conversation

@goldmedal
Copy link
Contributor

Which issue does this PR close?

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

SELECT * FROM UNNEST([1,2,3]) t(a)

It can be transpiled to the equivalent SQL in Snowfalke dialect:

SELECT "t"."a" FROM TABLE(FLATTEN([1, 2, 3], '', false, false, 'ARRAY')) AS "t" ("SEQ", "KEY", "PATH", "INDEX", "a", "THIS")

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.

Are these changes tested?

yes.
Wren AI has been using it in production for a while. Canner#9

Are there any user-facing changes?

yes, new method for the unparser dialect.

@github-actions github-actions bot added the sql SQL Planner label Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant