BigQuery support inline comment with hash syntax (#1192)

This commit is contained in:
Ifeanyi Ubah 2024-04-07 14:31:04 +02:00 committed by GitHub
parent 23103302e6
commit 732e1ec1fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View file

@ -984,7 +984,7 @@ impl<'a> Tokenizer<'a> {
}
'{' => self.consume_and_return(chars, Token::LBrace),
'}' => self.consume_and_return(chars, Token::RBrace),
'#' if dialect_of!(self is SnowflakeDialect) => {
'#' if dialect_of!(self is SnowflakeDialect | BigQueryDialect) => {
chars.next(); // consume the '#', starting a snowflake single-line comment
let comment = self.tokenize_single_line_comment(chars);
Ok(Some(Token::Whitespace(Whitespace::SingleLineComment {

View file

@ -8607,6 +8607,24 @@ fn test_release_savepoint() {
one_statement_parses_to("RELEASE test1", "RELEASE SAVEPOINT test1");
}
#[test]
fn test_comment_hash_syntax() {
let dialects = TestedDialects {
dialects: vec![Box::new(BigQueryDialect {}), Box::new(SnowflakeDialect {})],
options: None,
};
let sql = r#"
# comment
SELECT a, b, c # , d, e
FROM T
####### comment #################
WHERE true
# comment
"#;
let canonical = "SELECT a, b, c FROM T WHERE true";
dialects.verified_only_select_with_canonical(sql, canonical);
}
#[test]
fn test_buffer_reuse() {
let d = GenericDialect {};