fix: begin statement for bigquery (#1975)
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run

This commit is contained in:
Chen Chongchen 2025-07-25 22:56:12 +08:00 committed by GitHub
parent 145922affe
commit 865c191a53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View file

@ -19,6 +19,7 @@ use crate::ast::Statement;
use crate::dialect::Dialect;
use crate::keywords::Keyword;
use crate::parser::{Parser, ParserError};
use crate::tokenizer::Token;
/// These keywords are disallowed as column identifiers. Such that
/// `SELECT 5 AS <col> FROM T` is rejected by BigQuery.
@ -47,6 +48,13 @@ pub struct BigQueryDialect;
impl Dialect for BigQueryDialect {
fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
if parser.parse_keyword(Keyword::BEGIN) {
if parser.peek_keyword(Keyword::TRANSACTION)
|| parser.peek_token_ref().token == Token::SemiColon
|| parser.peek_token_ref().token == Token::EOF
{
parser.prev_token();
return None;
}
return Some(parser.parse_begin_exception_end());
}

View file

@ -2566,3 +2566,13 @@ fn test_struct_trailing_and_nested_bracket() {
)
);
}
#[test]
fn test_begin_transaction() {
bigquery().verified_stmt("BEGIN TRANSACTION");
}
#[test]
fn test_begin_statement() {
bigquery().verified_stmt("BEGIN");
}