Skip to content

Commit 732e1ec

Browse files
authored
BigQuery support inline comment with hash syntax (apache#1192)
1 parent 2310330 commit 732e1ec

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/tokenizer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ impl<'a> Tokenizer<'a> {
984984
}
985985
'{' => self.consume_and_return(chars, Token::LBrace),
986986
'}' => self.consume_and_return(chars, Token::RBrace),
987-
'#' if dialect_of!(self is SnowflakeDialect) => {
987+
'#' if dialect_of!(self is SnowflakeDialect | BigQueryDialect) => {
988988
chars.next(); // consume the '#', starting a snowflake single-line comment
989989
let comment = self.tokenize_single_line_comment(chars);
990990
Ok(Some(Token::Whitespace(Whitespace::SingleLineComment {

tests/sqlparser_common.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8607,6 +8607,24 @@ fn test_release_savepoint() {
86078607
one_statement_parses_to("RELEASE test1", "RELEASE SAVEPOINT test1");
86088608
}
86098609

8610+
#[test]
8611+
fn test_comment_hash_syntax() {
8612+
let dialects = TestedDialects {
8613+
dialects: vec![Box::new(BigQueryDialect {}), Box::new(SnowflakeDialect {})],
8614+
options: None,
8615+
};
8616+
let sql = r#"
8617+
# comment
8618+
SELECT a, b, c # , d, e
8619+
FROM T
8620+
####### comment #################
8621+
WHERE true
8622+
# comment
8623+
"#;
8624+
let canonical = "SELECT a, b, c FROM T WHERE true";
8625+
dialects.verified_only_select_with_canonical(sql, canonical);
8626+
}
8627+
86108628
#[test]
86118629
fn test_buffer_reuse() {
86128630
let d = GenericDialect {};

0 commit comments

Comments
 (0)