Skip to content

Commit a5832b4

Browse files
authored
parser: support admin alter ddl jobs grammar (#57268)
ref #57229
1 parent 169210a commit a5832b4

File tree

4 files changed

+7089
-6972
lines changed

4 files changed

+7089
-6972
lines changed

pkg/parser/ast/misc.go

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,7 @@ const (
24692469
AdminSetBDRRole
24702470
AdminShowBDRRole
24712471
AdminUnsetBDRRole
2472+
AdminAlterDDLJob
24722473
)
24732474

24742475
// HandleRange represents a range where handle value >= Begin and < End.
@@ -2557,6 +2558,25 @@ type LimitSimple struct {
25572558
Offset uint64
25582559
}
25592560

2561+
type AlterJobOption struct {
2562+
// Name is the name of the option, will be converted to lower case during parse.
2563+
Name string
2564+
// only literal is allowed, we use ExprNode to support negative number
2565+
Value ExprNode
2566+
}
2567+
2568+
func (l *AlterJobOption) Restore(ctx *format.RestoreCtx) error {
2569+
if l.Value == nil {
2570+
ctx.WritePlain(l.Name)
2571+
} else {
2572+
ctx.WritePlain(l.Name + " = ")
2573+
if err := l.Value.Restore(ctx); err != nil {
2574+
return errors.Annotatef(err, "An error occurred while restore AlterJobOption")
2575+
}
2576+
}
2577+
return nil
2578+
}
2579+
25602580
// AdminStmt is the struct for Admin statement.
25612581
type AdminStmt struct {
25622582
stmtNode
@@ -2567,13 +2587,14 @@ type AdminStmt struct {
25672587
JobIDs []int64
25682588
JobNumber int64
25692589

2570-
HandleRanges []HandleRange
2571-
ShowSlow *ShowSlow
2572-
Plugins []string
2573-
Where ExprNode
2574-
StatementScope StatementScope
2575-
LimitSimple LimitSimple
2576-
BDRRole BDRRole
2590+
HandleRanges []HandleRange
2591+
ShowSlow *ShowSlow
2592+
Plugins []string
2593+
Where ExprNode
2594+
StatementScope StatementScope
2595+
LimitSimple LimitSimple
2596+
BDRRole BDRRole
2597+
AlterJobOptions []*AlterJobOption
25772598
}
25782599

25792600
// Restore implements Node interface.
@@ -2737,6 +2758,18 @@ func (n *AdminStmt) Restore(ctx *format.RestoreCtx) error {
27372758
ctx.WriteKeyWord("SHOW BDR ROLE")
27382759
case AdminUnsetBDRRole:
27392760
ctx.WriteKeyWord("UNSET BDR ROLE")
2761+
case AdminAlterDDLJob:
2762+
ctx.WriteKeyWord("ALTER DDL JOBS ")
2763+
ctx.WritePlainf("%d", n.JobNumber)
2764+
for i, option := range n.AlterJobOptions {
2765+
if i != 0 {
2766+
ctx.WritePlain(",")
2767+
}
2768+
ctx.WritePlain(" ")
2769+
if err := option.Restore(ctx); err != nil {
2770+
return errors.Annotatef(err, "An error occurred while restore AdminStmt.AlterJobOptions[%d]", i)
2771+
}
2772+
}
27402773
default:
27412774
return errors.New("Unsupported AdminStmt type")
27422775
}

0 commit comments

Comments
 (0)