feat(duckdb): Add transpilation support for ARRAY_UNION_AGG function#7495
Open
fivetran-amrutabhimsenayachit wants to merge 1 commit intomainfrom
Open
feat(duckdb): Add transpilation support for ARRAY_UNION_AGG function#7495fivetran-amrutabhimsenayachit wants to merge 1 commit intomainfrom
fivetran-amrutabhimsenayachit wants to merge 1 commit intomainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Snowflake's
ARRAY_UNION_AGGcomputes the set-union of multiple input arrays across rows — returning one flat array of distinct elements. DuckDB has no equivalent function. SQLGlot was emitting it verbatim, causing DuckDB to raise aCatalog Errorat runtime.The window form added a second wrinkle: even if we replaced the inner function correctly, DuckDB requires the
OVER (...)clause to wrap the innermost aggregate (LIST), not the outer transformation functions. Simply swapping the function name and appending OVER would produce structurally invalid SQL.Fix
Two changes to the DuckDB generator:
Regular aggregate form — Added
arrayunionagg_sql, which rewritesARRAY_UNION_AGG(col)asLIST_DISTINCT(FLATTEN(LIST(col))).LISTcollects all input arrays into a list-of-lists,FLATTENunwraps them into one flat list, andLIST_DISTINCTremoves duplicates — together approximating the set-union semantics.Window form — Extended the existing
window_sqloverride to interceptARRAY_UNION_AGG(...) OVER (...). It deep-copies the Window node, swaps the inner function fromArrayUnionAggtoLIST, then wraps the restructured window inFLATTENandLIST_DISTINCT— producingLIST_DISTINCT(FLATTEN(LIST(col) OVER (PARTITION BY grp)))where theOVERcorrectly wraps only the aggregate.Known limitation: DuckDB
LIST_DISTINCTuses strict set semantics. Snowflake's multiset semantics (where duplicates from a single input array are preserved) cannot be reproduced in DuckDB with built-in functions.