mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-08 01:15:00 +00:00
feat: support different USE statement syntaxes (#1387)
This commit is contained in:
parent
19e694aa91
commit
7282ce22f9
11 changed files with 386 additions and 17 deletions
|
@ -189,3 +189,77 @@ fn test_values_clause() {
|
|||
// TODO: support this example from https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-values.html#examples
|
||||
// databricks().verified_query("VALUES 1, 2, 3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_use() {
|
||||
let valid_object_names = ["mydb", "WAREHOUSE", "DEFAULT"];
|
||||
let quote_styles = ['"', '`'];
|
||||
|
||||
for object_name in &valid_object_names {
|
||||
// Test single identifier without quotes
|
||||
assert_eq!(
|
||||
databricks().verified_stmt(&format!("USE {}", object_name)),
|
||||
Statement::Use(Use::Object(ObjectName(vec![Ident::new(
|
||||
object_name.to_string()
|
||||
)])))
|
||||
);
|
||||
for "e in "e_styles {
|
||||
// Test single identifier with different type of quotes
|
||||
assert_eq!(
|
||||
databricks().verified_stmt(&format!("USE {0}{1}{0}", quote, object_name)),
|
||||
Statement::Use(Use::Object(ObjectName(vec![Ident::with_quote(
|
||||
quote,
|
||||
object_name.to_string(),
|
||||
)])))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for "e in "e_styles {
|
||||
// Test single identifier with keyword and different type of quotes
|
||||
assert_eq!(
|
||||
databricks().verified_stmt(&format!("USE CATALOG {0}my_catalog{0}", quote)),
|
||||
Statement::Use(Use::Catalog(ObjectName(vec![Ident::with_quote(
|
||||
quote,
|
||||
"my_catalog".to_string(),
|
||||
)])))
|
||||
);
|
||||
assert_eq!(
|
||||
databricks().verified_stmt(&format!("USE DATABASE {0}my_database{0}", quote)),
|
||||
Statement::Use(Use::Database(ObjectName(vec![Ident::with_quote(
|
||||
quote,
|
||||
"my_database".to_string(),
|
||||
)])))
|
||||
);
|
||||
assert_eq!(
|
||||
databricks().verified_stmt(&format!("USE SCHEMA {0}my_schema{0}", quote)),
|
||||
Statement::Use(Use::Schema(ObjectName(vec![Ident::with_quote(
|
||||
quote,
|
||||
"my_schema".to_string(),
|
||||
)])))
|
||||
);
|
||||
}
|
||||
|
||||
// Test single identifier with keyword and no quotes
|
||||
assert_eq!(
|
||||
databricks().verified_stmt("USE CATALOG my_catalog"),
|
||||
Statement::Use(Use::Catalog(ObjectName(vec![Ident::new("my_catalog")])))
|
||||
);
|
||||
assert_eq!(
|
||||
databricks().verified_stmt("USE DATABASE my_schema"),
|
||||
Statement::Use(Use::Database(ObjectName(vec![Ident::new("my_schema")])))
|
||||
);
|
||||
assert_eq!(
|
||||
databricks().verified_stmt("USE SCHEMA my_schema"),
|
||||
Statement::Use(Use::Schema(ObjectName(vec![Ident::new("my_schema")])))
|
||||
);
|
||||
|
||||
// Test invalid syntax - missing identifier
|
||||
let invalid_cases = ["USE SCHEMA", "USE DATABASE", "USE CATALOG"];
|
||||
for sql in &invalid_cases {
|
||||
assert_eq!(
|
||||
databricks().parse_sql_statements(sql).unwrap_err(),
|
||||
ParserError::ParserError("Expected: identifier, found: EOF".to_string()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue