Skip to content

Commit c39bbee

Browse files
authored
Merge pull request #89 from cvng/create-tablespace
2 parents 7e58c4d + c2fc1b4 commit c39bbee

File tree

7 files changed

+452
-0
lines changed

7 files changed

+452
-0
lines changed

Diff for: crates/codegen/src/get_node_properties.rs

+11
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,17 @@ fn custom_handlers(node: &Node) -> TokenStream {
668668
_ => panic!("Unknown IndexElem {:#?}", n.nulls_ordering()),
669669
}
670670
},
671+
"CreateTableSpaceStmt" => quote! {
672+
tokens.push(TokenProperty::from(Token::Create));
673+
tokens.push(TokenProperty::from(Token::Tablespace));
674+
tokens.push(TokenProperty::from(Token::Location));
675+
if n.owner.is_some() {
676+
tokens.push(TokenProperty::from(Token::Owner));
677+
}
678+
if n.options.len() > 0 {
679+
tokens.push(TokenProperty::from(Token::With));
680+
}
681+
},
671682
_ => quote! {},
672683
}
673684
}

Diff for: crates/parser/src/codegen.rs

+17
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,21 @@ mod tests {
239239
],
240240
)
241241
}
242+
243+
#[test]
244+
fn test_create_tablespace() {
245+
test_get_node_properties(
246+
"create tablespace x owner a location 'b' with (seq_page_cost=3);",
247+
SyntaxKind::CreateTableSpaceStmt,
248+
vec![
249+
TokenProperty::from(SyntaxKind::Create),
250+
TokenProperty::from(SyntaxKind::Tablespace),
251+
TokenProperty::from(SyntaxKind::Location),
252+
TokenProperty::from(SyntaxKind::Owner),
253+
TokenProperty::from(SyntaxKind::With),
254+
TokenProperty::from("x".to_string()),
255+
TokenProperty::from("b".to_string()),
256+
],
257+
)
258+
}
242259
}

