diff --git a/crates/codegen/src/get_node_properties.rs b/crates/codegen/src/get_node_properties.rs index dd5ca160..6f9443a4 100644 --- a/crates/codegen/src/get_node_properties.rs +++ b/crates/codegen/src/get_node_properties.rs @@ -668,6 +668,17 @@ fn custom_handlers(node: &Node) -> TokenStream { _ => panic!("Unknown IndexElem {:#?}", n.nulls_ordering()), } }, + "CreateTableSpaceStmt" => quote! { + tokens.push(TokenProperty::from(Token::Create)); + tokens.push(TokenProperty::from(Token::Tablespace)); + tokens.push(TokenProperty::from(Token::Location)); + if n.owner.is_some() { + tokens.push(TokenProperty::from(Token::Owner)); + } + if n.options.len() > 0 { + tokens.push(TokenProperty::from(Token::With)); + } + }, _ => quote! {}, } } diff --git a/crates/parser/src/codegen.rs b/crates/parser/src/codegen.rs index 648eb5ea..7a297924 100644 --- a/crates/parser/src/codegen.rs +++ b/crates/parser/src/codegen.rs @@ -239,4 +239,21 @@ mod tests { ], ) } + + #[test] + fn test_create_tablespace() { + test_get_node_properties( + "create tablespace x owner a location 'b' with (seq_page_cost=3);", + SyntaxKind::CreateTableSpaceStmt, + vec![ + TokenProperty::from(SyntaxKind::Create), + TokenProperty::from(SyntaxKind::Tablespace), + TokenProperty::from(SyntaxKind::Location), + TokenProperty::from(SyntaxKind::Owner), + TokenProperty::from(SyntaxKind::With), + TokenProperty::from("x".to_string()), + TokenProperty::from("b".to_string()), + ], + ) + } } diff --git a/crates/parser/tests/data/statements/valid/0048.sql b/crates/parser/tests/data/statements/valid/0048.sql new file mode 100644 index 00000000..4d0e2ec2 --- /dev/null +++ b/crates/parser/tests/data/statements/valid/0048.sql @@ -0,0 +1,2 @@ +CREATE TABLESPACE x LOCATION 'a'; +CREATE TABLESPACE x OWNER a LOCATION 'b' WITH (random_page_cost=42, seq_page_cost=3); diff --git a/crates/parser/tests/snapshots/statements/valid/0048@1.snap b/crates/parser/tests/snapshots/statements/valid/0048@1.snap new file mode 100644 index 00000000..d2573da0 --- /dev/null +++ b/crates/parser/tests/snapshots/statements/valid/0048@1.snap @@ -0,0 +1,33 @@ +--- +source: crates/parser/tests/statement_parser_test.rs +description: "CREATE TABLESPACE x LOCATION 'a';" +--- +Parse { + cst: SourceFile@0..33 + CreateTableSpaceStmt@0..33 + Create@0..6 "CREATE" + Whitespace@6..7 " " + Tablespace@7..17 "TABLESPACE" + Whitespace@17..18 " " + Ident@18..19 "x" + Whitespace@19..20 " " + Location@20..28 "LOCATION" + Whitespace@28..29 " " + Sconst@29..32 "'a'" + Ascii59@32..33 ";" + , + errors: [], + stmts: [ + RawStmt { + stmt: CreateTableSpaceStmt( + CreateTableSpaceStmt { + tablespacename: "x", + owner: None, + location: "a", + options: [], + }, + ), + range: 0..32, + }, + ], +} diff --git a/crates/parser/tests/snapshots/statements/valid/0048@2.snap b/crates/parser/tests/snapshots/statements/valid/0048@2.snap new file mode 100644 index 00000000..0dfc3881 --- /dev/null +++ b/crates/parser/tests/snapshots/statements/valid/0048@2.snap @@ -0,0 +1,107 @@ +--- +source: crates/parser/tests/statement_parser_test.rs +description: "\nCREATE TABLESPACE x OWNER a LOCATION 'b' WITH (random_page_cost=42, seq_page_cost=3);" +--- +Parse { + cst: SourceFile@0..86 + Newline@0..1 "\n" + CreateTableSpaceStmt@1..86 + Create@1..7 "CREATE" + Whitespace@7..8 " " + Tablespace@8..18 "TABLESPACE" + Whitespace@18..19 " " + Ident@19..20 "x" + Whitespace@20..21 " " + Owner@21..26 "OWNER" + Whitespace@26..27 " " + RoleSpec@27..28 + Ident@27..28 "a" + Whitespace@28..29 " " + Location@29..37 "LOCATION" + Whitespace@37..38 " " + Sconst@38..41 "'b'" + Whitespace@41..42 " " + With@42..46 "WITH" + Whitespace@46..47 " " + Ascii40@47..48 "(" + DefElem@48..67 + Ident@48..64 "random_page_cost" + Ascii61@64..65 "=" + Iconst@65..67 "42" + Ascii44@67..68 "," + Whitespace@68..69 " " + DefElem@69..84 + Ident@69..82 "seq_page_cost" + Ascii61@82..83 "=" + Iconst@83..84 "3" + Ascii41@84..85 ")" + Ascii59@85..86 ";" + , + errors: [], + stmts: [ + RawStmt { + stmt: CreateTableSpaceStmt( + CreateTableSpaceStmt { + tablespacename: "x", + owner: Some( + RoleSpec { + roletype: RolespecCstring, + rolename: "a", + location: 26, + }, + ), + location: "b", + options: [ + Node { + node: Some( + DefElem( + DefElem { + defnamespace: "", + defname: "random_page_cost", + arg: Some( + Node { + node: Some( + Integer( + Integer { + ival: 42, + }, + ), + ), + }, + ), + defaction: DefelemUnspec, + location: 47, + }, + ), + ), + }, + Node { + node: Some( + DefElem( + DefElem { + defnamespace: "", + defname: "seq_page_cost", + arg: Some( + Node { + node: Some( + Integer( + Integer { + ival: 3, + }, + ), + ), + }, + ), + defaction: DefelemUnspec, + location: 68, + }, + ), + ), + }, + ], + }, + ), + range: 0..85, + }, + ], +} diff --git a/crates/parser/tests/snapshots/statements/valid/0052@1.snap b/crates/parser/tests/snapshots/statements/valid/0052@1.snap new file mode 100644 index 00000000..f028c9b7 --- /dev/null +++ b/crates/parser/tests/snapshots/statements/valid/0052@1.snap @@ -0,0 +1,34 @@ +--- +source: crates/parser/tests/statement_parser_test.rs +description: "CREATE PROCEDURE insert_data(a integer, b integer) LANGUAGE SQL AS $$INSERT INTO tbl VALUES (a); INSERT INTO tbl VALUES (b);$$;" +--- +Parse { + cst: SourceFile@0..127 + Create@0..6 "CREATE" + Whitespace@6..7 " " + Procedure@7..16 "PROCEDURE" + Whitespace@16..17 " " + Ident@17..28 "insert_data" + Ascii40@28..29 "(" + Ident@29..30 "a" + Whitespace@30..31 " " + Integer@31..38 "integer" + Ascii44@38..39 "," + Whitespace@39..40 " " + Ident@40..41 "b" + Whitespace@41..42 " " + Integer@42..49 "integer" + Ascii41@49..50 ")" + Whitespace@50..51 " " + Language@51..59 "LANGUAGE" + Whitespace@59..60 " " + SqlP@60..63 "SQL" + Whitespace@63..64 " " + As@64..66 "AS" + Whitespace@66..67 " " + Sconst@67..126 "$$INSERT INTO tbl VAL ..." + Ascii59@126..127 ";" + , + errors: [], + stmts: [], +} diff --git a/crates/parser/tests/snapshots/statements/valid/0052@2.snap b/crates/parser/tests/snapshots/statements/valid/0052@2.snap new file mode 100644 index 00000000..94171c5c --- /dev/null +++ b/crates/parser/tests/snapshots/statements/valid/0052@2.snap @@ -0,0 +1,248 @@ +--- +source: crates/parser/tests/statement_parser_test.rs +description: "\nCREATE PROCEDURE insert_data(a integer, b integer) LANGUAGE SQL BEGIN ATOMIC INSERT INTO tbl VALUES (a); INSERT INTO tbl VALUES (b); END;" +--- +Parse { + cst: SourceFile@0..135 + Newline@0..1 "\n" + Create@1..7 "CREATE" + Whitespace@7..8 " " + Procedure@8..17 "PROCEDURE" + Whitespace@17..18 " " + Ident@18..29 "insert_data" + Ascii40@29..30 "(" + Ident@30..31 "a" + Whitespace@31..32 " " + Integer@32..39 "integer" + Ascii44@39..40 "," + Whitespace@40..41 " " + Ident@41..42 "b" + Whitespace@42..43 " " + Integer@43..50 "integer" + Ascii41@50..51 ")" + Whitespace@51..52 " " + Language@52..60 "LANGUAGE" + Whitespace@60..61 " " + SqlP@61..64 "SQL" + BeginP@64..69 "BEGIN" + Whitespace@69..70 " " + Atomic@70..76 "ATOMIC" + InsertStmt@76..103 + Insert@76..82 "INSERT" + Whitespace@82..83 " " + Into@83..87 "INTO" + Whitespace@87..88 " " + RangeVar@88..91 + Ident@88..91 "tbl" + Whitespace@91..92 " " + SelectStmt@92..101 + Values@92..98 "VALUES" + Whitespace@98..99 " " + Ascii40@99..100 "(" + List@100..101 + ColumnRef@100..101 + Ident@100..101 "a" + Ascii41@101..102 ")" + Ascii59@102..103 ";" + InsertStmt@103..130 + Insert@103..109 "INSERT" + Whitespace@109..110 " " + Into@110..114 "INTO" + Whitespace@114..115 " " + RangeVar@115..118 + Ident@115..118 "tbl" + Whitespace@118..119 " " + SelectStmt@119..128 + Values@119..125 "VALUES" + Whitespace@125..126 " " + Ascii40@126..127 "(" + List@127..128 + ColumnRef@127..128 + Ident@127..128 "b" + Ascii41@128..129 ")" + Ascii59@129..130 ";" + Whitespace@130..131 " " + EndP@131..134 "END" + Ascii59@134..135 ";" + , + errors: [ + SyntaxError( + "Expected Ascii59, found Whitespace", + 77..77, + ), + SyntaxError( + "Invalid statement: syntax error at or near \"ATOMIC\"", + 21..24, + ), + ], + stmts: [ + RawStmt { + stmt: InsertStmt( + InsertStmt { + relation: Some( + RangeVar { + catalogname: "", + schemaname: "", + relname: "tbl", + inh: true, + relpersistence: "p", + alias: None, + location: 12, + }, + ), + cols: [], + select_stmt: Some( + Node { + node: Some( + SelectStmt( + SelectStmt { + distinct_clause: [], + into_clause: None, + target_list: [], + from_clause: [], + where_clause: None, + group_clause: [], + group_distinct: false, + having_clause: None, + window_clause: [], + values_lists: [ + Node { + node: Some( + List( + List { + items: [ + Node { + node: Some( + ColumnRef( + ColumnRef { + fields: [ + Node { + node: Some( + String( + String { + sval: "a", + }, + ), + ), + }, + ], + location: 24, + }, + ), + ), + }, + ], + }, + ), + ), + }, + ], + sort_clause: [], + limit_offset: None, + limit_count: None, + limit_option: Default, + locking_clause: [], + with_clause: None, + op: SetopNone, + all: false, + larg: None, + rarg: None, + }, + ), + ), + }, + ), + on_conflict_clause: None, + returning_list: [], + with_clause: None, + r#override: OverridingNotSet, + }, + ), + range: 77..105, + }, + RawStmt { + stmt: InsertStmt( + InsertStmt { + relation: Some( + RangeVar { + catalogname: "", + schemaname: "", + relname: "tbl", + inh: true, + relpersistence: "p", + alias: None, + location: 12, + }, + ), + cols: [], + select_stmt: Some( + Node { + node: Some( + SelectStmt( + SelectStmt { + distinct_clause: [], + into_clause: None, + target_list: [], + from_clause: [], + where_clause: None, + group_clause: [], + group_distinct: false, + having_clause: None, + window_clause: [], + values_lists: [ + Node { + node: Some( + List( + List { + items: [ + Node { + node: Some( + ColumnRef( + ColumnRef { + fields: [ + Node { + node: Some( + String( + String { + sval: "b", + }, + ), + ), + }, + ], + location: 24, + }, + ), + ), + }, + ], + }, + ), + ), + }, + ], + sort_clause: [], + limit_offset: None, + limit_count: None, + limit_option: Default, + locking_clause: [], + with_clause: None, + op: SetopNone, + all: false, + larg: None, + rarg: None, + }, + ), + ), + }, + ), + on_conflict_clause: None, + returning_list: [], + with_clause: None, + r#override: OverridingNotSet, + }, + ), + range: 105..133, + }, + ], +}