Skip to content

Commit

Permalink
Feat(parser): add show create view sql parser. (#162)
Browse files Browse the repository at this point in the history
Signed-off-by: Zonglei Dong <[email protected]>
  • Loading branch information
dongzl authored Jul 4, 2022
1 parent 78fafd7 commit f67687b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pisa-proxy/parser/mysql/src/ast/dml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3139,3 +3139,9 @@ pub enum ShowVariableType {
Global,
Session,
}

#[derive(Debug, Clone)]
pub struct ShowCreateViewStmt {
pub span: Span,
pub view_name: String,
}
1 change: 1 addition & 0 deletions pisa-proxy/parser/mysql/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub enum SqlStmt {
ShowCreateTableStmt(Box<ShowCreateTableStmt>),
ShowKeysStmt(Box<ShowKeysStmt>),
ShowVariablesStmt(Box<ShowVariablesStmt>),
ShowCreateViewStmt(Box<ShowCreateViewStmt>),
Start(Start),
Commit(Commit),
Rollback(Rollback),
Expand Down
11 changes: 11 additions & 0 deletions pisa-proxy/parser/mysql/src/grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ sql_stmt -> SqlStmt:
| show_create_table_stmt { SqlStmt::ShowCreateTableStmt($1) }
| show_keys_stmt { SqlStmt::ShowKeysStmt($1) }
| show_variables_stmt { SqlStmt::ShowVariablesStmt($1) }
| show_create_view_stmt { SqlStmt::ShowCreateViewStmt($1) }
| start { SqlStmt::Start($1) }
| create { SqlStmt::Create($1) }

Expand Down Expand Up @@ -6033,6 +6034,16 @@ opt_var_type -> Option<ShowVariableType>:
| SESSION { Some(ShowVariableType::Session) }
;
show_create_view_stmt -> Box<ShowCreateViewStmt>:
'SHOW' 'CREATE' 'VIEW' table_ident
{
Box::new(ShowCreateViewStmt {
span: $span,
view_name: $4,
})
}
;
start -> Start:
START TRANSACTION opt_start_transaction_option_list
{
Expand Down
1 change: 1 addition & 0 deletions pisa-proxy/parser/mysql/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ mod test {
"SHOW VARIABLES LIKE '%size%';",
"SHOW GLOBAL VARIABLES LIKE '%size%';",
"SHOW SESSION VARIABLES LIKE '%size%';",
"SHOW CREATE VIEW view_name;",
];

let p = Parser::new();
Expand Down

0 comments on commit f67687b

Please sign in to comment.