Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
7phs committed Sep 25, 2024
1 parent 619d7c9 commit 4cb10c0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
23 changes: 11 additions & 12 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8197,26 +8197,25 @@ impl<'a> Parser<'a> {
&& self.parse_keyword(Keyword::OPTIONS)
{
self.prev_token();
let option = ColumnOption::Options(self.parse_options(Keyword::OPTIONS)?);
options.push(option);
if let Some(option) = self.parse_optional_column_option()? {
options.push(option);
}
};
if dialect_of!(self is SnowflakeDialect | GenericDialect)
&& self.parse_keyword(Keyword::COMMENT)
{
let next_token = self.next_token();
let option = match next_token.token {
Token::SingleQuotedString(str) => ColumnOption::Comment(str),
_ => self.expected("string literal", next_token)?,
};
options.push(option);
self.prev_token();
if let Some(option) = self.parse_optional_column_option()? {
options.push(option);
}
};
let data_type = if dialect_of!(self is ClickHouseDialect) {
Some(self.parse_data_type()?)
let options = if !options.is_empty() {
Some(options)
} else {
None
};
let options = if !options.is_empty() {
Some(options)
let data_type = if dialect_of!(self is ClickHouseDialect) {
Some(self.parse_data_type()?)
} else {
None
};
Expand Down
34 changes: 21 additions & 13 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2401,26 +2401,34 @@ fn parse_use() {
}
}

#[test]
fn view_comment_option_should_be_after_column_list() {
snowflake_and_generic()
.verified_stmt("CREATE OR REPLACE VIEW v (a) COMMENT = 'Comment' AS SELECT a FROM t");
}

#[test]
fn parse_view_column_descriptions() {
let sql = "CREATE OR REPLACE VIEW v (a COMMENT 'Comment of field') COMMENT = 'Comment of view' AS SELECT a FROM table1 AS o";
let sql =
"CREATE OR REPLACE VIEW v (a COMMENT 'Comment', b) AS SELECT a, b FROM table1";

match snowflake_and_generic().verified_stmt(sql) {
Statement::CreateView {
name,
columns,
comment,
..
} => {
Statement::CreateView { name, columns, .. } => {
assert_eq!(name.to_string(), "v");
assert_eq!(comment, Some("Comment of view".to_string()));
assert_eq!(
columns,
vec![ViewColumnDef {
name: Ident::new("a"),
data_type: None,
options: Some(vec![ColumnOption::Comment("Comment of field".to_string())]),
},]
vec![
ViewColumnDef {
name: Ident::new("a"),
data_type: None,
options: Some(vec![ColumnOption::Comment("Comment".to_string())]),
},
ViewColumnDef {
name: Ident::new("b"),
data_type: None,
options: None,
}
]
);
}
_ => unreachable!(),
Expand Down

0 comments on commit 4cb10c0

Please sign in to comment.