Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: support admin alter ddl jobs grammar #57268

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 AlterJobOpt 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 *AlterJobOpt) 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 AlterJobOpt")
}
}
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 []*AlterJobOpt
}

// 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 AlterJobStmt.Options")
}
}
default:
return errors.New("Unsupported AdminStmt type")
}
Expand Down
Loading