Skip to content

Commit

Permalink
parser: support admin alter ddl jobs grammar (#57268) (#57512)
Browse files Browse the repository at this point in the history
ref #57229
  • Loading branch information
ti-chi-bot authored Nov 20, 2024
1 parent ed6d669 commit 562f614
Show file tree
Hide file tree
Showing 4 changed files with 7,089 additions and 6,972 deletions.
47 changes: 40 additions & 7 deletions pkg/parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,7 @@ const (
AdminSetBDRRole
AdminShowBDRRole
AdminUnsetBDRRole
AdminAlterDDLJob
)

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

type AlterJobOption struct {
// Name is the name of the option, will be converted to lower case during parse.
Name string
// only literal is allowed, we use ExprNode to support negative number
Value ExprNode
}

func (l *AlterJobOption) Restore(ctx *format.RestoreCtx) error {
if l.Value == nil {
ctx.WritePlain(l.Name)
} else {
ctx.WritePlain(l.Name + " = ")
if err := l.Value.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore AlterJobOption")
}
}
return nil
}

// AdminStmt is the struct for Admin statement.
type AdminStmt struct {
stmtNode
Expand All @@ -2567,13 +2587,14 @@ type AdminStmt struct {
JobIDs []int64
JobNumber int64

HandleRanges []HandleRange
ShowSlow *ShowSlow
Plugins []string
Where ExprNode
StatementScope StatementScope
LimitSimple LimitSimple
BDRRole BDRRole
HandleRanges []HandleRange
ShowSlow *ShowSlow
Plugins []string
Where ExprNode
StatementScope StatementScope
LimitSimple LimitSimple
BDRRole BDRRole
AlterJobOptions []*AlterJobOption
}

// Restore implements Node interface.
Expand Down Expand Up @@ -2737,6 +2758,18 @@ func (n *AdminStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("SHOW BDR ROLE")
case AdminUnsetBDRRole:
ctx.WriteKeyWord("UNSET BDR ROLE")
case AdminAlterDDLJob:
ctx.WriteKeyWord("ALTER DDL JOBS ")
ctx.WritePlainf("%d", n.JobNumber)
for i, option := range n.AlterJobOptions {
if i != 0 {
ctx.WritePlain(",")
}
ctx.WritePlain(" ")
if err := option.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore AdminStmt.AlterJobOptions[%d]", i)
}
}
default:
return errors.New("Unsupported AdminStmt type")
}
Expand Down
Loading

0 comments on commit 562f614

Please sign in to comment.