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

parser : support admin repair table syntax #547

Merged
merged 4 commits into from
Oct 21, 2019
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
41 changes: 41 additions & 0 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
_ DDLNode = &DropTableStmt{}
_ DDLNode = &RenameTableStmt{}
_ DDLNode = &TruncateTableStmt{}
_ DDLNode = &RepairTableStmt{}

_ Node = &AlterTableSpec{}
_ Node = &ColumnDef{}
Expand Down Expand Up @@ -1559,6 +1560,46 @@ func (n *CleanupTableLockStmt) Restore(ctx *RestoreCtx) error {
return nil
}

// RepairTableStmt is a statement to repair tableInfo.
type RepairTableStmt struct {
ddlNode
Table *TableName
CreateStmt *CreateTableStmt
}

// Accept implements Node Accept interface.
func (n *RepairTableStmt) Accept(v Visitor) (Node, bool) {
newNode, skipChildren := v.Enter(n)
if skipChildren {
return v.Leave(newNode)
}
n = newNode.(*RepairTableStmt)
node, ok := n.Table.Accept(v)
if !ok {
return n, false
}
n.Table = node.(*TableName)
node, ok = n.CreateStmt.Accept(v)
if !ok {
return n, false
}
n.CreateStmt = node.(*CreateTableStmt)
return v.Leave(n)
}

// Restore implements Node interface.
func (n *RepairTableStmt) Restore(ctx *RestoreCtx) error {
ctx.WriteKeyWord("ADMIN REPAIR TABLE ")
if err := n.Table.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore RepairTableStmt.table : [%v]", n.Table)
}
ctx.WritePlain(" ")
if err := n.CreateStmt.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore RepairTableStmt.createStmt : [%v]", n.CreateStmt)
}
return nil
}

// TableOptionType is the type for TableOption
type TableOptionType int

Expand Down
12 changes: 12 additions & 0 deletions ast/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,15 @@ func (ts *testDDLSuite) TestAlterTableSpecRestore(c *C) {
}
RunNodeRestoreTest(c, testCases, "ALTER TABLE t %s", extractNodeFunc)
}

func (ts *testDDLSuite) TestAdminRepairTableRestore(c *C) {
testCases := []NodeRestoreTestCase{
{"ADMIN REPAIR TABLE t CREATE TABLE t (a int)", "ADMIN REPAIR TABLE `t` CREATE TABLE `t` (`a` INT)"},
{"ADMIN REPAIR TABLE t CREATE TABLE t (a char(1), b int)", "ADMIN REPAIR TABLE `t` CREATE TABLE `t` (`a` CHAR(1),`b` INT)"},
{"ADMIN REPAIR TABLE t CREATE TABLE t (a TINYINT UNSIGNED)", "ADMIN REPAIR TABLE `t` CREATE TABLE `t` (`a` TINYINT UNSIGNED)"},
}
extractNodeFunc := func(node Node) Node {
return node
}
RunNodeRestoreTest(c, testCases, "%s", extractNodeFunc)
}
2 changes: 2 additions & 0 deletions model/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
ActionModifySchemaCharsetAndCollate ActionType = 26
ActionLockTable ActionType = 27
ActionUnlockTable ActionType = 28
ActionRepairTable ActionType = 29
)

// AddIndexStr is a string related to the operation of "add index".
Expand Down Expand Up @@ -92,6 +93,7 @@ var actionMap = map[ActionType]string{
ActionModifySchemaCharsetAndCollate: "modify schema charset and collate",
ActionLockTable: "lock table",
ActionUnlockTable: "unlock table",
ActionRepairTable: "repair table",
}

// String return current ddl action in string
Expand Down
Loading