Skip to content

Commit

Permalink
*: add flashback table syntax (pingcap#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored Dec 3, 2019
1 parent 7910dab commit 884ad42
Show file tree
Hide file tree
Showing 4 changed files with 8,114 additions and 7,975 deletions.
44 changes: 44 additions & 0 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3173,3 +3173,47 @@ func (n *RecoverTableStmt) Accept(v Visitor) (Node, bool) {
}
return v.Leave(n)
}

// FlashBackTableStmt is a statement to restore a dropped/truncate table.
type FlashBackTableStmt struct {
ddlNode

Table *TableName
Timestamp ValueExpr
NewName string
}

// Restore implements Node interface.
func (n *FlashBackTableStmt) Restore(ctx *RestoreCtx) error {
ctx.WriteKeyWord("FLASHBACK TABLE ")
if err := n.Table.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while splicing RecoverTableStmt Table")
}
ctx.WriteKeyWord(" UNTIL TIMESTAMP ")
if err := n.Timestamp.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while splicing FlashBackTableStmt Table")
}
if len(n.NewName) > 0 {
ctx.WriteKeyWord(" TO ")
ctx.WriteName(n.NewName)
}
return nil
}

// Accept implements Node Accept interface.
func (n *FlashBackTableStmt) Accept(v Visitor) (Node, bool) {
newNode, skipChildren := v.Enter(n)
if skipChildren {
return v.Leave(newNode)
}

n = newNode.(*FlashBackTableStmt)
if n.Table != nil {
node, ok := n.Table.Accept(v)
if !ok {
return n, false
}
n.Table = node.(*TableName)
}
return v.Leave(n)
}
2 changes: 2 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ var tokenMap = map[string]int{
"FIXED": fixed,
"FLOAT": floatType,
"FLUSH": flush,
"FLASHBACK": flashback,
"FOLLOWING": following,
"FOR": forKwd,
"FORCE": force,
Expand Down Expand Up @@ -642,6 +643,7 @@ var tokenMap = map[string]int{
"UNKNOWN": unknown,
"UNLOCK": unlock,
"UNSIGNED": unsigned,
"UNTIL": until,
"UPDATE": update,
"USAGE": usage,
"USE": use,
Expand Down
Loading

0 comments on commit 884ad42

Please sign in to comment.