Skip to content

Commit c3227e2

Browse files
authored
fix(parse): create partition of table schema (#146)
related #145
1 parent 03b1912 commit c3227e2

File tree

3 files changed

+132
-1
lines changed

3 files changed

+132
-1
lines changed

parser/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ pub struct CreateStmt {
729729
/// relation to create
730730
pub relation: RelationKind,
731731
/// column definitions (list of ColumnDef)
732-
#[serde(rename = "tableElts")]
732+
#[serde(rename = "tableElts", default)]
733733
pub table_elts: Vec<TableElt>,
734734
/// relations to inherit from (list of inhRelation)
735735
#[serde(rename = "inhRelations")]

parser/src/parse.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,16 @@ CREATE TABLE example (
12241224
c integer,
12251225
PRIMARY KEY (a, c)
12261226
);
1227+
"#;
1228+
let res = parse_sql_query(sql);
1229+
assert_debug_snapshot!(res);
1230+
}
1231+
1232+
#[test]
1233+
fn test_parse_create_table_partition() {
1234+
let sql = r#"
1235+
CREATE TABLE measurement_y2006m02 PARTITION OF measurement
1236+
FOR VALUES FROM ('2006-02-01') TO ('2006-03-01');
12271237
"#;
12281238
let res = parse_sql_query(sql);
12291239
assert_debug_snapshot!(res);
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
source: parser/src/parse.rs
3+
expression: res
4+
---
5+
Ok(
6+
[
7+
RawStmt(
8+
RawStmt {
9+
stmt: CreateStmt(
10+
CreateStmt {
11+
relation: RangeVar(
12+
RangeVar {
13+
catalogname: None,
14+
schemaname: None,
15+
relname: "measurement_y2006m02",
16+
inh: true,
17+
relpersistence: "p",
18+
alias: None,
19+
location: 14,
20+
},
21+
),
22+
table_elts: [],
23+
inh_relations: [
24+
Object({
25+
"RangeVar": Object({
26+
"inh": Bool(
27+
true,
28+
),
29+
"location": Number(
30+
48,
31+
),
32+
"relname": String(
33+
"measurement",
34+
),
35+
"relpersistence": String(
36+
"p",
37+
),
38+
}),
39+
}),
40+
],
41+
partbound: Some(
42+
Object({
43+
"PartitionBoundSpec": Object({
44+
"location": Number(
45+
75,
46+
),
47+
"lowerdatums": Array([
48+
Object({
49+
"PartitionRangeDatum": Object({
50+
"kind": Number(
51+
0,
52+
),
53+
"location": Number(
54+
81,
55+
),
56+
"value": Object({
57+
"A_Const": Object({
58+
"location": Number(
59+
81,
60+
),
61+
"val": Object({
62+
"String": Object({
63+
"str": String(
64+
"2006-02-01",
65+
),
66+
}),
67+
}),
68+
}),
69+
}),
70+
}),
71+
}),
72+
]),
73+
"strategy": String(
74+
"r",
75+
),
76+
"upperdatums": Array([
77+
Object({
78+
"PartitionRangeDatum": Object({
79+
"kind": Number(
80+
0,
81+
),
82+
"location": Number(
83+
99,
84+
),
85+
"value": Object({
86+
"A_Const": Object({
87+
"location": Number(
88+
99,
89+
),
90+
"val": Object({
91+
"String": Object({
92+
"str": String(
93+
"2006-03-01",
94+
),
95+
}),
96+
}),
97+
}),
98+
}),
99+
}),
100+
}),
101+
]),
102+
}),
103+
}),
104+
),
105+
partspec: None,
106+
of_typename: None,
107+
constraints: [],
108+
options: [],
109+
oncommit: Noop,
110+
tablespacename: None,
111+
if_not_exists: false,
112+
},
113+
),
114+
stmt_location: 0,
115+
stmt_len: Some(
116+
112,
117+
),
118+
},
119+
),
120+
],
121+
)

0 commit comments

Comments
 (0)