Skip to content

BigQuery: enable FROM-first SELECT - #2439

Open
moshap-firebolt wants to merge 2 commits into
apache:mainfrom
moshap-firebolt:bigquery-from-first-select
Open

BigQuery: enable FROM-first SELECT#2439
moshap-firebolt wants to merge 2 commits into
apache:mainfrom
moshap-firebolt:bigquery-from-first-select

Conversation

@moshap-firebolt

Copy link
Copy Markdown
Contributor

BigQuery allows a query to start with FROM, e.g. FROM t and FROM t SELECT *,
which is also the entry form for pipe syntax (FROM t |> ...).

The parser already supports FROM-first SELECT behind
Dialect::supports_from_first_select() (enabled for ClickHouse, DuckDB and
Generic); this enables it for BigQuery as well. The existing
test_select_from_first / test_select_from_first_with_cte, parameterized over
all_dialects_where(|d| d.supports_from_first_select()), now cover BigQuery.

Docs: https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#from_queries

BigQuery allows a query to start with `FROM`, e.g. `FROM t` and `FROM t SELECT *`,
which is also the entry form for pipe syntax (`FROM t |> ...`).

The parser already supports FROM-first `SELECT` behind
`Dialect::supports_from_first_select()` (enabled for ClickHouse, DuckDB and
Generic); this enables it for BigQuery as well. The existing
`test_select_from_first` / `test_select_from_first_with_cte`, parameterized over
`all_dialects_where(|d| d.supports_from_first_select())`, now cover BigQuery.

Docs: https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#from_queries

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

@LucaCappelletti94 LucaCappelletti94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Include tests for the big query dialect to avoid regressions.

Add regression tests for the BigQuery dialect's FROM-first `SELECT`: the bare
`FROM t` (`FromFirstNoSelect`) and `FROM t SELECT ...` (`FromFirst`) forms, and
`FROM t |> ...` as the entry form for pipe syntax.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
@moshap-firebolt

Copy link
Copy Markdown
Contributor Author

Include tests for the big query dialect to avoid regressions.

Done.

Comment on lines +2961 to +2978

// The bare form has no explicit SELECT and parses as `FromFirstNoSelect`;
// adding a SELECT switches it to `FromFirst`.
match bigquery().verified_stmt("FROM t") {
Statement::Query(query) => match *query.body {
SetExpr::Select(select) => {
assert_eq!(select.flavor, SelectFlavor::FromFirstNoSelect)
}
other => panic!("expected a select, got {other:?}"),
},
other => panic!("expected a query, got {other:?}"),
}
match bigquery().verified_stmt("FROM t SELECT a, b") {
Statement::Query(query) => match *query.body {
SetExpr::Select(select) => assert_eq!(select.flavor, SelectFlavor::FromFirst),
other => panic!("expected a select, got {other:?}"),
},
other => panic!("expected a query, got {other:?}"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// The bare form has no explicit SELECT and parses as `FromFirstNoSelect`;
// adding a SELECT switches it to `FromFirst`.
match bigquery().verified_stmt("FROM t") {
Statement::Query(query) => match *query.body {
SetExpr::Select(select) => {
assert_eq!(select.flavor, SelectFlavor::FromFirstNoSelect)
}
other => panic!("expected a select, got {other:?}"),
},
other => panic!("expected a query, got {other:?}"),
}
match bigquery().verified_stmt("FROM t SELECT a, b") {
Statement::Query(query) => match *query.body {
SetExpr::Select(select) => assert_eq!(select.flavor, SelectFlavor::FromFirst),
other => panic!("expected a select, got {other:?}"),
},
other => panic!("expected a query, got {other:?}"),

Comment on lines +2956 to +2957
// BigQuery allows a query to begin with `FROM`, both on its own and as the
// entry form for pipe syntax.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// BigQuery allows a query to begin with `FROM`, both on its own and as the
// entry form for pipe syntax.

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.

3 participants