Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extend support for table commit opts #105

Merged
merged 3 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/codegen/src/get_node_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,12 @@ fn custom_handlers(node: &Node) -> TokenStream {
tokens.push(TokenProperty::from(Token::All));
}
},
"TransactionStmt" => quote! {
match n.kind() {
protobuf::TransactionStmtKind::TransStmtCommit => tokens.push(TokenProperty::from(Token::Commit)),
_ => panic!("Unknown TransactionStmt {:#?}", n.kind())
}
},
"PartitionBoundSpec" => quote! {
tokens.push(TokenProperty::from(Token::From));
tokens.push(TokenProperty::from(Token::To));
Expand Down
2 changes: 1 addition & 1 deletion crates/parser/tests/data/statements/valid/0043.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ CREATE TABLE tablename (colname int NOT NULL DEFAULT nextval('tablename_colname_
CREATE TABLE capitals (state char(2)) INHERITS (cities);
/* TODO: CREATE TEMPORARY TABLE temp AS SELECT c FROM t; */ SELECT 1;
/* TODO: CREATE TABLE films2 AS SELECT * FROM films; */ SELECT 1;
/* TODO: CREATE TEMPORARY TABLE films_recent ON COMMIT DROP AS SELECT * FROM films WHERE date_prod > $1; */ SELECT 1;
CREATE TEMPORARY TABLE films_recent ON COMMIT DROP AS SELECT * FROM films WHERE date_prod > $1;
CREATE TABLE like_constraint_rename_cache (LIKE constraint_rename_cache INCLUDING ALL);
CREATE TABLE distributors (did int, name varchar(40), UNIQUE (name) WITH (fillfactor=70)) WITH (fillfactor=70);
124 changes: 59 additions & 65 deletions crates/parser/tests/snapshots/statements/valid/0043@9.snap
Original file line number Diff line number Diff line change
@@ -1,77 +1,71 @@
---
source: crates/parser/tests/statement_parser_test.rs
description: "/* TODO: CREATE TEMPORARY TABLE films_recent ON COMMIT DROP AS SELECT * FROM films WHERE date_prod > $1; */ SELECT 1;"
description: CREATE TEMPORARY TABLE films_recent ON COMMIT DROP AS SELECT * FROM films WHERE date_prod > $1;
---
Parse {
cst: SourceFile@0..116
CComment@0..107 "/* TODO: CREATE TEMPO ..."
SelectStmt@107..116
Select@107..113 "SELECT"
Whitespace@113..114 " "
ResTarget@114..115
AConst@114..115
Iconst@114..115 "1"
Ascii59@115..116 ";"
cst: SourceFile@0..93
Create@0..6 "CREATE"
Whitespace@6..7 " "
Temporary@7..16 "TEMPORARY"
Whitespace@16..17 " "
Table@17..22 "TABLE"
Whitespace@22..23 " "
Ident@23..35 "films_recent"
Whitespace@35..36 " "
On@36..38 "ON"
TransactionStmt@38..44
Commit@38..44 "COMMIT"
Drop@44..48 "DROP"
Whitespace@48..49 " "
As@49..51 "AS"
Whitespace@51..52 " "
Select@52..58 "SELECT"
Whitespace@58..59 " "
Ascii42@59..60 "*"
Whitespace@60..61 " "
From@61..65 "FROM"
Whitespace@65..66 " "
Ident@66..71 "films"
Whitespace@71..72 " "
Where@72..77 "WHERE"
Whitespace@77..78 " "
Ident@78..87 "date_prod"
Whitespace@87..88 " "
Ascii62@88..89 ">"
Whitespace@89..90 " "
Param@90..92 "$1"
Ascii59@92..93 ";"
,
errors: [],
errors: [
SyntaxError(
"Expected Ascii59, found Whitespace",
38..38,
),
SyntaxError(
"Invalid statement: syntax error at end of input",
0..9,
),
SyntaxError(
"Expected Ascii59, found Whitespace",
45..45,
),
SyntaxError(
"Invalid statement: syntax error at or near \"AS\"",
12..32,
),
],
stmts: [
RawStmt {
stmt: SelectStmt(
SelectStmt {
distinct_clause: [],
into_clause: None,
target_list: [
Node {
node: Some(
ResTarget(
ResTarget {
name: "",
indirection: [],
val: Some(
Node {
node: Some(
AConst(
AConst {
isnull: false,
location: 7,
val: Some(
Ival(
Integer {
ival: 1,
},
),
),
},
),
),
},
),
location: 7,
},
),
),
},
],
from_clause: [],
where_clause: None,
group_clause: [],
group_distinct: false,
having_clause: None,
window_clause: [],
values_lists: [],
sort_clause: [],
limit_offset: None,
limit_count: None,
limit_option: Default,
locking_clause: [],
with_clause: None,
op: SetopNone,
all: false,
larg: None,
rarg: None,
stmt: TransactionStmt(
TransactionStmt {
kind: TransStmtCommit,
options: [],
savepoint_name: "",
gid: "",
chain: false,
},
),
range: 107..116,
range: 38..45,
},
],
}