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 create and alter placement policy #1313

Merged
merged 8 commits into from
Aug 23, 2021
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
70 changes: 70 additions & 0 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ import (
var (
_ DDLNode = &AlterTableStmt{}
_ DDLNode = &AlterSequenceStmt{}
_ DDLNode = &AlterPlacementPolicyStmt{}
_ DDLNode = &CreateDatabaseStmt{}
_ DDLNode = &CreateIndexStmt{}
_ DDLNode = &CreateTableStmt{}
_ DDLNode = &CreateViewStmt{}
_ DDLNode = &CreateSequenceStmt{}
_ DDLNode = &CreatePlacementPolicyStmt{}
_ DDLNode = &DropDatabaseStmt{}
_ DDLNode = &DropIndexStmt{}
_ DDLNode = &DropTableStmt{}
Expand Down Expand Up @@ -1429,6 +1431,41 @@ func (n *CreateViewStmt) Accept(v Visitor) (Node, bool) {
return v.Leave(n)
}

// CreatePlacementPolicyStmt is a statement to create a policy.
type CreatePlacementPolicyStmt struct {
ddlNode

IfNotExists bool
PolicyName model.CIStr
PlacementOptions []*PlacementOption
}

// Restore implements Node interface.
func (n *CreatePlacementPolicyStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("CREATE PLACEMENT POLICY ")
if n.IfNotExists {
ctx.WriteKeyWord("IF NOT EXISTS ")
}
ctx.WriteName(n.PolicyName.O)
for i, option := range n.PlacementOptions {
ctx.WritePlain(" ")
if err := option.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while splicing CreatePlacementPolicy TableOption: [%v]", i)
}
}
return nil
}

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

// CreateSequenceStmt is a statement to create a Sequence.
type CreateSequenceStmt struct {
ddlNode
Expand Down Expand Up @@ -3897,6 +3934,39 @@ func (n *AttributesSpec) Accept(v Visitor) (Node, bool) {
return v.Leave(n)
}

// AlterPlacementPolicyStmt is a statement to alter placement policy option.
type AlterPlacementPolicyStmt struct {
ddlNode

PolicyName model.CIStr
IfExists bool
PlacementOptions []*PlacementOption
}

func (n *AlterPlacementPolicyStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("ALTER PLACEMENT POLICY ")
if n.IfExists {
ctx.WriteKeyWord("IF EXISTS ")
}
ctx.WriteName(n.PolicyName.O)
for i, option := range n.PlacementOptions {
ctx.WritePlain(" ")
if err := option.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while splicing AlterPlacementPolicyStmt TableOption: [%v]", i)
}
}
return nil
}

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

// AlterSequenceStmt is a statement to alter sequence option.
type AlterSequenceStmt struct {
ddlNode
Expand Down
6 changes: 6 additions & 0 deletions model/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ const (
ActionDropIndexes ActionType = 48
ActionAlterTableAttributes ActionType = 49
ActionAlterTablePartitionAttributes ActionType = 50
ActionCreatePlacementPolicy ActionType = 51
ActionAlterPlacementPolicy ActionType = 52
ActionDropPlacementPolicy ActionType = 53
)

var actionMap = map[ActionType]string{
Expand Down Expand Up @@ -133,6 +136,9 @@ var actionMap = map[ActionType]string{
ActionDropIndexes: "drop multi-indexes",
ActionAlterTableAttributes: "alter table attributes",
ActionAlterTablePartitionAttributes: "alter table partition attributes",
ActionCreatePlacementPolicy: "create placement policy",
ActionAlterPlacementPolicy: "alter placement policy",
ActionDropPlacementPolicy: "drop placement policy",
}

// String return current ddl action in string
Expand Down
Loading