Skip to content

Commit

Permalink
*: Add split index region syntax support. (pingcap#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored May 6, 2019
1 parent 8eed790 commit 6528a83
Show file tree
Hide file tree
Showing 5 changed files with 6,351 additions and 6,237 deletions.
59 changes: 59 additions & 0 deletions ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
_ DMLNode = &SelectStmt{}
_ DMLNode = &ShowStmt{}
_ DMLNode = &LoadDataStmt{}
_ DMLNode = &SplitIndexRegionStmt{}

_ Node = &Assignment{}
_ Node = &ByItem{}
Expand Down Expand Up @@ -2396,3 +2397,61 @@ func (n *FrameBound) Accept(v Visitor) (Node, bool) {
}
return v.Leave(n)
}

type SplitIndexRegionStmt struct {
dmlNode

Table *TableName
IndexName string
ValueLists [][]ExprNode
}

func (n *SplitIndexRegionStmt) Restore(ctx *RestoreCtx) error {
ctx.WriteKeyWord("SPLIT TABLE ")
if err := n.Table.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore SplitIndexRegionStmt.Table")
}
ctx.WriteKeyWord(" INDEX ")
ctx.WriteName(n.IndexName)
ctx.WriteKeyWord(" BY ")
for i, row := range n.ValueLists {
if i != 0 {
ctx.WritePlain(",")
}
ctx.WritePlain("(")
for j, v := range row {
if j != 0 {
ctx.WritePlain(",")
}
if err := v.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore SplitIndexRegionStmt.ValueLists[%d][%d]", i, j)
}
}
ctx.WritePlain(")")
}
return nil
}

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

n = newNode.(*SplitIndexRegionStmt)
node, ok := n.Table.Accept(v)
if !ok {
return n, false
}
n.Table = node.(*TableName)
for i, list := range n.ValueLists {
for j, val := range list {
node, ok := val.Accept(v)
if !ok {
return n, false
}
n.ValueLists[i][j] = node.(ExprNode)
}
}
return v.Leave(n)
}
1 change: 1 addition & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ var tokenMap = map[string]int{
"SMALLINT": smallIntType,
"SNAPSHOT": snapshot,
"SOME": some,
"SPLIT": split,
"SQL": sql,
"SQL_CACHE": sqlCache,
"SQL_CALC_FOUND_ROWS": sqlCalcFoundRows,
Expand Down
Loading

0 comments on commit 6528a83

Please sign in to comment.