mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
Parse Snowflake USE ROLE and USE SECONDARY ROLES (#1578)
This commit is contained in:
parent
dd7ba72a0b
commit
7b50ac31c3
7 changed files with 115 additions and 36 deletions
|
@ -2649,7 +2649,7 @@ fn parse_use() {
|
|||
let quote_styles = ['\'', '"', '`'];
|
||||
for object_name in &valid_object_names {
|
||||
// Test single identifier without quotes
|
||||
std::assert_eq!(
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt(&format!("USE {}", object_name)),
|
||||
Statement::Use(Use::Object(ObjectName(vec![Ident::new(
|
||||
object_name.to_string()
|
||||
|
@ -2657,7 +2657,7 @@ fn parse_use() {
|
|||
);
|
||||
for "e in "e_styles {
|
||||
// Test single identifier with different type of quotes
|
||||
std::assert_eq!(
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt(&format!("USE {}{}{}", quote, object_name, quote)),
|
||||
Statement::Use(Use::Object(ObjectName(vec![Ident::with_quote(
|
||||
quote,
|
||||
|
@ -2669,7 +2669,7 @@ fn parse_use() {
|
|||
|
||||
for "e in "e_styles {
|
||||
// Test double identifier with different type of quotes
|
||||
std::assert_eq!(
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt(&format!("USE {0}CATALOG{0}.{0}my_schema{0}", quote)),
|
||||
Statement::Use(Use::Object(ObjectName(vec![
|
||||
Ident::with_quote(quote, "CATALOG"),
|
||||
|
@ -2678,7 +2678,7 @@ fn parse_use() {
|
|||
);
|
||||
}
|
||||
// Test double identifier without quotes
|
||||
std::assert_eq!(
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt("USE mydb.my_schema"),
|
||||
Statement::Use(Use::Object(ObjectName(vec![
|
||||
Ident::new("mydb"),
|
||||
|
@ -2688,37 +2688,55 @@ fn parse_use() {
|
|||
|
||||
for "e in "e_styles {
|
||||
// Test single and double identifier with keyword and different type of quotes
|
||||
std::assert_eq!(
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt(&format!("USE DATABASE {0}my_database{0}", quote)),
|
||||
Statement::Use(Use::Database(ObjectName(vec![Ident::with_quote(
|
||||
quote,
|
||||
"my_database".to_string(),
|
||||
)])))
|
||||
);
|
||||
std::assert_eq!(
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt(&format!("USE SCHEMA {0}my_schema{0}", quote)),
|
||||
Statement::Use(Use::Schema(ObjectName(vec![Ident::with_quote(
|
||||
quote,
|
||||
"my_schema".to_string(),
|
||||
)])))
|
||||
);
|
||||
std::assert_eq!(
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt(&format!("USE SCHEMA {0}CATALOG{0}.{0}my_schema{0}", quote)),
|
||||
Statement::Use(Use::Schema(ObjectName(vec![
|
||||
Ident::with_quote(quote, "CATALOG"),
|
||||
Ident::with_quote(quote, "my_schema")
|
||||
])))
|
||||
);
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt(&format!("USE ROLE {0}my_role{0}", quote)),
|
||||
Statement::Use(Use::Role(ObjectName(vec![Ident::with_quote(
|
||||
quote,
|
||||
"my_role".to_string(),
|
||||
)])))
|
||||
);
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt(&format!("USE WAREHOUSE {0}my_wh{0}", quote)),
|
||||
Statement::Use(Use::Warehouse(ObjectName(vec![Ident::with_quote(
|
||||
quote,
|
||||
"my_wh".to_string(),
|
||||
)])))
|
||||
);
|
||||
}
|
||||
|
||||
// Test invalid syntax - missing identifier
|
||||
let invalid_cases = ["USE SCHEMA", "USE DATABASE", "USE WAREHOUSE"];
|
||||
for sql in &invalid_cases {
|
||||
std::assert_eq!(
|
||||
assert_eq!(
|
||||
snowflake().parse_sql_statements(sql).unwrap_err(),
|
||||
ParserError::ParserError("Expected: identifier, found: EOF".to_string()),
|
||||
);
|
||||
}
|
||||
|
||||
snowflake().verified_stmt("USE SECONDARY ROLES ALL");
|
||||
snowflake().verified_stmt("USE SECONDARY ROLES NONE");
|
||||
snowflake().verified_stmt("USE SECONDARY ROLES r1, r2, r3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue