Skip to content

Commit

Permalink
Feat(parser): support show create table sql parser. (#150)
Browse files Browse the repository at this point in the history
* Feat(parser): support show create table sql parser.
Signed-off-by: Zonglei Dong <dongzonglei@apache.org>

* Feat(parser): add show create table sql parser test case.
Signed-off-by: Zonglei Dong <dongzonglei@apache.org>
  • Loading branch information
dongzl committed Jun 29, 2022
1 parent 1625094 commit f550827
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 @@ -3103,3 +3103,9 @@ pub struct ShowTableDb {
pub from_or_in: FromOrIn,
pub db: String,
}

#[derive(Debug, Clone)]
pub struct ShowCreateTable {
pub span: Span,
pub table: 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 @@ -42,6 +42,7 @@ pub enum SqlStmt {
ShowDatabasesStmt(Box<ShowDatabasesStmt>),
ShowTablesStmt(Box<ShowTablesStmt>),
ShowColumnsStmt(Box<ShowColumnsStmt>),
ShowCreateTable(Box<ShowCreateTable>),
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 @@ -108,6 +108,7 @@ sql_stmt -> SqlStmt:
| show_databases_stmt { SqlStmt::ShowDatabasesStmt($1) }
| show_tables_stmt { SqlStmt::ShowTablesStmt($1) }
| show_columns_stmt { SqlStmt::ShowColumnsStmt($1) }
| show_create_table_stmt { SqlStmt::ShowCreateTable($1) }
| start { SqlStmt::Start($1) }
| create { SqlStmt::Create($1) }

Expand Down Expand Up @@ -5977,6 +5978,16 @@ from_or_in -> FromOrIn:
| 'IN' { FromOrIn::In }
;
show_create_table_stmt -> Box<ShowCreateTable>:
'SHOW' 'CREATE' 'TABLE' table_ident
{
Box::new(ShowCreateTable {
span: $span,
table: $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 @@ -128,6 +128,7 @@ mod test {
"select * from test.test limit 1",
"select * from test.1test limit 1",
"SHOW COLUMNS FROM t_order;",
"SHOW CREATE TABLE t_order;",
];

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

0 comments on commit f550827

Please sign in to comment.