Skip to content

BigQuery: Support inline aggregate WHERE filter (AGG(expr WHERE cond))#2404

Open
moshap-firebolt wants to merge 1 commit into
apache:mainfrom
moshap-firebolt:upstream/bigquery-agg-where-filter
Open

BigQuery: Support inline aggregate WHERE filter (AGG(expr WHERE cond))#2404
moshap-firebolt wants to merge 1 commit into
apache:mainfrom
moshap-firebolt:upstream/bigquery-agg-where-filter

Conversation

@moshap-firebolt

Copy link
Copy Markdown
Contributor

GoogleSQL allows an aggregate call to carry an inline WHERE filter, 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(expr) 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.
  • Display renders WHERE <expr>; span is computed from the predicate.
  • New test parse_aggregate_with_where_filter in tests/sqlparser_bigquery.rs.

Docs: https://cloud.google.com/bigquery/docs/reference/standard-sql/aggregate_functions

GoogleSQL allows an aggregate call to carry an inline WHERE filter, 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(expr) FILTER (WHERE cond)`.

Add `FunctionArgumentClause::Where(Expr)` and parse it in
`parse_function_argument_list` for the BigQuery and Generic dialects (before
ORDER BY / LIMIT / HAVING), with `Display` and span support. Covered by a new
`parse_aggregate_with_where_filter` test.
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