mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
Enhance object name path segments (#1539)
This commit is contained in:
parent
fd6c98e933
commit
211b15e790
20 changed files with 584 additions and 466 deletions
|
@ -634,7 +634,7 @@ fn test_snowflake_create_table_with_collated_column() {
|
|||
vec![ColumnDef {
|
||||
name: "a".into(),
|
||||
data_type: DataType::Text,
|
||||
collation: Some(ObjectName(vec![Ident::with_quote('\'', "de_DE")])),
|
||||
collation: Some(ObjectName::from(vec![Ident::with_quote('\'', "de_DE")])),
|
||||
options: vec![]
|
||||
},]
|
||||
);
|
||||
|
@ -818,7 +818,7 @@ fn test_snowflake_create_table_with_several_column_options() {
|
|||
ColumnDef {
|
||||
name: "b".into(),
|
||||
data_type: DataType::Text,
|
||||
collation: Some(ObjectName(vec![Ident::with_quote('\'', "de_DE")])),
|
||||
collation: Some(ObjectName::from(vec![Ident::with_quote('\'', "de_DE")])),
|
||||
options: vec![
|
||||
ColumnOptionDef {
|
||||
name: None,
|
||||
|
@ -1274,7 +1274,10 @@ fn parse_delimited_identifiers() {
|
|||
version,
|
||||
..
|
||||
} => {
|
||||
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
|
||||
assert_eq!(
|
||||
ObjectName::from(vec![Ident::with_quote('"', "a table")]),
|
||||
name
|
||||
);
|
||||
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
|
||||
assert!(args.is_none());
|
||||
assert!(with_hints.is_empty());
|
||||
|
@ -1293,7 +1296,7 @@ fn parse_delimited_identifiers() {
|
|||
);
|
||||
assert_eq!(
|
||||
&Expr::Function(Function {
|
||||
name: ObjectName(vec![Ident::with_quote('"', "myfun")]),
|
||||
name: ObjectName::from(vec![Ident::with_quote('"', "myfun")]),
|
||||
uses_odbc_syntax: false,
|
||||
parameters: FunctionArguments::None,
|
||||
args: FunctionArguments::List(FunctionArgumentList {
|
||||
|
@ -1365,7 +1368,7 @@ fn test_select_wildcard_with_exclude() {
|
|||
let select = snowflake_and_generic()
|
||||
.verified_only_select("SELECT name.* EXCLUDE department_id FROM employee_table");
|
||||
let expected = SelectItem::QualifiedWildcard(
|
||||
ObjectName(vec![Ident::new("name")]),
|
||||
ObjectName::from(vec![Ident::new("name")]),
|
||||
WildcardAdditionalOptions {
|
||||
opt_exclude: Some(ExcludeSelectItem::Single(Ident::new("department_id"))),
|
||||
..Default::default()
|
||||
|
@ -1402,7 +1405,7 @@ fn test_select_wildcard_with_rename() {
|
|||
"SELECT name.* RENAME (department_id AS new_dep, employee_id AS new_emp) FROM employee_table",
|
||||
);
|
||||
let expected = SelectItem::QualifiedWildcard(
|
||||
ObjectName(vec![Ident::new("name")]),
|
||||
ObjectName::from(vec![Ident::new("name")]),
|
||||
WildcardAdditionalOptions {
|
||||
opt_rename: Some(RenameSelectItem::Multiple(vec![
|
||||
IdentWithAlias {
|
||||
|
@ -1505,7 +1508,7 @@ fn test_alter_table_clustering() {
|
|||
Expr::Identifier(Ident::new("c1")),
|
||||
Expr::Identifier(Ident::with_quote('"', "c2")),
|
||||
Expr::Function(Function {
|
||||
name: ObjectName(vec![Ident::new("TO_DATE")]),
|
||||
name: ObjectName::from(vec![Ident::new("TO_DATE")]),
|
||||
uses_odbc_syntax: false,
|
||||
parameters: FunctionArguments::None,
|
||||
args: FunctionArguments::List(FunctionArgumentList {
|
||||
|
@ -2034,11 +2037,11 @@ fn test_copy_into() {
|
|||
} => {
|
||||
assert_eq!(
|
||||
into,
|
||||
ObjectName(vec![Ident::new("my_company"), Ident::new("emp_basic")])
|
||||
ObjectName::from(vec![Ident::new("my_company"), Ident::new("emp_basic")])
|
||||
);
|
||||
assert_eq!(
|
||||
from_stage,
|
||||
ObjectName(vec![Ident::with_quote('\'', "gcs://mybucket/./../a.csv")])
|
||||
ObjectName::from(vec![Ident::with_quote('\'', "gcs://mybucket/./../a.csv")])
|
||||
);
|
||||
assert!(files.is_none());
|
||||
assert!(pattern.is_none());
|
||||
|
@ -2069,7 +2072,7 @@ fn test_copy_into_with_stage_params() {
|
|||
//assert_eq!("s3://load/files/", stage_params.url.unwrap());
|
||||
assert_eq!(
|
||||
from_stage,
|
||||
ObjectName(vec![Ident::with_quote('\'', "s3://load/files/")])
|
||||
ObjectName::from(vec![Ident::with_quote('\'', "s3://load/files/")])
|
||||
);
|
||||
assert_eq!("myint", stage_params.storage_integration.unwrap());
|
||||
assert_eq!(
|
||||
|
@ -2128,7 +2131,7 @@ fn test_copy_into_with_stage_params() {
|
|||
} => {
|
||||
assert_eq!(
|
||||
from_stage,
|
||||
ObjectName(vec![Ident::with_quote('\'', "s3://load/files/")])
|
||||
ObjectName::from(vec![Ident::with_quote('\'', "s3://load/files/")])
|
||||
);
|
||||
assert_eq!("myint", stage_params.storage_integration.unwrap());
|
||||
}
|
||||
|
@ -2182,7 +2185,7 @@ fn test_copy_into_with_transformations() {
|
|||
} => {
|
||||
assert_eq!(
|
||||
from_stage,
|
||||
ObjectName(vec![Ident::new("@schema"), Ident::new("general_finished")])
|
||||
ObjectName::from(vec![Ident::new("@schema"), Ident::new("general_finished")])
|
||||
);
|
||||
assert_eq!(
|
||||
from_transformations.as_ref().unwrap()[0],
|
||||
|
@ -2291,17 +2294,17 @@ fn test_snowflake_stage_object_names() {
|
|||
"@~/path",
|
||||
];
|
||||
let mut allowed_object_names = [
|
||||
ObjectName(vec![Ident::new("my_company"), Ident::new("emp_basic")]),
|
||||
ObjectName(vec![Ident::new("@namespace"), Ident::new("%table_name")]),
|
||||
ObjectName(vec![
|
||||
ObjectName::from(vec![Ident::new("my_company"), Ident::new("emp_basic")]),
|
||||
ObjectName::from(vec![Ident::new("@namespace"), Ident::new("%table_name")]),
|
||||
ObjectName::from(vec![
|
||||
Ident::new("@namespace"),
|
||||
Ident::new("%table_name/path"),
|
||||
]),
|
||||
ObjectName(vec![
|
||||
ObjectName::from(vec![
|
||||
Ident::new("@namespace"),
|
||||
Ident::new("stage_name/path"),
|
||||
]),
|
||||
ObjectName(vec![Ident::new("@~/path")]),
|
||||
ObjectName::from(vec![Ident::new("@~/path")]),
|
||||
];
|
||||
|
||||
for it in allowed_formatted_names
|
||||
|
@ -2330,10 +2333,13 @@ fn test_snowflake_copy_into() {
|
|||
Statement::CopyIntoSnowflake {
|
||||
into, from_stage, ..
|
||||
} => {
|
||||
assert_eq!(into, ObjectName(vec![Ident::new("a"), Ident::new("b")]));
|
||||
assert_eq!(
|
||||
into,
|
||||
ObjectName::from(vec![Ident::new("a"), Ident::new("b")])
|
||||
);
|
||||
assert_eq!(
|
||||
from_stage,
|
||||
ObjectName(vec![Ident::new("@namespace"), Ident::new("stage_name")])
|
||||
ObjectName::from(vec![Ident::new("@namespace"), Ident::new("stage_name")])
|
||||
)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
@ -2350,14 +2356,14 @@ fn test_snowflake_copy_into_stage_name_ends_with_parens() {
|
|||
} => {
|
||||
assert_eq!(
|
||||
into,
|
||||
ObjectName(vec![
|
||||
ObjectName::from(vec![
|
||||
Ident::new("SCHEMA"),
|
||||
Ident::new("SOME_MONITORING_SYSTEM")
|
||||
])
|
||||
);
|
||||
assert_eq!(
|
||||
from_stage,
|
||||
ObjectName(vec![Ident::new("@schema"), Ident::new("general_finished")])
|
||||
ObjectName::from(vec![Ident::new("@schema"), Ident::new("general_finished")])
|
||||
)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
@ -2771,7 +2777,7 @@ fn parse_use() {
|
|||
// Test single identifier without quotes
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt(&format!("USE {}", object_name)),
|
||||
Statement::Use(Use::Object(ObjectName(vec![Ident::new(
|
||||
Statement::Use(Use::Object(ObjectName::from(vec![Ident::new(
|
||||
object_name.to_string()
|
||||
)])))
|
||||
);
|
||||
|
@ -2779,7 +2785,7 @@ fn parse_use() {
|
|||
// Test single identifier with different type of quotes
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt(&format!("USE {}{}{}", quote, object_name, quote)),
|
||||
Statement::Use(Use::Object(ObjectName(vec![Ident::with_quote(
|
||||
Statement::Use(Use::Object(ObjectName::from(vec![Ident::with_quote(
|
||||
quote,
|
||||
object_name.to_string(),
|
||||
)])))
|
||||
|
@ -2791,7 +2797,7 @@ fn parse_use() {
|
|||
// Test double identifier with different type of quotes
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt(&format!("USE {0}CATALOG{0}.{0}my_schema{0}", quote)),
|
||||
Statement::Use(Use::Object(ObjectName(vec![
|
||||
Statement::Use(Use::Object(ObjectName::from(vec![
|
||||
Ident::with_quote(quote, "CATALOG"),
|
||||
Ident::with_quote(quote, "my_schema")
|
||||
])))
|
||||
|
@ -2800,7 +2806,7 @@ fn parse_use() {
|
|||
// Test double identifier without quotes
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt("USE mydb.my_schema"),
|
||||
Statement::Use(Use::Object(ObjectName(vec![
|
||||
Statement::Use(Use::Object(ObjectName::from(vec![
|
||||
Ident::new("mydb"),
|
||||
Ident::new("my_schema")
|
||||
])))
|
||||
|
@ -2810,35 +2816,35 @@ fn parse_use() {
|
|||
// Test single and double identifier with keyword and different type of quotes
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt(&format!("USE DATABASE {0}my_database{0}", quote)),
|
||||
Statement::Use(Use::Database(ObjectName(vec![Ident::with_quote(
|
||||
Statement::Use(Use::Database(ObjectName::from(vec![Ident::with_quote(
|
||||
quote,
|
||||
"my_database".to_string(),
|
||||
)])))
|
||||
);
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt(&format!("USE SCHEMA {0}my_schema{0}", quote)),
|
||||
Statement::Use(Use::Schema(ObjectName(vec![Ident::with_quote(
|
||||
Statement::Use(Use::Schema(ObjectName::from(vec![Ident::with_quote(
|
||||
quote,
|
||||
"my_schema".to_string(),
|
||||
)])))
|
||||
);
|
||||
assert_eq!(
|
||||
snowflake().verified_stmt(&format!("USE SCHEMA {0}CATALOG{0}.{0}my_schema{0}", quote)),
|
||||
Statement::Use(Use::Schema(ObjectName(vec![
|
||||
Statement::Use(Use::Schema(ObjectName::from(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(
|
||||
Statement::Use(Use::Role(ObjectName::from(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(
|
||||
Statement::Use(Use::Warehouse(ObjectName::from(vec![Ident::with_quote(
|
||||
quote,
|
||||
"my_wh".to_string(),
|
||||
)])))
|
||||
|
@ -3076,7 +3082,7 @@ fn parse_ls_and_rm() {
|
|||
.verified_stmt("LIST @SNOWFLAKE_KAFKA_CONNECTOR_externalDataLakeSnowflakeConnector_STAGE_call_tracker_stream/");
|
||||
match statement {
|
||||
Statement::List(command) => {
|
||||
assert_eq!(command.stage, ObjectName(vec!["@SNOWFLAKE_KAFKA_CONNECTOR_externalDataLakeSnowflakeConnector_STAGE_call_tracker_stream/".into()]));
|
||||
assert_eq!(command.stage, ObjectName::from(vec!["@SNOWFLAKE_KAFKA_CONNECTOR_externalDataLakeSnowflakeConnector_STAGE_call_tracker_stream/".into()]));
|
||||
assert!(command.pattern.is_none());
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
@ -3088,7 +3094,7 @@ fn parse_ls_and_rm() {
|
|||
Statement::Remove(command) => {
|
||||
assert_eq!(
|
||||
command.stage,
|
||||
ObjectName(vec!["@my_csv_stage/analysis/".into()])
|
||||
ObjectName::from(vec!["@my_csv_stage/analysis/".into()])
|
||||
);
|
||||
assert_eq!(command.pattern, Some(".*data_0.*".to_string()));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue