Skip to content

Commit

Permalink
use alter table remove ttl spec
Browse files Browse the repository at this point in the history
Signed-off-by: YangKeao <[email protected]>
  • Loading branch information
YangKeao committed Nov 23, 2022
1 parent 7c46100 commit 885cfa5
Show file tree
Hide file tree
Showing 6 changed files with 9,356 additions and 9,362 deletions.
22 changes: 10 additions & 12 deletions parser/ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,6 @@ const (
TableOptionEncryption
TableOptionTTL
TableOptionTTLEnable
TableOptionNoTTL
TableOptionPlacementPolicy = TableOptionType(PlacementOptionPolicy)
TableOptionStatsBuckets = TableOptionType(StatsOptionBuckets)
TableOptionStatsTopN = TableOptionType(StatsOptionTopN)
Expand Down Expand Up @@ -2138,7 +2137,6 @@ type TableOption struct {
BoolValue bool
TimeUnitValue *TimeUnitExpr
Value ValueExpr
Expression ExprNode
TableNames []*TableName
ColumnName *ColumnName
}
Expand Down Expand Up @@ -2425,7 +2423,7 @@ func (n *TableOption) Restore(ctx *format.RestoreCtx) error {
ctx.WritePlain("= ")
ctx.WriteName(n.ColumnName.Name.String())
ctx.WritePlain(" + INTERVAL ")
err := n.Expression.Restore(ctx)
err := n.Value.Restore(ctx)
ctx.WritePlain(" ")
if err != nil {
return err
Expand All @@ -2443,11 +2441,6 @@ func (n *TableOption) Restore(ctx *format.RestoreCtx) error {
}
return nil
})
case TableOptionNoTTL:
_ = ctx.WriteWithSpecialComments(tidb.FeatureIDTTL, func() error {
ctx.WriteKeyWord("NO_TTL")
return nil
})
default:
return errors.Errorf("invalid TableOption: %d", n.Tp)
}
Expand All @@ -2461,12 +2454,12 @@ func (n *TableOption) Accept(v Visitor) (Node, bool) {
return v.Leave(newNode)
}
n = newNode.(*TableOption)
if n.Expression != nil {
node, ok := n.Expression.Accept(v)
if n.Value != nil {
node, ok := n.Value.Accept(v)
if !ok {
return n, false
}
n.Expression = node.(ExprNode)
n.Value = node.(ValueExpr)
}
if n.TimeUnitValue != nil {
node, ok := n.TimeUnitValue.Accept(v)
Expand Down Expand Up @@ -2666,6 +2659,7 @@ const (
AlterTableAddLastPartition
AlterTableReorganizeLastPartition
AlterTableReorganizeFirstPartition
AlterTableRemoveTTL
)

// LockType is the type for AlterTableSpec.
Expand Down Expand Up @@ -3347,7 +3341,11 @@ func (n *AlterTableSpec) Restore(ctx *format.RestoreCtx) error {
if err := spec.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore AlterTableSpec.StatsOptionsSpec")
}

case AlterTableRemoveTTL:
_ = ctx.WriteWithSpecialComments(tidb.FeatureIDTTL, func() error {
ctx.WriteKeyWord("REMOVE TTL")
return nil
})
default:
// TODO: not support
ctx.WritePlainf(" /* AlterTableType(%d) is not supported */ ", n.Tp)
Expand Down
6 changes: 3 additions & 3 deletions parser/ast/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ func TestFlashBackDatabaseRestore(t *testing.T) {
func TestTableOptionTTLRestore(t *testing.T) {
sourceSQL1 := "create table t (created_at datetime) ttl = created_at + INTERVAL 1 YEAR"
sourceSQL2 := "alter table t ttl_enable = 'OFF'"
sourceSQL3 := "alter table t no_ttl"
sourceSQL3 := "alter table t remove ttl"
cases := []struct {
sourceSQL string
flags format.RestoreFlags
Expand All @@ -854,8 +854,8 @@ func TestTableOptionTTLRestore(t *testing.T) {
{sourceSQL1, format.DefaultRestoreFlags | format.RestoreTiDBSpecialComment, "CREATE TABLE `t` (`created_at` DATETIME) /*T![ttl] TTL = `created_at` + INTERVAL 1 YEAR */"},
{sourceSQL2, format.DefaultRestoreFlags, "ALTER TABLE `t` TTL_ENABLE = 'OFF'"},
{sourceSQL2, format.DefaultRestoreFlags | format.RestoreTiDBSpecialComment, "ALTER TABLE `t` /*T![ttl] TTL_ENABLE = 'OFF' */"},
{sourceSQL3, format.DefaultRestoreFlags, "ALTER TABLE `t` NO_TTL"},
{sourceSQL3, format.DefaultRestoreFlags | format.RestoreTiDBSpecialComment, "ALTER TABLE `t` /*T![ttl] NO_TTL */"},
{sourceSQL3, format.DefaultRestoreFlags, "ALTER TABLE `t` REMOVE TTL"},
{sourceSQL3, format.DefaultRestoreFlags | format.RestoreTiDBSpecialComment, "ALTER TABLE `t` /*T![ttl] REMOVE TTL */"},
}

extractNodeFunc := func(node Node) Node {
Expand Down
1 change: 0 additions & 1 deletion parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,6 @@ var tokenMap = map[string]int{
"TRUE_CARD_COST": trueCardCost,
"TTL": ttl,
"TTL_ENABLE": ttlEnable,
"NO_TTL": nottl,
"TYPE": tp,
"UNBOUNDED": unbounded,
"UNCOMMITTED": uncommitted,
Expand Down
Loading

0 comments on commit 885cfa5

Please sign in to comment.