Diff for: crates/parser/tests/data/statements/valid/0048.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE TABLESPACE x LOCATION 'a';
2+
CREATE TABLESPACE x OWNER a LOCATION 'b' WITH (random_page_cost=42, seq_page_cost=3);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
source: crates/parser/tests/statement_parser_test.rs
3+
description: "CREATE TABLESPACE x LOCATION 'a';"
4+
---
5+
Parse {
6+
cst: SourceFile@0..33
7+
CreateTableSpaceStmt@0..33
8+
Create@0..6 "CREATE"
9+
Whitespace@6..7 " "
10+
Tablespace@7..17 "TABLESPACE"
11+
Whitespace@17..18 " "
12+
Ident@18..19 "x"
13+
Whitespace@19..20 " "
14+
Location@20..28 "LOCATION"
15+
Whitespace@28..29 " "
16+
Sconst@29..32 "'a'"
17+
Ascii59@32..33 ";"
18+
,
19+
errors: [],
20+
stmts: [
21+
RawStmt {
22+
stmt: CreateTableSpaceStmt(
23+
CreateTableSpaceStmt {
24+
tablespacename: "x",
25+
owner: None,
26+
location: "a",
27+
options: [],
28+
},
29+
),
30+
range: 0..32,
31+
},
32+
],
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
source: crates/parser/tests/statement_parser_test.rs
3+
description: "\nCREATE TABLESPACE x OWNER a LOCATION 'b' WITH (random_page_cost=42, seq_page_cost=3);"
4+
---
5+
Parse {
6+
cst: SourceFile@0..86
7+
Newline@0..1 "\n"
8+
CreateTableSpaceStmt@1..86
9+
Create@1..7 "CREATE"
10+
Whitespace@7..8 " "
11+
Tablespace@8..18 "TABLESPACE"
12+
Whitespace@18..19 " "
13+
Ident@19..20 "x"
14+
Whitespace@20..21 " "
15+
Owner@21..26 "OWNER"
16+
Whitespace@26..27 " "
17+
RoleSpec@27..28
18+
Ident@27..28 "a"
19+
Whitespace@28..29 " "
20+
Location@29..37 "LOCATION"
21+
Whitespace@37..38 " "
22+
Sconst@38..41 "'b'"
23+
Whitespace@41..42 " "
24+
With@42..46 "WITH"
25+
Whitespace@46..47 " "
26+
Ascii40@47..48 "("
27+
DefElem@48..67
28+
Ident@48..64 "random_page_cost"
29+
Ascii61@64..65 "="
30+
Iconst@65..67 "42"
31+
Ascii44@67..68 ","
32+
Whitespace@68..69 " "
33+
DefElem@69..84
34+
Ident@69..82 "seq_page_cost"
35+
Ascii61@82..83 "="
36+
Iconst@83..84 "3"
37+
Ascii41@84..85 ")"
38+
Ascii59@85..86 ";"
39+
,
40+
errors: [],
41+
stmts: [
42+
RawStmt {
43+
stmt: CreateTableSpaceStmt(
44+
CreateTableSpaceStmt {
45+
tablespacename: "x",
46+
owner: Some(
47+
RoleSpec {
48+
roletype: RolespecCstring,
49+
rolename: "a",
50+
location: 26,
51+
},
52+
),
53+
location: "b",
54+
options: [
55+
Node {
56+
node: Some(
57+
DefElem(
58+
DefElem {
59+
defnamespace: "",
60+
defname: "random_page_cost",
61+
arg: Some(
62+
Node {
63+
node: Some(
64+
Integer(
65+
Integer {
66+
ival: 42,
67+
},
68+
),
69+
),
70+
},
71+
),
72+
defaction: DefelemUnspec,
73+
location: 47,
74+
},
75+
),
76+
),
77+
},
78+
Node {
79+
node: Some(
80+
DefElem(
81+
DefElem {
82+
defnamespace: "",
83+
defname: "seq_page_cost",
84+
arg: Some(
85+
Node {
86+
node: Some(
87+
Integer(
88+
Integer {
89+
ival: 3,
90+
},
91+
),
92+
),
93+
},
94+
),
95+
defaction: DefelemUnspec,
96+
location: 68,
97+
},
98+
),
99+
),
100+
},
101+
],
102+
},
103+
),
104+
range: 0..85,
105+
},
106+
],
107+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
source: crates/parser/tests/statement_parser_test.rs
3+
description: "CREATE PROCEDURE insert_data(a integer, b integer) LANGUAGE SQL AS $$INSERT INTO tbl VALUES (a); INSERT INTO tbl VALUES (b);$$;"
4+
---
5+
Parse {
6+
cst: SourceFile@0..127
7+
Create@0..6 "CREATE"
8+
Whitespace@6..7 " "
9+
Procedure@7..16 "PROCEDURE"
10+
Whitespace@16..17 " "
11+
Ident@17..28 "insert_data"
12+
Ascii40@28..29 "("
13+
Ident@29..30 "a"
14+
Whitespace@30..31 " "
15+
Integer@31..38 "integer"
16+
Ascii44@38..39 ","
17+
Whitespace@39..40 " "
18+
Ident@40..41 "b"
19+
Whitespace@41..42 " "
20+
Integer@42..49 "integer"
21+
Ascii41@49..50 ")"
22+
Whitespace@50..51 " "
23+
Language@51..59 "LANGUAGE"
24+
Whitespace@59..60 " "
25+
SqlP@60..63 "SQL"
26+
Whitespace@63..64 " "
27+
As@64..66 "AS"
28+
Whitespace@66..67 " "
29+
Sconst@67..126 "$$INSERT INTO tbl VAL ..."
30+
Ascii59@126..127 ";"
31+
,
32+
errors: [],
33+
stmts: [],
34+
}

0 commit comments

Comments
 (0)