feat(duckdb): convert ARRAY_AGG IGNORE NULLS to FILTER clause#7893
Merged
Conversation
BigQuery's `ARRAY_AGG(x IGNORE NULLS ...)` silently drops NULLs from the aggregation. DuckDB does not support `IGNORE NULLS` on aggregate functions, but the same semantics can be expressed with a `FILTER` clause: `ARRAY_AGG(x ...) FILTER(WHERE x IS NOT NULL)`. Previously, the DuckDB generator silently dropped the `IGNORE NULLS` modifier on `ARRAY_AGG`, producing incorrect results when the input contained NULL values. Adds: - `ArrayAgg`-specific handling in `ignorenulls_sql` that sets a `nulls_excluded` flag, which the existing `_add_arrayagg_null_filter` infrastructure converts to a `FILTER(WHERE col IS NOT NULL)` clause - `arrayagg_sql` override to unwrap `Order`/`Limit` nodes so the FILTER clause references the correct column expression - Updated test expectations for ARRAY_AGG DISTINCT IGNORE NULLS
geooo109
reviewed
Jul 17, 2026
geooo109
reviewed
Jul 17, 2026
geooo109
reviewed
Jul 19, 2026
- Move Order/Limit unwrapping from DuckDB override to base generator's arrayagg_sql so all dialects benefit - Emit unsupported warning for LIMIT inside ARRAY_AGG in DuckDB - Remove invalid LIMIT 1, 10 test (unsupported BigQuery syntax) - Simplify DuckDB arrayagg_sql to delegate to super() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
|
@sirockin is this still a draft? What's pending? |
geooo109
marked this pull request as ready for review
July 21, 2026 11:17
geooo109
approved these changes
Jul 21, 2026
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.
Summary
BigQuery's
ARRAY_AGG(x IGNORE NULLS ...)silently drops NULLs from the aggregation. DuckDB does not supportIGNORE NULLSon aggregate functions, but the same semantics can be expressed with aFILTERclause:ARRAY_AGG(x ...) FILTER(WHERE x IS NOT NULL).Problem
Previously, the DuckDB generator silently dropped the
IGNORE NULLSmodifier onARRAY_AGG, producing incorrect results when the input contained NULL values. Theignorenulls_sqlmethod handled window functions (viaIGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS) and convertedFirsttoAnyValue, butArrayAggwas not handled — theIGNORE NULLSwas silently lost.Changes
ArrayAgg-specific handling inignorenulls_sqlthat sets anulls_excludedflag, which the existing_add_arrayagg_null_filterinfrastructure converts to aFILTER(WHERE col IS NOT NULL)clausearrayagg_sqloverride to unwrapOrder/Limitnodes so the FILTER clause references the correct column expression (not the ordering wrapper)ARRAY_AGG DISTINCT IGNORE NULLSto include theFILTERclauseMotivation
We use sqlglot to transpile BigQuery SQL models to DuckDB for local testing via sqlmesh. Our production models use
ARRAY_AGG(... IGNORE NULLS ORDER BY ...)extensively, and the silent loss ofIGNORE NULLScaused incorrect test results.