diff --git a/tests/sqlparser_clickhouse.rs b/tests/sqlparser_clickhouse.rs index 2c59d66cad..3e6fe93270 100644 --- a/tests/sqlparser_clickhouse.rs +++ b/tests/sqlparser_clickhouse.rs @@ -156,65 +156,6 @@ fn parse_kill() { #[test] fn parse_delimited_identifiers() { - // check that quoted identifiers in any position remain quoted after serialization - let select = clickhouse().verified_only_select( - r#"SELECT "alias"."bar baz", "myfun"(), "simple id" AS "column alias" FROM "a table" AS "alias""#, - ); - // check FROM - match only(select.from).relation { - TableFactor::Table { - name, - alias, - args, - with_hints, - version, - .. - } => { - 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()); - assert!(version.is_none()); - } - _ => panic!("Expecting TableFactor::Table"), - } - // check SELECT - assert_eq!(3, select.projection.len()); - assert_eq!( - &Expr::CompoundIdentifier(vec![ - Ident::with_quote('"', "alias"), - Ident::with_quote('"', "bar baz"), - ]), - expr_from_projection(&select.projection[0]), - ); - assert_eq!( - &Expr::Function(Function { - name: ObjectName::from(vec![Ident::with_quote('"', "myfun")]), - uses_odbc_syntax: false, - parameters: FunctionArguments::None, - args: FunctionArguments::List(FunctionArgumentList { - duplicate_treatment: None, - args: vec![], - clauses: vec![], - }), - null_treatment: None, - filter: None, - over: None, - within_group: vec![], - }), - expr_from_projection(&select.projection[1]), - ); - match &select.projection[2] { - SelectItem::ExprWithAlias { expr, alias } => { - assert_eq!(&Expr::Identifier(Ident::with_quote('"', "simple id")), expr); - assert_eq!(&Ident::with_quote('"', "column alias"), alias); - } - _ => panic!("Expected ExprWithAlias"), - } - clickhouse().verified_stmt(r#"CREATE TABLE "foo" ("bar" "int")"#); clickhouse().verified_stmt(r#"ALTER TABLE foo ADD CONSTRAINT "bar" PRIMARY KEY (baz)"#); //TODO verified_stmt(r#"UPDATE foo SET "bar" = 5"#); diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 4dfd4f48f9..90a11b5647 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -22273,3 +22273,71 @@ fn unsupported_key_column_option_preserves_keyword() { assert!(parser.parse_keyword(Keyword::KEY), "{dialect:?}"); } } + +#[test] +fn parse_delimited_identifiers() { + let dialects = TestedDialects::new(vec![ + Box::new(ClickHouseDialect {}), + Box::new(MsSqlDialect {}), + Box::new(GenericDialect {}), + Box::new(HiveDialect {}), + Box::new(PostgreSqlDialect {}), + Box::new(RedshiftSqlDialect {}), + Box::new(SnowflakeDialect {}), + ]); + let select = dialects.verified_only_select( + r#"SELECT "alias"."bar baz", "myfun"(), "simple id" AS "column alias" FROM "a table" AS "alias""#, + ); + match only(select.from).relation { + TableFactor::Table { + name, + alias, + args, + with_hints, + version, + .. + } => { + 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()); + assert!(version.is_none()); + } + _ => panic!("Expecting TableFactor::Table"), + } + assert_eq!(3, select.projection.len()); + assert_eq!( + &Expr::CompoundIdentifier(vec![ + Ident::with_quote('"', "alias"), + Ident::with_quote('"', "bar baz"), + ]), + expr_from_projection(&select.projection[0]), + ); + assert_eq!( + &Expr::Function(Function { + name: ObjectName::from(vec![Ident::with_quote('"', "myfun")]), + uses_odbc_syntax: false, + parameters: FunctionArguments::None, + args: FunctionArguments::List(FunctionArgumentList { + duplicate_treatment: None, + args: vec![], + clauses: vec![], + }), + null_treatment: None, + filter: None, + over: None, + within_group: vec![], + }), + expr_from_projection(&select.projection[1]), + ); + match &select.projection[2] { + SelectItem::ExprWithAlias { expr, alias } => { + assert_eq!(&Expr::Identifier(Ident::with_quote('"', "simple id")), expr); + assert_eq!(&Ident::with_quote('"', "column alias"), alias); + } + _ => panic!("Expected ExprWithAlias"), + } +} diff --git a/tests/sqlparser_hive.rs b/tests/sqlparser_hive.rs index ab4d4f141a..355fd5c8d5 100644 --- a/tests/sqlparser_hive.rs +++ b/tests/sqlparser_hive.rs @@ -22,9 +22,8 @@ use sqlparser::ast::{ ClusteredBy, CommentDef, CreateFunction, CreateFunctionBody, CreateFunctionUsing, CreateTable, - Expr, Function, FunctionArgumentList, FunctionArguments, Ident, ObjectName, OrderByExpr, - OrderByOptions, OrderBySort, SelectItem, Set, Statement, TableFactor, UnaryOperator, Use, - Value, + Expr, Ident, ObjectName, OrderByExpr, OrderByOptions, OrderBySort, Set, Statement, + UnaryOperator, Use, Value, }; use sqlparser::dialect::{AnsiDialect, GenericDialect, HiveDialect}; use sqlparser::parser::ParserError; @@ -461,69 +460,6 @@ fn filter_as_alias() { #[test] fn parse_delimited_identifiers() { - // check that quoted identifiers in any position remain quoted after serialization - let select = hive().verified_only_select( - r#"SELECT "alias"."bar baz", "myfun"(), "simple id" AS "column alias" FROM "a table" AS "alias""#, - ); - // check FROM - match only(select.from).relation { - TableFactor::Table { - name, - alias, - args, - with_hints, - version, - with_ordinality: _, - partitions: _, - json_path: _, - sample: _, - index_directives: _, - } => { - 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()); - assert!(version.is_none()); - } - _ => panic!("Expecting TableFactor::Table"), - } - // check SELECT - assert_eq!(3, select.projection.len()); - assert_eq!( - &Expr::CompoundIdentifier(vec![ - Ident::with_quote('"', "alias"), - Ident::with_quote('"', "bar baz"), - ]), - expr_from_projection(&select.projection[0]), - ); - assert_eq!( - &Expr::Function(Function { - name: ObjectName::from(vec![Ident::with_quote('"', "myfun")]), - uses_odbc_syntax: false, - parameters: FunctionArguments::None, - args: FunctionArguments::List(FunctionArgumentList { - duplicate_treatment: None, - args: vec![], - clauses: vec![], - }), - null_treatment: None, - filter: None, - over: None, - within_group: vec![], - }), - expr_from_projection(&select.projection[1]), - ); - match &select.projection[2] { - SelectItem::ExprWithAlias { expr, alias } => { - assert_eq!(&Expr::Identifier(Ident::with_quote('"', "simple id")), expr); - assert_eq!(&Ident::with_quote('"', "column alias"), alias); - } - _ => panic!("Expected: ExprWithAlias"), - } - hive().verified_stmt(r#"CREATE TABLE "foo" ("bar" "int")"#); hive().verified_stmt(r#"ALTER TABLE foo ADD CONSTRAINT "bar" PRIMARY KEY (baz)"#); //TODO verified_stmt(r#"UPDATE foo SET "bar" = 5"#); diff --git a/tests/sqlparser_mssql.rs b/tests/sqlparser_mssql.rs index 23388bd15a..fe8531cace 100644 --- a/tests/sqlparser_mssql.rs +++ b/tests/sqlparser_mssql.rs @@ -858,65 +858,6 @@ fn parse_alter_role() { #[test] fn parse_delimited_identifiers() { - // check that quoted identifiers in any position remain quoted after serialization - let select = ms_and_generic().verified_only_select( - r#"SELECT "alias"."bar baz", "myfun"(), "simple id" AS "column alias" FROM "a table" AS "alias""#, - ); - // check FROM - match only(select.from).relation { - TableFactor::Table { - name, - alias, - args, - with_hints, - version, - .. - } => { - 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()); - assert!(version.is_none()); - } - _ => panic!("Expecting TableFactor::Table"), - } - // check SELECT - assert_eq!(3, select.projection.len()); - assert_eq!( - &Expr::CompoundIdentifier(vec![ - Ident::with_quote('"', "alias"), - Ident::with_quote('"', "bar baz"), - ]), - expr_from_projection(&select.projection[0]), - ); - assert_eq!( - &Expr::Function(Function { - name: ObjectName::from(vec![Ident::with_quote('"', "myfun")]), - uses_odbc_syntax: false, - parameters: FunctionArguments::None, - args: FunctionArguments::List(FunctionArgumentList { - duplicate_treatment: None, - args: vec![], - clauses: vec![], - }), - null_treatment: None, - filter: None, - over: None, - within_group: vec![], - }), - expr_from_projection(&select.projection[1]), - ); - match &select.projection[2] { - SelectItem::ExprWithAlias { expr, alias } => { - assert_eq!(&Expr::Identifier(Ident::with_quote('"', "simple id")), expr); - assert_eq!(&Ident::with_quote('"', "column alias"), alias); - } - _ => panic!("Expected ExprWithAlias"), - } - ms_and_generic().verified_stmt(r#"CREATE TABLE "foo" ("bar" "int")"#); ms_and_generic().verified_stmt(r#"ALTER TABLE foo ADD CONSTRAINT "bar" PRIMARY KEY (baz)"#); //TODO verified_stmt(r#"UPDATE foo SET "bar" = 5"#); diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index 74072e9f51..e882668378 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs @@ -5104,65 +5104,6 @@ fn parse_alter_user() { #[test] fn parse_delimited_identifiers() { - // check that quoted identifiers in any position remain quoted after serialization - let select = pg().verified_only_select( - r#"SELECT "alias"."bar baz", "myfun"(), "simple id" AS "column alias" FROM "a table" AS "alias""#, - ); - // check FROM - match only(select.from).relation { - TableFactor::Table { - name, - alias, - args, - with_hints, - version, - .. - } => { - 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()); - assert!(version.is_none()); - } - _ => panic!("Expecting TableFactor::Table"), - } - // check SELECT - assert_eq!(3, select.projection.len()); - assert_eq!( - &Expr::CompoundIdentifier(vec![ - Ident::with_quote('"', "alias"), - Ident::with_quote('"', "bar baz"), - ]), - expr_from_projection(&select.projection[0]), - ); - assert_eq!( - &Expr::Function(Function { - name: ObjectName::from(vec![Ident::with_quote('"', "myfun")]), - uses_odbc_syntax: false, - parameters: FunctionArguments::None, - args: FunctionArguments::List(FunctionArgumentList { - duplicate_treatment: None, - args: vec![], - clauses: vec![], - }), - null_treatment: None, - filter: None, - over: None, - within_group: vec![], - }), - expr_from_projection(&select.projection[1]), - ); - match &select.projection[2] { - SelectItem::ExprWithAlias { expr, alias } => { - assert_eq!(&Expr::Identifier(Ident::with_quote('"', "simple id")), expr); - assert_eq!(&Ident::with_quote('"', "column alias"), alias); - } - _ => panic!("Expected: ExprWithAlias"), - } - pg().verified_stmt(r#"CREATE TABLE "foo" ("bar" "int")"#); pg().verified_stmt(r#"ALTER TABLE foo ADD CONSTRAINT "bar" PRIMARY KEY (baz)"#); pg().verified_stmt(r#"UPDATE foo SET "bar" = 5"#); diff --git a/tests/sqlparser_redshift.rs b/tests/sqlparser_redshift.rs index 5bf1a89328..3ffc567e6d 100644 --- a/tests/sqlparser_redshift.rs +++ b/tests/sqlparser_redshift.rs @@ -101,65 +101,6 @@ fn test_double_quotes_over_db_schema_table_name() { #[test] fn parse_delimited_identifiers() { - // check that quoted identifiers in any position remain quoted after serialization - let select = redshift().verified_only_select( - r#"SELECT "alias"."bar baz", "myfun"(), "simple id" AS "column alias" FROM "a table" AS "alias""#, - ); - // check FROM - match only(select.from).relation { - TableFactor::Table { - name, - alias, - args, - with_hints, - version, - .. - } => { - 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()); - assert!(version.is_none()); - } - _ => panic!("Expecting TableFactor::Table"), - } - // check SELECT - assert_eq!(3, select.projection.len()); - assert_eq!( - &Expr::CompoundIdentifier(vec![ - Ident::with_quote('"', "alias"), - Ident::with_quote('"', "bar baz"), - ]), - expr_from_projection(&select.projection[0]), - ); - assert_eq!( - &Expr::Function(Function { - name: ObjectName::from(vec![Ident::with_quote('"', "myfun")]), - uses_odbc_syntax: false, - parameters: FunctionArguments::None, - args: FunctionArguments::List(FunctionArgumentList { - duplicate_treatment: None, - args: vec![], - clauses: vec![], - }), - null_treatment: None, - filter: None, - over: None, - within_group: vec![], - }), - expr_from_projection(&select.projection[1]), - ); - match &select.projection[2] { - SelectItem::ExprWithAlias { expr, alias } => { - assert_eq!(&Expr::Identifier(Ident::with_quote('"', "simple id")), expr); - assert_eq!(&Ident::with_quote('"', "column alias"), alias); - } - _ => panic!("Expected ExprWithAlias"), - } - redshift().verified_stmt(r#"CREATE TABLE "foo" ("bar" "int")"#); // An alias starting with a number redshift().verified_stmt(r#"CREATE TABLE "foo" ("1" INT)"#); diff --git a/tests/sqlparser_snowflake.rs b/tests/sqlparser_snowflake.rs index 0c37194467..5e3cbc8e01 100644 --- a/tests/sqlparser_snowflake.rs +++ b/tests/sqlparser_snowflake.rs @@ -1406,65 +1406,6 @@ fn parse_semi_structured_data_traversal() { #[test] fn parse_delimited_identifiers() { - // check that quoted identifiers in any position remain quoted after serialization - let select = snowflake().verified_only_select( - r#"SELECT "alias"."bar baz", "myfun"(), "simple id" AS "column alias" FROM "a table" AS "alias""#, - ); - // check FROM - match only(select.from).relation { - TableFactor::Table { - name, - alias, - args, - with_hints, - version, - .. - } => { - 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()); - assert!(version.is_none()); - } - _ => panic!("Expecting TableFactor::Table"), - } - // check SELECT - assert_eq!(3, select.projection.len()); - assert_eq!( - &Expr::CompoundIdentifier(vec![ - Ident::with_quote('"', "alias"), - Ident::with_quote('"', "bar baz"), - ]), - expr_from_projection(&select.projection[0]), - ); - assert_eq!( - &Expr::Function(Function { - name: ObjectName::from(vec![Ident::with_quote('"', "myfun")]), - uses_odbc_syntax: false, - parameters: FunctionArguments::None, - args: FunctionArguments::List(FunctionArgumentList { - duplicate_treatment: None, - args: vec![], - clauses: vec![], - }), - filter: None, - null_treatment: None, - over: None, - within_group: vec![], - }), - expr_from_projection(&select.projection[1]), - ); - match &select.projection[2] { - SelectItem::ExprWithAlias { expr, alias } => { - assert_eq!(&Expr::Identifier(Ident::with_quote('"', "simple id")), expr); - assert_eq!(&Ident::with_quote('"', "column alias"), alias); - } - _ => panic!("Expected: ExprWithAlias"), - } - snowflake().verified_stmt(r#"CREATE TABLE "foo" ("bar" "int")"#); snowflake().verified_stmt(r#"ALTER TABLE foo ADD CONSTRAINT "bar" PRIMARY KEY (baz)"#); //TODO verified_stmt(r#"UPDATE foo SET "bar" = 5"#);