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

ddl: support multiple table rename #1021

Merged
merged 3 commits into from
Oct 28, 2020
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
15 changes: 0 additions & 15 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,11 +1157,6 @@ func (n *DropSequenceStmt) Accept(v Visitor) (Node, bool) {
type RenameTableStmt struct {
ddlNode

OldTable *TableName
NewTable *TableName

// TableToTables is only useful for syncer which depends heavily on tidb parser to do some dirty work for now.
// TODO: Refactor this when you are going to add full support for multiple schema changes.
TableToTables []*TableToTable
}

Expand All @@ -1186,16 +1181,6 @@ func (n *RenameTableStmt) Accept(v Visitor) (Node, bool) {
return v.Leave(newNode)
}
n = newNode.(*RenameTableStmt)
node, ok := n.OldTable.Accept(v)
if !ok {
return n, false
}
n.OldTable = node.(*TableName)
node, ok = n.NewTable.Accept(v)
if !ok {
return n, false
}
n.NewTable = node.(*TableName)

for i, t := range n.TableToTables {
node, ok := t.Accept(v)
Expand Down
2 changes: 1 addition & 1 deletion ast/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (ts *testDDLSuite) TestDDLVisitorCover(c *C) {
{&DropDatabaseStmt{}, 0, 0},
{&DropIndexStmt{Table: &TableName{}}, 0, 0},
{&DropTableStmt{Tables: []*TableName{{}, {}}}, 0, 0},
{&RenameTableStmt{OldTable: &TableName{}, NewTable: &TableName{}}, 0, 0},
{&RenameTableStmt{TableToTables: []*TableToTable{}}, 0, 0},
{&TruncateTableStmt{Table: &TableName{}}, 0, 0},

// TODO: cover children
Expand Down
1 change: 1 addition & 0 deletions model/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const (
ActionDropCheckConstraint ActionType = 44
ActionAlterCheckConstraint ActionType = 45
ActionAlterTableAlterPartition ActionType = 46
ActionRenameTables ActionType = 47
)

const (
Expand Down
2 changes: 0 additions & 2 deletions parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -2189,15 +2189,14 @@ Symbol:
/**************************************RenameTableStmt***************************************
* See http://dev.mysql.com/doc/refman/5.7/en/rename-table.html
*
* TODO: refactor this when you are going to add full support for multiple schema changes.
* Currently it is only useful for syncer which depends heavily on tidb parser to do some dirty work.
* RENAME TABLE
* tbl_name TO new_tbl_name
* [, tbl_name2 TO new_tbl_name2] ...
*******************************************************************************************/
RenameTableStmt:
"RENAME" "TABLE" TableToTableList
{
$$ = &ast.RenameTableStmt{
OldTable: $3.([]*ast.TableToTable)[0].OldTable,
NewTable: $3.([]*ast.TableToTable)[0].NewTable,
TableToTables: $3.([]*ast.TableToTable),
}
}
Expand Down