Skip to content

Commit eaf66bc

Browse files
author
aleksei.p
committed
update
1 parent 24a2968 commit eaf66bc

File tree

3 files changed

+18
-33
lines changed

3 files changed

+18
-33
lines changed

src/dialect/snowflake.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,6 @@ impl Dialect for SnowflakeDialect {
245245
.map(|p| Some(ColumnOption::Policy(ColumnPolicy::ProjectionPolicy(p)))))
246246
} else if parser.parse_keywords(&[Keyword::TAG]) {
247247
Ok(parse_column_tags(parser, with).map(|p| Some(ColumnOption::Tags(p))))
248-
} else if parser.parse_keywords(&[Keyword::COMMENT]) {
249-
let next_token = parser.next_token();
250-
match next_token.token {
251-
Token::DollarQuotedString(value, ..) => {
252-
Ok(Ok(Some(ColumnOption::Comment(value.value))))
253-
}
254-
_ => Err(ParserError::ParserError("not found match".to_string())),
255-
}
256248
} else {
257249
Err(ParserError::ParserError("not found match".to_string()))
258250
}
@@ -430,7 +422,7 @@ pub fn parse_create_table(
430422
Keyword::COMMENT => {
431423
// Rewind the COMMENT keyword
432424
parser.prev_token();
433-
builder = builder.comment(parser.parse_optional_inline_comment(true)?);
425+
builder = builder.comment(parser.parse_optional_inline_comment()?);
434426
}
435427
Keyword::AS => {
436428
let query = parser.parse_query()?;

src/parser/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5765,7 +5765,7 @@ impl<'a> Parser<'a> {
57655765
None
57665766
};
57675767

5768-
let comment = self.parse_optional_inline_comment(false)?;
5768+
let comment = self.parse_optional_inline_comment()?;
57695769

57705770
let with_dcproperties =
57715771
match self.parse_options_with_keywords(&[Keyword::WITH, Keyword::DCPROPERTIES])? {
@@ -6822,8 +6822,7 @@ impl<'a> Parser<'a> {
68226822
if !dialect_of!(self is HiveDialect) && self.parse_keyword(Keyword::COMMENT) {
68236823
// rewind the COMMENT keyword
68246824
self.prev_token();
6825-
let support_dollar_quoted_comment = dialect_of!(self is SnowflakeDialect);
6826-
comment = self.parse_optional_inline_comment(support_dollar_quoted_comment)?
6825+
comment = self.parse_optional_inline_comment()?
68276826
};
68286827

68296828
// Parse optional `AS ( query )`
@@ -6924,16 +6923,13 @@ impl<'a> Parser<'a> {
69246923
})
69256924
}
69266925

6927-
pub fn parse_optional_inline_comment(
6928-
&mut self,
6929-
support_dollar_quoted_comment: bool,
6930-
) -> Result<Option<CommentDef>, ParserError> {
6926+
pub fn parse_optional_inline_comment(&mut self) -> Result<Option<CommentDef>, ParserError> {
69316927
let comment = if self.parse_keyword(Keyword::COMMENT) {
69326928
let has_eq = self.consume_token(&Token::Eq);
69336929
let next_token = self.next_token();
69346930
let comment = match next_token.token {
69356931
Token::SingleQuotedString(str) => str,
6936-
Token::DollarQuotedString(str) if support_dollar_quoted_comment => str.value,
6932+
Token::DollarQuotedString(str) => str.value,
69376933
_ => self.expected("comment", next_token)?,
69386934
};
69396935
Some(if has_eq {
@@ -7085,6 +7081,9 @@ impl<'a> Parser<'a> {
70857081
let next_token = self.next_token();
70867082
match next_token.token {
70877083
Token::SingleQuotedString(value, ..) => Ok(Some(ColumnOption::Comment(value))),
7084+
Token::DollarQuotedString(value, ..) => {
7085+
Ok(Some(ColumnOption::Comment(value.value)))
7086+
}
70887087
_ => self.expected("string", next_token),
70897088
}
70907089
} else if self.parse_keyword(Keyword::NULL) {

tests/sqlparser_snowflake.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -978,23 +978,17 @@ fn parse_sf_create_or_replace_with_comment_for_snowflake() {
978978

979979
#[test]
980980
fn parse_sf_create_table_or_view_with_dollar_quoted_comment() {
981-
assert!(snowflake()
982-
.parse_sql_statements(
983-
r#"CREATE OR REPLACE TEMPORARY VIEW foo.bar.baz (
984-
"COL_1" COMMENT $$comment 1$$
985-
) COMMENT = $$view comment$$ AS (
986-
SELECT 1
987-
)"#
988-
)
989-
.is_ok());
981+
// Snowflake transforms dollar quoted comments into a common comment in DDL representation of creation
982+
snowflake()
983+
.one_statement_parses_to(
984+
r#"CREATE OR REPLACE TEMPORARY VIEW foo.bar.baz ("COL_1" COMMENT $$comment 1$$) COMMENT = $$view comment$$ AS (SELECT 1)"#,
985+
r#"CREATE OR REPLACE TEMPORARY VIEW foo.bar.baz ("COL_1" COMMENT 'comment 1') COMMENT = 'view comment' AS (SELECT 1)"#
986+
);
990987

991-
assert!(snowflake()
992-
.parse_sql_statements(
993-
r#"CREATE TABLE my_table (
994-
a STRING COMMENT $$comment 1$$
995-
) COMMENT = $$table comment$$"#
996-
)
997-
.is_ok());
988+
snowflake().one_statement_parses_to(
989+
r#"CREATE TABLE my_table (a STRING COMMENT $$comment 1$$) COMMENT = $$table comment$$"#,
990+
r#"CREATE TABLE my_table (a STRING COMMENT 'comment 1') COMMENT = 'table comment'"#,
991+
);
998992
}
999993

1000994
#[test]

0 commit comments

Comments
 (0)