Skip to content

Commit c746f90

Browse files
Tests: Share quoted-identifier assertions
1 parent 583c4d4 commit c746f90

7 files changed

Lines changed: 70 additions & 361 deletions

‎tests/sqlparser_clickhouse.rs‎

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -156,65 +156,6 @@ fn parse_kill() {
156156

157157
#[test]
158158
fn parse_delimited_identifiers() {
159-
// check that quoted identifiers in any position remain quoted after serialization
160-
let select = clickhouse().verified_only_select(
161-
r#"SELECT "alias"."bar baz", "myfun"(), "simple id" AS "column alias" FROM "a table" AS "alias""#,
162-
);
163-
// check FROM
164-
match only(select.from).relation {
165-
TableFactor::Table {
166-
name,
167-
alias,
168-
args,
169-
with_hints,
170-
version,
171-
..
172-
} => {
173-
assert_eq!(
174-
ObjectName::from(vec![Ident::with_quote('"', "a table")]),
175-
name
176-
);
177-
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
178-
assert!(args.is_none());
179-
assert!(with_hints.is_empty());
180-
assert!(version.is_none());
181-
}
182-
_ => panic!("Expecting TableFactor::Table"),
183-
}
184-
// check SELECT
185-
assert_eq!(3, select.projection.len());
186-
assert_eq!(
187-
&Expr::CompoundIdentifier(vec![
188-
Ident::with_quote('"', "alias"),
189-
Ident::with_quote('"', "bar baz"),
190-
]),
191-
expr_from_projection(&select.projection[0]),
192-
);
193-
assert_eq!(
194-
&Expr::Function(Function {
195-
name: ObjectName::from(vec![Ident::with_quote('"', "myfun")]),
196-
uses_odbc_syntax: false,
197-
parameters: FunctionArguments::None,
198-
args: FunctionArguments::List(FunctionArgumentList {
199-
duplicate_treatment: None,
200-
args: vec![],
201-
clauses: vec![],
202-
}),
203-
null_treatment: None,
204-
filter: None,
205-
over: None,
206-
within_group: vec![],
207-
}),
208-
expr_from_projection(&select.projection[1]),
209-
);
210-
match &select.projection[2] {
211-
SelectItem::ExprWithAlias { expr, alias } => {
212-
assert_eq!(&Expr::Identifier(Ident::with_quote('"', "simple id")), expr);
213-
assert_eq!(&Ident::with_quote('"', "column alias"), alias);
214-
}
215-
_ => panic!("Expected ExprWithAlias"),
216-
}
217-
218159
clickhouse().verified_stmt(r#"CREATE TABLE "foo" ("bar" "int")"#);
219160
clickhouse().verified_stmt(r#"ALTER TABLE foo ADD CONSTRAINT "bar" PRIMARY KEY (baz)"#);
220161
//TODO verified_stmt(r#"UPDATE foo SET "bar" = 5"#);

‎tests/sqlparser_common.rs‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22230,3 +22230,71 @@ fn parse_div_with_nested_divisor() {
2223022230
}
2223122231
);
2223222232
}
22233+
22234+
#[test]
22235+
fn parse_delimited_identifiers() {
22236+
let dialects = TestedDialects::new(vec![
22237+
Box::new(ClickHouseDialect {}),
22238+
Box::new(MsSqlDialect {}),
22239+
Box::new(GenericDialect {}),
22240+
Box::new(HiveDialect {}),
22241+
Box::new(PostgreSqlDialect {}),
22242+
Box::new(RedshiftSqlDialect {}),
22243+
Box::new(SnowflakeDialect {}),
22244+
]);
22245+
let select = dialects.verified_only_select(
22246+
r#"SELECT "alias"."bar baz", "myfun"(), "simple id" AS "column alias" FROM "a table" AS "alias""#,
22247+
);
22248+
match only(select.from).relation {
22249+
TableFactor::Table {
22250+
name,
22251+
alias,
22252+
args,
22253+
with_hints,
22254+
version,
22255+
..
22256+
} => {
22257+
assert_eq!(
22258+
ObjectName::from(vec![Ident::with_quote('"', "a table")]),
22259+
name
22260+
);
22261+
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
22262+
assert!(args.is_none());
22263+
assert!(with_hints.is_empty());
22264+
assert!(version.is_none());
22265+
}
22266+
_ => panic!("Expecting TableFactor::Table"),
22267+
}
22268+
assert_eq!(3, select.projection.len());
22269+
assert_eq!(
22270+
&Expr::CompoundIdentifier(vec![
22271+
Ident::with_quote('"', "alias"),
22272+
Ident::with_quote('"', "bar baz"),
22273+
]),
22274+
expr_from_projection(&select.projection[0]),
22275+
);
22276+
assert_eq!(
22277+
&Expr::Function(Function {
22278+
name: ObjectName::from(vec![Ident::with_quote('"', "myfun")]),
22279+
uses_odbc_syntax: false,
22280+
parameters: FunctionArguments::None,
22281+
args: FunctionArguments::List(FunctionArgumentList {
22282+
duplicate_treatment: None,
22283+
args: vec![],
22284+
clauses: vec![],
22285+
}),
22286+
null_treatment: None,
22287+
filter: None,
22288+
over: None,
22289+
within_group: vec![],
22290+
}),
22291+
expr_from_projection(&select.projection[1]),
22292+
);
22293+
match &select.projection[2] {
22294+
SelectItem::ExprWithAlias { expr, alias } => {
22295+
assert_eq!(&Expr::Identifier(Ident::with_quote('"', "simple id")), expr);
22296+
assert_eq!(&Ident::with_quote('"', "column alias"), alias);
22297+
}
22298+
_ => panic!("Expected ExprWithAlias"),
22299+
}
22300+
}

‎tests/sqlparser_hive.rs‎

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
2323
use sqlparser::ast::{
2424
ClusteredBy, CommentDef, CreateFunction, CreateFunctionBody, CreateFunctionUsing, CreateTable,
25-
Expr, Function, FunctionArgumentList, FunctionArguments, Ident, ObjectName, OrderByExpr,
26-
OrderByOptions, OrderBySort, SelectItem, Set, Statement, TableFactor, UnaryOperator, Use,
27-
Value,
25+
Expr, Ident, ObjectName, OrderByExpr, OrderByOptions, OrderBySort, Set, Statement,
26+
UnaryOperator, Use, Value,
2827
};
2928
use sqlparser::dialect::{AnsiDialect, GenericDialect, HiveDialect};
3029
use sqlparser::parser::ParserError;
@@ -461,69 +460,6 @@ fn filter_as_alias() {
461460

462461
#[test]
463462
fn parse_delimited_identifiers() {
464-
// check that quoted identifiers in any position remain quoted after serialization
465-
let select = hive().verified_only_select(
466-
r#"SELECT "alias"."bar baz", "myfun"(), "simple id" AS "column alias" FROM "a table" AS "alias""#,
467-
);
468-
// check FROM
469-
match only(select.from).relation {
470-
TableFactor::Table {
471-
name,
472-
alias,
473-
args,
474-
with_hints,
475-
version,
476-
with_ordinality: _,
477-
partitions: _,
478-
json_path: _,
479-
sample: _,
480-
index_directives: _,
481-
} => {
482-
assert_eq!(
483-
ObjectName::from(vec![Ident::with_quote('"', "a table")]),
484-
name
485-
);
486-
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
487-
assert!(args.is_none());
488-
assert!(with_hints.is_empty());
489-
assert!(version.is_none());
490-
}
491-
_ => panic!("Expecting TableFactor::Table"),
492-
}
493-
// check SELECT
494-
assert_eq!(3, select.projection.len());
495-
assert_eq!(
496-
&Expr::CompoundIdentifier(vec![
497-
Ident::with_quote('"', "alias"),
498-
Ident::with_quote('"', "bar baz"),
499-
]),
500-
expr_from_projection(&select.projection[0]),
501-
);
502-
assert_eq!(
503-
&Expr::Function(Function {
504-
name: ObjectName::from(vec![Ident::with_quote('"', "myfun")]),
505-
uses_odbc_syntax: false,
506-
parameters: FunctionArguments::None,
507-
args: FunctionArguments::List(FunctionArgumentList {
508-
duplicate_treatment: None,
509-
args: vec![],
510-
clauses: vec![],
511-
}),
512-
null_treatment: None,
513-
filter: None,
514-
over: None,
515-
within_group: vec![],
516-
}),
517-
expr_from_projection(&select.projection[1]),
518-
);
519-
match &select.projection[2] {
520-
SelectItem::ExprWithAlias { expr, alias } => {
521-
assert_eq!(&Expr::Identifier(Ident::with_quote('"', "simple id")), expr);
522-
assert_eq!(&Ident::with_quote('"', "column alias"), alias);
523-
}
524-
_ => panic!("Expected: ExprWithAlias"),
525-
}
526-
527463
hive().verified_stmt(r#"CREATE TABLE "foo" ("bar" "int")"#);
528464
hive().verified_stmt(r#"ALTER TABLE foo ADD CONSTRAINT "bar" PRIMARY KEY (baz)"#);
529465
//TODO verified_stmt(r#"UPDATE foo SET "bar" = 5"#);

‎tests/sqlparser_mssql.rs‎

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -858,65 +858,6 @@ fn parse_alter_role() {
858858

859859
#[test]
860860
fn parse_delimited_identifiers() {
861-
// check that quoted identifiers in any position remain quoted after serialization
862-
let select = ms_and_generic().verified_only_select(
863-
r#"SELECT "alias"."bar baz", "myfun"(), "simple id" AS "column alias" FROM "a table" AS "alias""#,
864-
);
865-
// check FROM
866-
match only(select.from).relation {
867-
TableFactor::Table {
868-
name,
869-
alias,
870-
args,
871-
with_hints,
872-
version,
873-
..
874-
} => {
875-
assert_eq!(
876-
ObjectName::from(vec![Ident::with_quote('"', "a table")]),
877-
name
878-
);
879-
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
880-
assert!(args.is_none());
881-
assert!(with_hints.is_empty());
882-
assert!(version.is_none());
883-
}
884-
_ => panic!("Expecting TableFactor::Table"),
885-
}
886-
// check SELECT
887-
assert_eq!(3, select.projection.len());
888-
assert_eq!(
889-
&Expr::CompoundIdentifier(vec![
890-
Ident::with_quote('"', "alias"),
891-
Ident::with_quote('"', "bar baz"),
892-
]),
893-
expr_from_projection(&select.projection[0]),
894-
);
895-
assert_eq!(
896-
&Expr::Function(Function {
897-
name: ObjectName::from(vec![Ident::with_quote('"', "myfun")]),
898-
uses_odbc_syntax: false,
899-
parameters: FunctionArguments::None,
900-
args: FunctionArguments::List(FunctionArgumentList {
901-
duplicate_treatment: None,
902-
args: vec![],
903-
clauses: vec![],
904-
}),
905-
null_treatment: None,
906-
filter: None,
907-
over: None,
908-
within_group: vec![],
909-
}),
910-
expr_from_projection(&select.projection[1]),
911-
);
912-
match &select.projection[2] {
913-
SelectItem::ExprWithAlias { expr, alias } => {
914-
assert_eq!(&Expr::Identifier(Ident::with_quote('"', "simple id")), expr);
915-
assert_eq!(&Ident::with_quote('"', "column alias"), alias);
916-
}
917-
_ => panic!("Expected ExprWithAlias"),
918-
}
919-
920861
ms_and_generic().verified_stmt(r#"CREATE TABLE "foo" ("bar" "int")"#);
921862
ms_and_generic().verified_stmt(r#"ALTER TABLE foo ADD CONSTRAINT "bar" PRIMARY KEY (baz)"#);
922863
//TODO verified_stmt(r#"UPDATE foo SET "bar" = 5"#);

‎tests/sqlparser_postgres.rs‎

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5104,65 +5104,6 @@ fn parse_alter_user() {
51045104

51055105
#[test]
51065106
fn parse_delimited_identifiers() {
5107-
// check that quoted identifiers in any position remain quoted after serialization
5108-
let select = pg().verified_only_select(
5109-
r#"SELECT "alias"."bar baz", "myfun"(), "simple id" AS "column alias" FROM "a table" AS "alias""#,
5110-
);
5111-
// check FROM
5112-
match only(select.from).relation {
5113-
TableFactor::Table {
5114-
name,
5115-
alias,
5116-
args,
5117-
with_hints,
5118-
version,
5119-
..
5120-
} => {
5121-
assert_eq!(
5122-
ObjectName::from(vec![Ident::with_quote('"', "a table")]),
5123-
name
5124-
);
5125-
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
5126-
assert!(args.is_none());
5127-
assert!(with_hints.is_empty());
5128-
assert!(version.is_none());
5129-
}
5130-
_ => panic!("Expecting TableFactor::Table"),
5131-
}
5132-
// check SELECT
5133-
assert_eq!(3, select.projection.len());
5134-
assert_eq!(
5135-
&Expr::CompoundIdentifier(vec![
5136-
Ident::with_quote('"', "alias"),
5137-
Ident::with_quote('"', "bar baz"),
5138-
]),
5139-
expr_from_projection(&select.projection[0]),
5140-
);
5141-
assert_eq!(
5142-
&Expr::Function(Function {
5143-
name: ObjectName::from(vec![Ident::with_quote('"', "myfun")]),
5144-
uses_odbc_syntax: false,
5145-
parameters: FunctionArguments::None,
5146-
args: FunctionArguments::List(FunctionArgumentList {
5147-
duplicate_treatment: None,
5148-
args: vec![],
5149-
clauses: vec![],
5150-
}),
5151-
null_treatment: None,
5152-
filter: None,
5153-
over: None,
5154-
within_group: vec![],
5155-
}),
5156-
expr_from_projection(&select.projection[1]),
5157-
);
5158-
match &select.projection[2] {
5159-
SelectItem::ExprWithAlias { expr, alias } => {
5160-
assert_eq!(&Expr::Identifier(Ident::with_quote('"', "simple id")), expr);
5161-
assert_eq!(&Ident::with_quote('"', "column alias"), alias);
5162-
}
5163-
_ => panic!("Expected: ExprWithAlias"),
5164-
}
5165-
51665107
pg().verified_stmt(r#"CREATE TABLE "foo" ("bar" "int")"#);
51675108
pg().verified_stmt(r#"ALTER TABLE foo ADD CONSTRAINT "bar" PRIMARY KEY (baz)"#);
51685109
pg().verified_stmt(r#"UPDATE foo SET "bar" = 5"#);

0 commit comments

Comments
 (0)