Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 44 additions & 3 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,9 @@ type CreateMaskingPolicyStmt struct {
Expr ExprNode
RestrictOps MaskingPolicyRestrictOps
MaskingPolicyState MaskingPolicyState
// Using selects the USING (expr) spelling of the masking expression
// clause over AS expr.
Using bool
}

// Restore implements Node interface.
Expand All @@ -1875,9 +1878,18 @@ func (n *CreateMaskingPolicyStmt) Restore(ctx *format.RestoreCtx) error {
return annotate(err, "An error occurred while restore CreateMaskingPolicyStmt.Column")
}
ctx.WritePlain(") ")
ctx.WriteKeyWord("AS ")
if err := n.Expr.Restore(ctx); err != nil {
return annotate(err, "An error occurred while restore CreateMaskingPolicyStmt.Expr")
if n.Using {
ctx.WriteKeyWord("USING ")
ctx.WritePlain("(")
if err := n.Expr.Restore(ctx); err != nil {
return annotate(err, "An error occurred while restore CreateMaskingPolicyStmt.Expr")
}
ctx.WritePlain(")")
} else {
ctx.WriteKeyWord("AS ")
if err := n.Expr.Restore(ctx); err != nil {
return annotate(err, "An error occurred while restore CreateMaskingPolicyStmt.Expr")
}
}
if n.RestrictOps != MaskingPolicyRestrictOpNone {
ctx.WritePlain(" ")
Expand Down Expand Up @@ -1925,6 +1937,35 @@ func (n *CreateMaskingPolicyStmt) Accept(v Visitor) (Node, bool) {
return v.Leave(n)
}

// DropMaskingPolicyStmt is a statement to drop a masking policy:
// DROP MASKING POLICY [IF EXISTS] policy_name.
type DropMaskingPolicyStmt struct {
ddlNode

IfExists bool
PolicyName CIStr
}

// Restore implements Node interface.
func (n *DropMaskingPolicyStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("DROP MASKING POLICY ")
if n.IfExists {
ctx.WriteKeyWord("IF EXISTS ")
}
ctx.WriteName(n.PolicyName.O)
return nil
}

// Accept implements Node Accept interface.
func (n *DropMaskingPolicyStmt) Accept(v Visitor) (Node, bool) {
newNode, skipChildren := v.Enter(n)
if skipChildren {
return v.Leave(newNode)
}
n = newNode.(*DropMaskingPolicyStmt)
return v.Leave(n)
}

// CreateResourceGroupStmt is a statement to create a policy.
type CreateResourceGroupStmt struct {
ddlNode
Expand Down
32 changes: 30 additions & 2 deletions ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -3896,12 +3896,32 @@ type SelectIntoOption struct {
FileName string
FieldsInfo *FieldsClause
LinesInfo *LinesClause
// Vars is the variable list of the SelectIntoVars form: user
// variables and, in stored programs, program variables (restored as
// plain names).
Vars []ExprNode
}

// Restore implements Node interface.
func (n *SelectIntoOption) Restore(ctx *format.RestoreCtx) error {
if n.Tp != SelectIntoOutfile {
// only support SELECT/TABLE/VALUES ... INTO OUTFILE statement now
switch n.Tp {
case SelectIntoOutfile:
case SelectIntoDumpfile:
ctx.WriteKeyWord("INTO DUMPFILE ")
ctx.WriteString(n.FileName)
return nil
case SelectIntoVars:
ctx.WriteKeyWord("INTO ")
for i, v := range n.Vars {
if i != 0 {
ctx.WritePlain(", ")
}
if err := v.Restore(ctx); err != nil {
return annotatef(err, "An error occurred while restore SelectInto.Vars[%d]", i)
}
}
return nil
default:
return errors.New("Unsupported SelectionInto type")
}

Expand All @@ -3926,6 +3946,14 @@ func (n *SelectIntoOption) Accept(v Visitor) (Node, bool) {
if skipChildren {
return v.Leave(newNode)
}
n = newNode.(*SelectIntoOption)
for i, v2 := range n.Vars {
node, ok := v2.Accept(v)
if !ok {
return n, false
}
n.Vars[i] = node.(ExprNode)
}
return v.Leave(n)
}

Expand Down
37 changes: 37 additions & 0 deletions ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,10 @@ type ReplicationSourceOption struct {
// Restore implements Node interface.
func (n *ReplicationSourceOption) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord(n.Name)
if n.Value == nil {
// A bare option name (START REPLICA UNTIL SQL_AFTER_MTS_GAPS).
return nil
}
ctx.WritePlain(" = ")
if err := n.Value.Restore(ctx); err != nil {
return fmt.Errorf("an error occurred while restore ReplicationSourceOption.Value: %w", err)
Expand Down Expand Up @@ -2063,18 +2067,51 @@ func (n *AlterUserStmt) Accept(v Visitor) (Node, bool) {

// AlterInstanceStmt modifies instance.
// See https://dev.mysql.com/doc/refman/8.0/en/alter-instance.html
// Exactly one of the action fields is set: ReloadTLS (with optional
// Channel and NoRollbackOnError), RotateInnoDBMasterKey,
// RotateBinlogMasterKey, ReloadKeyring, EnableInnoDBRedoLog, or
// DisableInnoDBRedoLog.
type AlterInstanceStmt struct {
stmtNode

ReloadTLS bool
NoRollbackOnError bool
// Channel is the FOR CHANNEL name of RELOAD TLS (mysql_main or
// mysql_admin); empty when absent.
Channel string
RotateInnoDBMasterKey bool
RotateBinlogMasterKey bool
ReloadKeyring bool
EnableInnoDBRedoLog bool
DisableInnoDBRedoLog bool
}

// Restore implements Node interface.
func (n *AlterInstanceStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("ALTER INSTANCE")
switch {
case n.RotateInnoDBMasterKey:
ctx.WriteKeyWord(" ROTATE INNODB MASTER KEY")
return nil
case n.RotateBinlogMasterKey:
ctx.WriteKeyWord(" ROTATE BINLOG MASTER KEY")
return nil
case n.ReloadKeyring:
ctx.WriteKeyWord(" RELOAD KEYRING")
return nil
case n.EnableInnoDBRedoLog:
ctx.WriteKeyWord(" ENABLE INNODB REDO_LOG")
return nil
case n.DisableInnoDBRedoLog:
ctx.WriteKeyWord(" DISABLE INNODB REDO_LOG")
return nil
}
if n.ReloadTLS {
ctx.WriteKeyWord(" RELOAD TLS")
if n.Channel != "" {
ctx.WriteKeyWord(" FOR CHANNEL ")
ctx.WriteName(n.Channel)
}
}
if n.NoRollbackOnError {
ctx.WriteKeyWord(" NO ROLLBACK ON ERROR")
Expand Down
Loading
Loading