Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bigquery): Do not generate null ordering on agg funcs #4172

Merged
merged 2 commits into from
Sep 30, 2024

Conversation

VaggelisD
Copy link
Collaborator

Fixes #4170

BigQuery does not allow ASC NULLS LAST and DESC NULLS FIRST ordering in aggregate functions:

with colors as (SELECT 1 AS id, 'red' AS color) SELECT color, array_agg(id ORDER BY id ASC NULLS LAST) AS ids FROM colors GROUP BY 1

NULLS LAST not supported with ascending sort order in aggregate functions.
with colors as (SELECT 1 AS id, 'red' AS color) SELECT color, array_agg(id ORDER BY id DESC NULLS FIRST) AS ids FROM colors GROUP BY 1

NULLS FIRST not supported with descending sort order in aggregate functions.

Note that BigQuery is the only dialect with NULL_ORDERING_SUPPORTED = False so this PR uses this as a proxy to handle this case.

@VaggelisD VaggelisD changed the title fix(bigquery): Do not generate NULLS LAST on asc agg funcs fix(bigquery): Do not generate null ordering on agg funcs Sep 27, 2024
sqlglot/generator.py Outdated Show resolved Hide resolved
sqlglot/generator.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

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

LGTM, one question to really understand this.

@VaggelisD VaggelisD merged commit 0703152 into main Sep 30, 2024
6 checks passed
@VaggelisD VaggelisD deleted the vaggelisd/bq_nulls branch September 30, 2024 12:23
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.

Generated SQL for Array Aggregations with Order By doesn't work in BigQuery
3 participants