Skip to content

feat(bigquery): parse GoogleSQL set-operation column matching - #8

Merged
moshap-firebolt merged 1 commit into
firebolt/v0.62.0-patchesfrom
moshap/bigquery-setop-corresponding
Aug 18, 2026
Merged

feat(bigquery): parse GoogleSQL set-operation column matching#8
moshap-firebolt merged 1 commit into
firebolt/v0.62.0-patchesfrom
moshap/bigquery-setop-corresponding

Conversation

@moshap-firebolt

@moshap-firebolt moshap-firebolt commented Aug 14, 2026

Copy link
Copy Markdown

What

Parse GoogleSQL/BigQuery set-operation column matching:

<query> [ {INNER|LEFT|FULL} [OUTER] ] {UNION|INTERSECT|EXCEPT} {ALL|DISTINCT}
        [ BY NAME [ON (cols)] | CORRESPONDING [BY (cols)] ] <query>

Today the fork parses only UNION [ALL|DISTINCT] BY NAME; the mode prefix (INNER/LEFT/FULL/STRICT) and the explicit column list (ON (...) / BY (...)) fail to parse.

How

  • New SetOperationMode { None, Inner, Left, Full, Strict } and two fields on SetExpr::SetOperation: mode (the prefix) and corresponding_columns: Option<Vec<Ident>> (the ON/BY list). The existing SetQuantifier (ALL/DISTINCT/ByName) is kept as-is, not overloaded.
  • The mode prefix is recognized in parse_query_body only when a set operator actually follows (lookahead), so INNER JOIN etc. are untouched.
  • CORRESPONDING / CORRESPONDING BY (...) are equivalent spellings of BY NAME / BY NAME ON (...); Display canonicalizes to the BY NAME spelling and round-trips (verified_stmt).
  • Parser-only — no lowering/semantics.

Test

tests/sqlparser_bigquery.rs::parse_set_operation_by_name asserts the mode + column list on the AST; representative forms (INNER/FULL/LEFT ... UNION ALL BY NAME [ON (cols)], CORRESPONDING BY (...)) round-trip.

Consumed by Firebolt's dialect=bigquery set-operation lowering. Upstream PR to follow separately.

🤖 Generated with Claude Code


Note

Medium Risk
Breaking AST shape change on SetExpr::SetOperation for downstream pattern matches, plus subtle lexer disambiguation between set-op modes and JOIN keywords.

Overview
Extends BigQuery/GoogleSQL set-operation column matching so queries like FULL UNION ALL BY NAME ON (a, b) and LEFT UNION ALL CORRESPONDING BY (a) parse into the AST instead of failing.

SetExpr::SetOperation gains mode (SetOperationMode: INNER/LEFT/FULL/STRICT, with optional OUTER) and corresponding_columns for explicit ON (...) / BY (...) lists. Display prints the mode prefix and ON (...) list; CORRESPONDING spellings normalize to BY NAME / BY NAME ON (...) on round-trip.

The parser peeks the mode prefix only when a set operator follows (so INNER JOIN etc. stay unchanged), accepts CORRESPONDING alongside existing BY NAME quantifiers, and wires the new fields through parse_remaining_set_exprs. Existing tests that construct SetOperation manually are updated for the new fields.

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

Comment thread src/parser/mod.rs
@moshap-firebolt
moshap-firebolt force-pushed the moshap/bigquery-setop-corresponding branch from 12fd2e2 to 0792fab Compare August 14, 2026 18:51

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0792fab. Configure here.

Comment thread src/parser/mod.rs
Comment thread src/parser/mod.rs Outdated
Parse the GoogleSQL/BigQuery set-operation column-matching grammar:

    query_expr
    [ { INNER | [ { FULL | LEFT } [ OUTER ] ] } ]
    { UNION | INTERSECT | EXCEPT } { ALL | DISTINCT }
    [ { BY NAME [ ON (cols) ] | [ STRICT ] CORRESPONDING [ BY (cols) ] } ]
    query_expr

AST: `SetExpr::SetOperation` (and the `UNION`/`INTERSECT`/`EXCEPT` pipe
operators) gain a `mode: Option<SetOperationMode>` column-propagation prefix
(`INNER`/`LEFT`/`FULL`, each `LEFT`/`FULL` with an optional `OUTER`) and a
`column_match: Option<SetOperationColumnMatch>` trailing clause carrying the
spelling (`BY NAME` vs `CORRESPONDING`), the `STRICT` flag, and the explicit
column list. `BY NAME` moves out of `SetQuantifier` into `column_match`, so the
quantifier is once again just `ALL`/`DISTINCT`; DuckDB's `UNION BY NAME` uses
the same representation.

`BY NAME` and `CORRESPONDING` are kept distinct (they differ in default
semantics and in the column-list keyword), the mode prefix is recognized only
in the slot immediately before the operator -- and is not captured as a
preceding select item's alias -- and `STRICT` is parsed only as part of
`STRICT CORRESPONDING`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@moshap-firebolt
moshap-firebolt force-pushed the moshap/bigquery-setop-corresponding branch from 0792fab to 23132a2 Compare August 16, 2026 17:30
@moshap-firebolt
moshap-firebolt merged commit de91c15 into firebolt/v0.62.0-patches Aug 18, 2026
21 checks passed
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