Add support for view comments for Snowflake (#1287)

Co-authored-by: Joey Hain <joey@sigmacomputing.com>
This commit is contained in:
Simon Sawert 2024-05-30 18:21:39 +02:00 committed by GitHub
parent c2d84f5683
commit 029a999645
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 94 additions and 1 deletions

View file

@ -18,7 +18,7 @@ use sqlparser::ast::helpers::stmt_data_loading::{
DataLoadingOption, DataLoadingOptionType, StageLoadSelectItem,
};
use sqlparser::ast::*;
use sqlparser::dialect::{GenericDialect, SnowflakeDialect};
use sqlparser::dialect::{Dialect, GenericDialect, SnowflakeDialect};
use sqlparser::parser::{ParserError, ParserOptions};
use sqlparser::tokenizer::*;
use test_utils::*;
@ -91,6 +91,56 @@ fn test_snowflake_single_line_tokenize() {
assert_eq!(expected, tokens);
}
#[test]
fn parse_sf_create_or_replace_view_with_comment_missing_equal() {
assert!(snowflake_and_generic()
.parse_sql_statements("CREATE OR REPLACE VIEW v COMMENT = 'hello, world' AS SELECT 1")
.is_ok());
assert!(snowflake_and_generic()
.parse_sql_statements("CREATE OR REPLACE VIEW v COMMENT 'hello, world' AS SELECT 1")
.is_err());
}
#[test]
fn parse_sf_create_or_replace_with_comment_for_snowflake() {
let sql = "CREATE OR REPLACE VIEW v COMMENT = 'hello, world' AS SELECT 1";
let dialect = test_utils::TestedDialects {
dialects: vec![Box::new(SnowflakeDialect {}) as Box<dyn Dialect>],
options: None,
};
match dialect.verified_stmt(sql) {
Statement::CreateView {
name,
columns,
or_replace,
options,
query,
materialized,
cluster_by,
comment,
with_no_schema_binding: late_binding,
if_not_exists,
temporary,
} => {
assert_eq!("v", name.to_string());
assert_eq!(columns, vec![]);
assert_eq!(options, CreateTableOptions::None);
assert_eq!("SELECT 1", query.to_string());
assert!(!materialized);
assert!(or_replace);
assert_eq!(cluster_by, vec![]);
assert!(comment.is_some());
assert_eq!(comment.expect("expected comment"), "hello, world");
assert!(!late_binding);
assert!(!if_not_exists);
assert!(!temporary);
}
_ => unreachable!(),
}
}
#[test]
fn test_sf_derived_table_in_parenthesis() {
// Nesting a subquery in an extra set of parentheses is non-standard,