Skip to content

Commit

Permalink
add support for [TRUNCATE|DISCARD|IMPORT|OPTIMIZE|REPAIR] PARTITION (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
huaouo authored and leoppro committed Aug 15, 2019
1 parent 7d6e1da commit 2eccb3a
Show file tree
Hide file tree
Showing 4 changed files with 7,669 additions and 7,395 deletions.
65 changes: 65 additions & 0 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,10 @@ const (
AlterTableWithValidation
AlterTableWithoutValidation
AlterTableExchangePartition
AlterTableOptimizePartition
AlterTableRepairPartition
AlterTableImportPartitionTablespace
AlterTableDiscardPartitionTablespace

// TODO: Add more actions
)
Expand Down Expand Up @@ -1890,6 +1894,7 @@ type AlterTableSpec struct {
// see https://mariadb.com/kb/en/library/alter-table/
IfNotExists bool

OnAllPartitions bool
NoWriteToBinlog bool

Tp AlterTableType
Expand Down Expand Up @@ -2107,12 +2112,72 @@ func (n *AlterTableSpec) Restore(ctx *RestoreCtx) error {
}
case AlterTableTruncatePartition:
ctx.WriteKeyWord("TRUNCATE PARTITION ")
if n.OnAllPartitions {
ctx.WriteKeyWord("ALL")
return nil
}
for i, name := range n.PartitionNames {
if i != 0 {
ctx.WritePlain(",")
}
ctx.WriteName(name.O)
}
case AlterTableOptimizePartition:
ctx.WriteKeyWord("OPTIMIZE PARTITION ")
if n.NoWriteToBinlog {
ctx.WriteKeyWord("NO_WRITE_TO_BINLOG ")
}
if n.OnAllPartitions {
ctx.WriteKeyWord("ALL")
return nil
}
for i, name := range n.PartitionNames {
if i != 0 {
ctx.WritePlain(",")
}
ctx.WriteName(name.O)
}
case AlterTableRepairPartition:
ctx.WriteKeyWord("REPAIR PARTITION ")
if n.NoWriteToBinlog {
ctx.WriteKeyWord("NO_WRITE_TO_BINLOG ")
}
if n.OnAllPartitions {
ctx.WriteKeyWord("ALL")
return nil
}
for i, name := range n.PartitionNames {
if i != 0 {
ctx.WritePlain(",")
}
ctx.WriteName(name.O)
}
case AlterTableImportPartitionTablespace:
ctx.WriteKeyWord("IMPORT PARTITION ")
if n.OnAllPartitions {
ctx.WriteKeyWord("ALL")
} else {
for i, name := range n.PartitionNames {
if i != 0 {
ctx.WritePlain(",")
}
ctx.WriteName(name.O)
}
}
ctx.WriteKeyWord(" TABLESPACE")
case AlterTableDiscardPartitionTablespace:
ctx.WriteKeyWord("DISCARD PARTITION ")
if n.OnAllPartitions {
ctx.WriteKeyWord("ALL")
} else {
for i, name := range n.PartitionNames {
if i != 0 {
ctx.WritePlain(",")
}
ctx.WriteName(name.O)
}
}
ctx.WriteKeyWord(" TABLESPACE")
case AlterTablePartition:
if err := n.Partition.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore AlterTableSpec.Partition")
Expand Down
4 changes: 4 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ var tokenMap = map[string]int{
"DESCRIBE": describe,
"DIRECTORY": directory,
"DISABLE": disable,
"DISCARD": discard,
"DISK": disk,
"DISTINCT": distinct,
"DISTINCTROW": distinct,
Expand Down Expand Up @@ -307,6 +308,7 @@ var tokenMap = map[string]int{
"IDENTIFIED": identified,
"IF": ifKwd,
"IGNORE": ignore,
"IMPORT": importKwd,
"IN": in,
"INCREMENTAL": incremental,
"INDEX": index,
Expand Down Expand Up @@ -413,6 +415,7 @@ var tokenMap = map[string]int{
"ON": on,
"ONLY": only,
"OPTIMISTIC": optimistic,
"OPTIMIZE": optimize,
"OPTION": option,
"OPTIONALLY": optionally,
"OR": or,
Expand Down Expand Up @@ -459,6 +462,7 @@ var tokenMap = map[string]int{
"RELOAD": reload,
"REMOVE": remove,
"RENAME": rename,
"REPAIR": repair,
"REPEAT": repeat,
"REPEATABLE": repeatable,
"REPLACE": replace,
Expand Down
Loading

0 comments on commit 2eccb3a

Please sign in to comment.