-
Notifications
You must be signed in to change notification settings - Fork 98
fix: location and add support for create publication #94
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -692,6 +692,74 @@ fn custom_handlers(node: &Node) -> TokenStream { | |
tokens.push(TokenProperty::from(Token::With)); | ||
} | ||
}, | ||
"CreatePublicationStmt" => quote! { | ||
tokens.push(TokenProperty::from(Token::Create)); | ||
tokens.push(TokenProperty::from(Token::Publication)); | ||
if n.for_all_tables { | ||
tokens.push(TokenProperty::from(Token::For)); | ||
tokens.push(TokenProperty::from(Token::All)); | ||
tokens.push(TokenProperty::from(Token::Tables)); | ||
} | ||
if let Some(n) = n.options.first() { | ||
tokens.push(TokenProperty::from(Token::With)); | ||
} | ||
if let Some(n) = n.pubobjects.first() { | ||
tokens.push(TokenProperty::from(Token::For)); | ||
if let Some(NodeEnum::PublicationObjSpec(n)) = &n.node { | ||
match n.pubobjtype() { | ||
protobuf::PublicationObjSpecType::PublicationobjTable => { | ||
tokens.push(TokenProperty::from(Token::Table)); | ||
}, | ||
protobuf::PublicationObjSpecType::PublicationobjTablesInSchema => { | ||
tokens.push(TokenProperty::from(Token::Tables)); | ||
tokens.push(TokenProperty::from(Token::InP)); | ||
tokens.push(TokenProperty::from(Token::Schema)); | ||
}, | ||
_ => panic!("Unknown CreatePublicationStmt {:#?}", n.pubobjtype()) | ||
} | ||
} | ||
} | ||
if let Some(n) = n.pubobjects.last() { | ||
if let Some(NodeEnum::PublicationObjSpec(n)) = &n.node { | ||
match n.pubobjtype() { | ||
protobuf::PublicationObjSpecType::PublicationobjTablesInSchema => { | ||
tokens.push(TokenProperty::from(Token::Tables)); | ||
tokens.push(TokenProperty::from(Token::InP)); | ||
tokens.push(TokenProperty::from(Token::Schema)); | ||
}, | ||
_ => {} | ||
} | ||
} | ||
Comment on lines
+706
to
+732
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be implemented safer. we should do .find() for all types and add the respective tokens if at least one can be found. feel free to fix this @cvng There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, let's have this in a next PR with a |
||
} | ||
}, | ||
"PublicationTable" => quote! { | ||
if n.where_clause.is_some() { | ||
tokens.push(TokenProperty::from(Token::Where)); | ||
} | ||
}, | ||
"BooleanTest" => quote! { | ||
match n.booltesttype() { | ||
protobuf::BoolTestType::IsTrue => { | ||
tokens.push(TokenProperty::from(Token::Is)); | ||
tokens.push(TokenProperty::from(Token::TrueP)); | ||
}, | ||
protobuf::BoolTestType::IsNotTrue => { | ||
tokens.push(TokenProperty::from(Token::Is)); | ||
tokens.push(TokenProperty::from(Token::Not)); | ||
tokens.push(TokenProperty::from(Token::TrueP)); | ||
}, | ||
protobuf::BoolTestType::IsFalse => { | ||
tokens.push(TokenProperty::from(Token::Is)); | ||
tokens.push(TokenProperty::from(Token::FalseP)); | ||
}, | ||
protobuf::BoolTestType::IsNotFalse => { | ||
tokens.push(TokenProperty::from(Token::Is)); | ||
tokens.push(TokenProperty::from(Token::Not)); | ||
tokens.push(TokenProperty::from(Token::FalseP)); | ||
}, | ||
_ => panic!("Unknown BooleanTest {:#?}", n.booltesttype()), | ||
} | ||
}, | ||
"CompositeTypeStmt" => quote! { | ||
tokens.push(TokenProperty::from(Token::Create)); | ||
tokens.push(TokenProperty::from(Token::TypeP)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE PUBLICATION mypublication FOR TABLE users, departments; | ||
CREATE PUBLICATION active_departments FOR TABLE departments WHERE (active IS TRUE); | ||
CREATE PUBLICATION alltables FOR ALL TABLES; | ||
CREATE PUBLICATION insert_only FOR TABLE mydata WITH (publish = 'insert'); | ||
CREATE PUBLICATION production_publication FOR TABLE users, departments, TABLES IN SCHEMA production; | ||
CREATE PUBLICATION sales_publication FOR TABLES IN SCHEMA marketing, sales; | ||
CREATE PUBLICATION users_filtered FOR TABLE users (user_id, firstname); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
--- | ||
source: crates/parser/tests/statement_parser_test.rs | ||
description: "CREATE PUBLICATION mypublication FOR TABLE users, departments;" | ||
--- | ||
Parse { | ||
cst: [email protected] | ||
[email protected] | ||
[email protected] "CREATE" | ||
[email protected] " " | ||
[email protected] "PUBLICATION" | ||
[email protected] " " | ||
[email protected] "mypublication" | ||
[email protected] " " | ||
[email protected] "FOR" | ||
[email protected] " " | ||
[email protected] "TABLE" | ||
[email protected] " " | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] "users" | ||
[email protected] "," | ||
[email protected] " " | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] "departments" | ||
[email protected] ";" | ||
, | ||
errors: [], | ||
stmts: [ | ||
RawStmt { | ||
stmt: CreatePublicationStmt( | ||
CreatePublicationStmt { | ||
pubname: "mypublication", | ||
options: [], | ||
pubobjects: [ | ||
Node { | ||
node: Some( | ||
PublicationObjSpec( | ||
PublicationObjSpec { | ||
pubobjtype: PublicationobjTable, | ||
name: "", | ||
pubtable: Some( | ||
PublicationTable { | ||
relation: Some( | ||
RangeVar { | ||
catalogname: "", | ||
schemaname: "", | ||
relname: "users", | ||
inh: true, | ||
relpersistence: "p", | ||
alias: None, | ||
location: 43, | ||
}, | ||
), | ||
where_clause: None, | ||
columns: [], | ||
}, | ||
), | ||
location: 0, | ||
}, | ||
), | ||
), | ||
}, | ||
Node { | ||
node: Some( | ||
PublicationObjSpec( | ||
PublicationObjSpec { | ||
pubobjtype: PublicationobjTable, | ||
name: "", | ||
pubtable: Some( | ||
PublicationTable { | ||
relation: Some( | ||
RangeVar { | ||
catalogname: "", | ||
schemaname: "", | ||
relname: "departments", | ||
inh: true, | ||
relpersistence: "p", | ||
alias: None, | ||
location: 50, | ||
}, | ||
), | ||
where_clause: None, | ||
columns: [], | ||
}, | ||
), | ||
location: 50, | ||
}, | ||
), | ||
), | ||
}, | ||
], | ||
for_all_tables: false, | ||
}, | ||
), | ||
range: 0..61, | ||
}, | ||
], | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cvng fixed location here