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: support "create view" with relpersistence #65

Merged
merged 1 commit into from
Dec 13, 2023
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
11 changes: 11 additions & 0 deletions crates/codegen/src/get_node_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,17 @@ fn custom_handlers(node: &Node) -> TokenStream {
tokens.push(TokenProperty::from(Token::Or));
tokens.push(TokenProperty::from(Token::Replace));
}
if let Some(n) = &n.view {
match n.relpersistence.as_str() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I would expect Temporary token to be part of RangeVar node but parser still panics so I had to make it part of ViewStmt, very similar to what we had with the As token being part of CreateDomainStmt in #61

cc @psteinroe

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats an interesting case! I agree with your reasoning. to give a bit of context. Take the substring create temporary view comedies as an example. The create and the view token should be part of the ViewStmt itself, while the temporary is definitely part of the RangeVar node. We cannot create a valid tree out of this, since we would have to open RangeVar at temporary, close it to go back to ViewStmt and then open it again to be back at RangeVar for comedies. So yes, we should pull temporary back up into ViewStmt. thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it makes sense, thanks for the clarification

// Permanent
"p" => {},
// Unlogged
"u" => tokens.push(TokenProperty::from(Token::Unlogged)),
// Temporary
"t" => tokens.push(TokenProperty::from(Token::Temporary)),
_ => panic!("Unknown ViewStmt {:#?}", n),
}
}
},
"CreateStmt" => quote! {
tokens.push(TokenProperty::from(Token::Create));
Expand Down
16 changes: 16 additions & 0 deletions crates/parser/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,20 @@ mod tests {
],
)
}

#[test]
fn test_create_view() {
test_get_node_properties(
"create or replace temporary view comedies as select * from films;",
SyntaxKind::ViewStmt,
vec![
TokenProperty::from(SyntaxKind::Create),
TokenProperty::from(SyntaxKind::View),
TokenProperty::from(SyntaxKind::As),
TokenProperty::from(SyntaxKind::Or),
TokenProperty::from(SyntaxKind::Replace),
TokenProperty::from(SyntaxKind::Temporary),
],
)
}
}