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

*: Add split index region syntax support. #297

Merged
merged 10 commits into from May 6, 2019
59 changes: 59 additions & 0 deletions ast/dml.go
Expand Up @@ -31,6 +31,7 @@ var (
_ DMLNode = &SelectStmt{}
_ DMLNode = &ShowStmt{}
_ DMLNode = &LoadDataStmt{}
_ DMLNode = &SplitIndexRegionStmt{}

_ Node = &Assignment{}
_ Node = &ByItem{}
Expand Down Expand Up @@ -2300,3 +2301,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 SplitTableIndexRegionStmt.Table")
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
}
ctx.WriteKeyWord(" INDEX ")
ctx.WriteName(n.IndexName)
ctx.WriteKeyWord(" BY ")
for i, row := range n.ValueLists {
if i != 0 {
ctx.WritePlain(",")
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
}
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 SplitTableIndexRegionStmt.ValueLists[%d][%d]", i, j)
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
}
}
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
Expand Up @@ -456,6 +456,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