Support GoogleSQL inline aggregate WHERE filter: AGG(expr WHERE cond)#5
Merged
moshap-firebolt merged 1 commit intoJul 13, 2026
Conversation
GoogleSQL/BigQuery allow an inline WHERE filter inside an aggregate call, e.g. `COUNT(* WHERE cond)`, `SUM(x WHERE cond)`, `ARRAY_AGG(x WHERE cond ORDER BY y)`. It is the in-argument spelling of the standard `AGG(x) FILTER (WHERE cond)`. Add `FunctionArgumentClause::Where(Expr)`, parse it in `parse_function_argument_list` for the BigQuery and Generic dialects (before ORDER BY / LIMIT / HAVING), render it in Display, and compute its span. Covered by a new test in tests/sqlparser_bigquery.rs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
|
Reverted this from |
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.
GoogleSQL/BigQuery allow an inline
WHEREfilter inside an aggregate call, e.g.COUNT(* WHERE cond),SUM(x WHERE cond),ARRAY_AGG(x WHERE cond ORDER BY y).It is the in-argument spelling of the standard
AGG(x) FILTER (WHERE cond).Changes
FunctionArgumentClause::Where(Expr).parse_function_argument_listfor the BigQuery and Genericdialects (before ORDER BY / LIMIT / HAVING).
Display(WHERE <expr>) and compute its span.parse_aggregate_with_where_filterintests/sqlparser_bigquery.rs.Used by Firebolt's
dialect=bigquerypath to lowerAGG(x WHERE c)toAGG(x) FILTER (WHERE c). Intended for eventual upstreaming to apache/datafusion-sqlparser-rs.🤖 Generated with Claude Code
Note
Low Risk
Scoped parser/AST extension for two dialects with tests; no changes to auth, data paths, or existing clause behavior beyond the new optional WHERE branch.
Overview
Adds support for GoogleSQL/BigQuery inline aggregate filters such as
COUNT(* WHERE x > 1)andSUM(x WHERE y > 0)—the in-argument form of standardFILTER (WHERE …).A new
FunctionArgumentClause::Where(Expr)AST variant is introduced and parsed inparse_function_argument_listfor Generic and BigQuery dialects immediately after the comma-separated arguments and beforeORDER BY/LIMIT/HAVING.DisplayrendersWHERE <expr>andSpanneduses the filter expression’s span.BigQuery tests cover round-trip parsing for simple aggregates and
ARRAY_AGG(… WHERE … ORDER BY …), and assert the clause is stored asFunctionArgumentClause::Where.Reviewed by Cursor Bugbot for commit f453ba7. Bugbot is set up for automated code reviews on this repo. Configure here.