Skip to content

Commit

Permalink
*: refine split region syntax add split partition table region syntax. (
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored Oct 12, 2019
1 parent 8b33331 commit 464e332
Show file tree
Hide file tree
Showing 4 changed files with 7,309 additions and 7,201 deletions.
37 changes: 34 additions & 3 deletions ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2427,8 +2427,11 @@ func (n *FrameBound) Accept(v Visitor) (Node, bool) {
type SplitRegionStmt struct {
dmlNode

Table *TableName
IndexName model.CIStr
Table *TableName
IndexName model.CIStr
PartitionNames []model.CIStr

SplitSyntaxOpt *SplitSyntaxOption

SplitOpt *SplitOption
}
Expand All @@ -2440,11 +2443,39 @@ type SplitOption struct {
ValueLists [][]ExprNode
}

type SplitSyntaxOption struct {
HasRegionFor bool
HasPartition bool
}

func (n *SplitRegionStmt) Restore(ctx *RestoreCtx) error {
ctx.WriteKeyWord("SPLIT TABLE ")
ctx.WriteKeyWord("SPLIT ")
if n.SplitSyntaxOpt != nil {
if n.SplitSyntaxOpt.HasRegionFor {
ctx.WriteKeyWord("REGION FOR ")
}
if n.SplitSyntaxOpt.HasPartition {
ctx.WriteKeyWord("PARTITION ")

}
}
ctx.WriteKeyWord("TABLE ")

if err := n.Table.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore SplitIndexRegionStmt.Table")
}
if len(n.PartitionNames) > 0 {
ctx.WriteKeyWord(" PARTITION")
ctx.WritePlain("(")
for i, v := range n.PartitionNames {
if i != 0 {
ctx.WritePlain(", ")
}
ctx.WriteName(v.String())
}
ctx.WritePlain(")")
}

if len(n.IndexName.L) > 0 {
ctx.WriteKeyWord(" INDEX ")
ctx.WriteName(n.IndexName.String())
Expand Down
1 change: 1 addition & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ var tokenMap = map[string]int{
"REFERENCES": references,
"REGEXP": regexpKwd,
"REGIONS": regions,
"REGION": region,
"RELOAD": reload,
"REMOVE": remove,
"RENAME": rename,
Expand Down
Loading

0 comments on commit 464e332

Please sign in to comment.