Skip to content

Support GoogleSQL inline aggregate WHERE filter: AGG(expr WHERE cond)#5

Merged
moshap-firebolt merged 1 commit into
firebolt-analytics:mainfrom
moshap-firebolt:moshap/agg-where-filter-clause
Jul 13, 2026
Merged

Support GoogleSQL inline aggregate WHERE filter: AGG(expr WHERE cond)#5
moshap-firebolt merged 1 commit into
firebolt-analytics:mainfrom
moshap-firebolt:moshap/agg-where-filter-clause

Conversation

@moshap-firebolt

@moshap-firebolt moshap-firebolt commented Jul 12, 2026

Copy link
Copy Markdown

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).

Changes

  • 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 (WHERE <expr>) and compute its span.
  • New test parse_aggregate_with_where_filter in tests/sqlparser_bigquery.rs.

Used by Firebolt's dialect=bigquery path to lower AGG(x WHERE c) to
AGG(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) and SUM(x WHERE y > 0)—the in-argument form of standard FILTER (WHERE …).

A new FunctionArgumentClause::Where(Expr) AST variant is introduced and parsed in parse_function_argument_list for Generic and BigQuery dialects immediately after the comma-separated arguments and before ORDER BY / LIMIT / HAVING. Display renders WHERE <expr> and Spanned uses 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 as FunctionArgumentClause::Where.

Reviewed by Cursor Bugbot for commit f453ba7. Bugbot is set up for automated code reviews on this repo. Configure here.

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>
@moshap-firebolt moshap-firebolt merged commit b975604 into firebolt-analytics:main Jul 13, 2026
2 checks passed
@moshap-firebolt

Copy link
Copy Markdown
Author

Reverted this from main — it was targeted at the wrong branch. main mirrors apache upstream (which carries the breaking ORDER BY AST change apache#2246 that packdb's dialect translator can't read), so packdb can't pin main. The change has been cherry-picked onto the stable pin line instead: branch firebolt/v0.62.0-patches (v0.62.0 + our cherry-picks, no apache#2246), commit eee77cb, which packdb now pins. Upstream PR: apache#2404.

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.

1 participant