Skip to content

feat(duckdb): Add transpilation support for FLATTEN (ARRAY_FLATTEN)#6848

Merged
georgesittas merged 1 commit intomainfrom
RD-1147617-array-flatten
Jan 26, 2026
Merged

feat(duckdb): Add transpilation support for FLATTEN (ARRAY_FLATTEN)#6848
georgesittas merged 1 commit intomainfrom
RD-1147617-array-flatten

Conversation

@fivetran-amrutabhimsenayachit
Copy link
Collaborator

ARRAY_FLATTEN function from Snowflake is not transpiling to DuckDB's FLATTEN function. SQLGlot currently parses ARRAY_FLATTEN as an Anonymous function without mapping it to the internal Flatten expression type, resulting in failed transpilation to DuckDB.

 python3 -c "import sqlglot; print(sqlglot.transpile(\"SELECT ARRAY_FLATTEN([[1, 2, 3], [4], [5, 6]]) AS result\", read='snowflake', write='duckdb')[0])" | duckdb
 DuckDB: SELECT FLATTEN([[1, 2, 3], [4], [5, 6]]) AS result
┌────────────────────┐
│       result       │
│      int32[]       │
├────────────────────┤
│ [1, 2, 3, 4, 5, 6] │
└────────────────────┘

@github-actions
Copy link
Contributor

SQLGlot Integration Test Results

Comparing:

  • this branch (sqlglot:RD-1147617-array-flatten, sqlglot version: RD-1147617-array-flatten)
  • baseline (main, sqlglot version: 28.6.1.dev82)

⚠️ Limited to dialects: snowflake

By Dialect

dialect main sqlglot:RD-1147617-array-flatten difference links
snowflake -> duckdb 615/847 passed (72.6%) 615/847 passed (72.6%) No change full result / delta
snowflake -> snowflake 847/847 passed (100.0%) 847/847 passed (100.0%) No change full result / delta

Overall

main: 1694 total, 1462 passed (pass rate: 86.3%), sqlglot version: 28.6.1.dev82

sqlglot:RD-1147617-array-flatten: 1694 total, 1462 passed (pass rate: 86.3%), sqlglot version: RD-1147617-array-flatten

Difference: No change

Copy link
Collaborator

@geooo109 geooo109 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function exists in various dialects but I think we missing tests, we could add them in a separate PR. cc: @VaggelisD , @georgesittas

@georgesittas georgesittas merged commit d97b842 into main Jan 26, 2026
9 checks passed
@georgesittas georgesittas deleted the RD-1147617-array-flatten branch January 26, 2026 09:15
@georgesittas
Copy link
Collaborator

This function exists in various dialects but I think we missing tests, we could add them in a separate PR. cc: @VaggelisD , @georgesittas

@geooo109 go for it. If we cover all dialects it may be worth renaming Flatten to ArrayFlatten. The former was introduced to support Snowflake's FLATTEN(...) operator, which was later mapped to Explode and hence that context was lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments