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 and bb7133 committed Dec 5, 2019
1 parent 62bbf32 commit 91f36bd
Show file tree
Hide file tree
Showing 5 changed files with 6,571 additions and 6,441 deletions.
37 changes: 34 additions & 3 deletions ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2438,8 +2438,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 @@ -2451,11 +2454,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 @@ -437,6 +437,7 @@ var tokenMap = map[string]int{
"REFERENCES": references,
"REGEXP": regexpKwd,
"REGIONS": regions,
"REGION": region,
"RELOAD": reload,
"RENAME": rename,
"REPEAT": repeat,
Expand Down
Loading

0 comments on commit 91f36bd

Please sign in to comment.