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

Order of IGNORE NULLS in BigQuery generated SQL is incorrect #2932

Closed
cpcloud opened this issue Feb 8, 2024 · 1 comment
Closed

Order of IGNORE NULLS in BigQuery generated SQL is incorrect #2932

cpcloud opened this issue Feb 8, 2024 · 1 comment
Assignees

Comments

@cpcloud
Copy link
Contributor

cpcloud commented Feb 8, 2024

IGNORE NULLS needs to occur before LIMIT, otherwise it's an error.

Fully reproducible code snippet

In [7]: import sqlglot as sg

In [8]: sg.__version__
Out[8]: '21.0.1'

In [9]: sg.parse_one('select array_agg(x ignore nulls limit 1)', read='bigquery').sql('bigquery')
Out[9]: 'SELECT array_agg(x LIMIT 1 IGNORE NULLS)'

Official Documentation

https://cloud.google.com/bigquery/docs/reference/standard-sql/aggregate-function-calls

@georgesittas
Copy link
Collaborator

georgesittas commented Feb 8, 2024

This one's tricky, I'm looking into it but haven't figured out the workaround yet.. The parser was recently updated and now the ignore/respect nulls expression is bubbled right above the AggFunc which makes it get generated at the end.

@tobymao tobymao self-assigned this Feb 8, 2024
@tobymao tobymao closed this as completed in e10010d Feb 8, 2024
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

No branches or pull requests

3 participants