Skip to content

Commit

Permalink
add support for REMOVE PARTITIONING syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta committed Jul 25, 2019
1 parent 57e1f3b commit 5225a29
Show file tree
Hide file tree
Showing 5 changed files with 6,936 additions and 6,835 deletions.
57 changes: 49 additions & 8 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,6 @@ const (
AlterTableCoalescePartitions
AlterTableDropPartition
AlterTableTruncatePartition
AlterTablePartition
AlterTableEnableKeys
AlterTableDisableKeys

Expand Down Expand Up @@ -1738,6 +1737,41 @@ func (a AlterAlgorithm) String() string {
}
}

type AlterTablePartitionOption struct {
node

Partition *PartitionOptions
IsRemovePartitioning bool
}

func (n *AlterTablePartitionOption) Restore(ctx *RestoreCtx) error {
if n.Partition != nil {
ctx.WritePlain(" ")
if n.IsRemovePartitioning {
ctx.WriteKeyWord("REMOVE PARTITIONING")
} else {
if err := n.Partition.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore AlterTableStmt.AlterTablePartitionOption.Partition")
}
}
}
return nil
}

func (n *AlterTablePartitionOption) Accept(v Visitor) (Node, bool) {
newNode, skipChildren := v.Enter(n)
if skipChildren {
return v.Leave(newNode)
}
n = newNode.(*AlterTablePartitionOption)
node, ok := n.Partition.Accept(v)
if !ok {
return n, false
}
n.Partition = node.(*PartitionOptions)
return v.Leave(n)
}

// AlterTableSpec represents alter table specification.
type AlterTableSpec struct {
node
Expand Down Expand Up @@ -1964,10 +1998,6 @@ func (n *AlterTableSpec) Restore(ctx *RestoreCtx) error {
}
ctx.WriteName(name.O)
}
case AlterTablePartition:
if err := n.Partition.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore AlterTableSpec.Partition")
}
case AlterTableEnableKeys:
ctx.WriteKeyWord("ENABLE KEYS")
case AlterTableDisableKeys:
Expand Down Expand Up @@ -2029,8 +2059,9 @@ func (n *AlterTableSpec) Accept(v Visitor) (Node, bool) {
type AlterTableStmt struct {
ddlNode

Table *TableName
Specs []*AlterTableSpec
Table *TableName
Specs []*AlterTableSpec
PartitionOpt *AlterTablePartitionOption
}

// Restore implements Node interface.
Expand All @@ -2040,7 +2071,7 @@ func (n *AlterTableStmt) Restore(ctx *RestoreCtx) error {
return errors.Annotate(err, "An error occurred while restore AlterTableStmt.Table")
}
for i, spec := range n.Specs {
if i == 0 || spec.Tp == AlterTablePartition {
if i == 0 {
ctx.WritePlain(" ")
} else {
ctx.WritePlain(", ")
Expand All @@ -2049,6 +2080,16 @@ func (n *AlterTableStmt) Restore(ctx *RestoreCtx) error {
return errors.Annotatef(err, "An error occurred while restore AlterTableStmt.Specs[%d]", i)
}
}
if n.PartitionOpt != nil {
ctx.WritePlain(" ")
if n.PartitionOpt.IsRemovePartitioning {
ctx.WriteKeyWord("REMOVE PARTITIONING")
} else {
if err := n.PartitionOpt.Partition.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore AlterTableStmt.AlterTablePartitionOption.Partition")
}
}
}
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ var tokenMap = map[string]int{
"PACK_KEYS": packKeys,
"PAGE": pageSym,
"PARTITION": partition,
"PARTITIONING": partitioning,
"PARTITIONS": partitions,
"PASSWORD": password,
"PESSIMISTIC": pessimistic,
Expand Down Expand Up @@ -438,6 +439,7 @@ var tokenMap = map[string]int{
"REGEXP": regexpKwd,
"REGIONS": regions,
"RELOAD": reload,
"REMOVE": remove,
"RENAME": rename,
"REPEAT": repeat,
"REPEATABLE": repeatable,
Expand Down
Loading

0 comments on commit 5225a29

Please sign in to comment.