Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pingcap/parser into table…
Browse files Browse the repository at this point in the history
…_lock
  • Loading branch information
crazycs520 committed Jun 6, 2019
2 parents d3658ad + 82be48f commit 9b7171e
Show file tree
Hide file tree
Showing 8 changed files with 6,577 additions and 6,373 deletions.
1 change: 1 addition & 0 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ type CreateViewStmt struct {
ViewName *TableName
Cols []model.CIStr
Select StmtNode
SchemaCols []model.CIStr
Algorithm model.ViewAlgorithm
Definer *auth.UserIdentity
Security model.ViewSecurity
Expand Down
55 changes: 55 additions & 0 deletions ast/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,61 @@ func (ts *testDDLSuite) TestDDLColumnDefRestore(c *C) {
{"id INT(11) comment 'hello'", "`id` INT(11) COMMENT 'hello'"},
{"id INT(11) generated always as(id + 1)", "`id` INT(11) GENERATED ALWAYS AS(`id`+1) VIRTUAL"},
{"id INT(11) REFERENCES parent(id)", "`id` INT(11) REFERENCES `parent`(`id`)"},

{"id bit", "`id` BIT(1)"},
{"id bit(1)", "`id` BIT(1)"},
{"id bit(64)", "`id` BIT(64)"},
{"id tinyint", "`id` TINYINT"},
{"id tinyint(255)", "`id` TINYINT(255)"},
{"id bool", "`id` TINYINT(1)"},
{"id boolean", "`id` TINYINT(1)"},
{"id smallint", "`id` SMALLINT"},
{"id smallint(255)", "`id` SMALLINT(255)"},
{"id mediumint", "`id` MEDIUMINT"},
{"id mediumint(255)", "`id` MEDIUMINT(255)"},
{"id int", "`id` INT"},
{"id int(255)", "`id` INT(255)"},
{"id integer", "`id` INT"},
{"id integer(255)", "`id` INT(255)"},
{"id bigint", "`id` BIGINT"},
{"id bigint(255)", "`id` BIGINT(255)"},
{"id decimal", "`id` DECIMAL"},
{"id decimal(10)", "`id` DECIMAL(10)"},
{"id decimal(10,0)", "`id` DECIMAL(10,0)"},
{"id decimal(65)", "`id` DECIMAL(65)"},
{"id decimal(65,30)", "`id` DECIMAL(65,30)"},
{"id dec(10,0)", "`id` DECIMAL(10,0)"},
{"id numeric(10,0)", "`id` DECIMAL(10,0)"},
{"id float(0)", "`id` FLOAT"},
{"id float(24)", "`id` FLOAT"},
{"id float(25)", "`id` DOUBLE"},
{"id float(53)", "`id` DOUBLE"},
{"id float(7,0)", "`id` FLOAT(7,0)"},
{"id float(25,0)", "`id` FLOAT(25,0)"},
{"id double(15,0)", "`id` DOUBLE(15,0)"},
{"id double precision(15,0)", "`id` DOUBLE(15,0)"},
{"id real(15,0)", "`id` DOUBLE(15,0)"},
{"id year(4)", "`id` YEAR(4)"},
{"id time", "`id` TIME"},
{"id char", "`id` CHAR"},
{"id char(0)", "`id` CHAR(0)"},
{"id char(255)", "`id` CHAR(255)"},
{"id national char(0)", "`id` CHAR(0)"},
{"id binary", "`id` BINARY"},
{"id varbinary(0)", "`id` VARBINARY(0)"},
{"id varbinary(65535)", "`id` VARBINARY(65535)"},
{"id tinyblob", "`id` TINYBLOB"},
{"id tinytext", "`id` TINYTEXT"},
{"id blob", "`id` BLOB"},
{"id blob(0)", "`id` BLOB(0)"},
{"id blob(65535)", "`id` BLOB(65535)"},
{"id text(0)", "`id` TEXT(0)"},
{"id text(65535)", "`id` TEXT(65535)"},
{"id mediumblob", "`id` MEDIUMBLOB"},
{"id mediumtext", "`id` MEDIUMTEXT"},
{"id longblob", "`id` LONGBLOB"},
{"id longtext", "`id` LONGTEXT"},
{"id json", "`id` JSON"},
}
extractNodeFunc := func(node Node) Node {
return node.(*CreateTableStmt).Cols[0]
Expand Down
113 changes: 86 additions & 27 deletions ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
_ DMLNode = &SelectStmt{}
_ DMLNode = &ShowStmt{}
_ DMLNode = &LoadDataStmt{}
_ DMLNode = &SplitIndexRegionStmt{}
_ DMLNode = &SplitRegionStmt{}

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

type SplitIndexRegionStmt struct {
type SplitRegionStmt struct {
dmlNode

Table *TableName
IndexName string
Table *TableName
IndexName model.CIStr

SplitOpt *SplitOption
}

type SplitOption struct {
Lower []ExprNode
Upper []ExprNode
Num int64
ValueLists [][]ExprNode
}

func (n *SplitIndexRegionStmt) Restore(ctx *RestoreCtx) error {
func (n *SplitRegionStmt) 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(")")
if len(n.IndexName.L) > 0 {
ctx.WriteKeyWord(" INDEX ")
ctx.WriteName(n.IndexName.String())
}
return nil
ctx.WritePlain(" ")
err := n.SplitOpt.Restore(ctx)
return err
}

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

n = newNode.(*SplitIndexRegionStmt)
n = newNode.(*SplitRegionStmt)
node, ok := n.Table.Accept(v)
if !ok {
return n, false
}
n.Table = node.(*TableName)
for i, list := range n.ValueLists {
for i, val := range n.SplitOpt.Lower {
node, ok := val.Accept(v)
if !ok {
return n, false
}
n.SplitOpt.Lower[i] = node.(ExprNode)
}
for i, val := range n.SplitOpt.Upper {
node, ok := val.Accept(v)
if !ok {
return n, false
}
n.SplitOpt.Upper[i] = node.(ExprNode)
}

for i, list := range n.SplitOpt.ValueLists {
for j, val := range list {
node, ok := val.Accept(v)
if !ok {
return n, false
}
n.ValueLists[i][j] = node.(ExprNode)
n.SplitOpt.ValueLists[i][j] = node.(ExprNode)
}
}
return v.Leave(n)
}

func (n *SplitOption) Restore(ctx *RestoreCtx) error {
if len(n.ValueLists) == 0 {
ctx.WriteKeyWord("BETWEEN ")
ctx.WritePlain("(")
for j, v := range n.Lower {
if j != 0 {
ctx.WritePlain(",")
}
if err := v.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore SplitOption Lower")
}
}
ctx.WritePlain(")")

ctx.WriteKeyWord(" AND ")
ctx.WritePlain("(")
for j, v := range n.Upper {
if j != 0 {
ctx.WritePlain(",")
}
if err := v.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore SplitOption Upper")
}
}
ctx.WritePlain(")")
ctx.WriteKeyWord(" REGIONS")
ctx.WritePlainf(" %d", n.Num)
return nil
}
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 SplitOption.ValueLists[%d][%d]", i, j)
}
}
ctx.WritePlain(")")
}
return nil
}
1 change: 1 addition & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ var tokenMap = map[string]int{
"REDUNDANT": redundant,
"REFERENCES": references,
"REGEXP": regexpKwd,
"REGIONS": regions,
"RELOAD": reload,
"RENAME": rename,
"REPEAT": repeat,
Expand Down
Loading

0 comments on commit 9b7171e

Please sign in to comment.