Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/dialect/bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ impl Dialect for BigQueryDialect {
true
}

/// BigQuery allows a query to start with `FROM` (e.g. `FROM t`, and the
/// entry form for pipe syntax, `FROM t |> ...`).
///
/// See <https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#from_queries>
fn supports_from_first_select(&self) -> bool {
true
}

/// See <https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#execute_immediate>
fn supports_execute_immediate(&self) -> bool {
true
Expand Down
28 changes: 28 additions & 0 deletions tests/sqlparser_bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2950,3 +2950,31 @@ fn test_create_snapshot_table() {
"CREATE SNAPSHOT TABLE IF NOT EXISTS dataset_id.table1 CLONE dataset_id.table2 FOR SYSTEM_TIME AS OF TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 HOUR) OPTIONS(expiration_timestamp = TIMESTAMP '2025-01-01 00:00:00 UTC')",
);
}

#[test]
fn parse_from_first_select() {
// BigQuery allows a query to begin with `FROM`, both on its own and as the
// entry form for pipe syntax.
Comment on lines +2956 to +2957

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.

bigquery().verified_stmt("FROM t");
bigquery().verified_stmt("FROM t SELECT a, b");
bigquery().verified_stmt("FROM t |> WHERE a > 1 |> SELECT a");

// 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 +2961 to +2978

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:?}"),

}
}
Loading