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

drds #42

Merged
merged 2 commits into from
Jan 4, 2024
Merged

drds #42

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
45 changes: 33 additions & 12 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3886,8 +3886,9 @@ func (n *PartitionMethod) acceptInPlace(v Visitor) bool {
type PartitionOptions struct {
node
PartitionMethod
Sub *PartitionMethod
Definitions []*PartitionDefinition
Sub *PartitionMethod
Definitions []*PartitionDefinition
PartitionFrom int
}

// Validate checks if the partition is well-formed.
Expand Down Expand Up @@ -3947,24 +3948,44 @@ func (n *PartitionOptions) Validate() error {
}

func (n *PartitionOptions) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("PARTITION BY ")
if n.PartitionFrom == 1 {
ctx.WriteKeyWord("DBPARTITION BY ")
} else {
ctx.WriteKeyWord("PARTITION BY ")
}
if err := n.PartitionMethod.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore PartitionOptions.PartitionMethod")
}

if n.Num > 0 && len(n.Definitions) == 0 {
ctx.WriteKeyWord(" PARTITIONS ")
ctx.WritePlainf("%d", n.Num)
if n.PartitionFrom == 1 {
ctx.WriteKeyWord(" DBPARTITIONS ")
ctx.WritePlainf("%d", n.Num)
} else {
ctx.WriteKeyWord(" PARTITIONS ")
ctx.WritePlainf("%d", n.Num)
}
}

if n.Sub != nil {
ctx.WriteKeyWord(" SUBPARTITION BY ")
if err := n.Sub.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore PartitionOptions.Sub")
}
if n.Sub.Num > 0 {
ctx.WriteKeyWord(" SUBPARTITIONS ")
ctx.WritePlainf("%d", n.Sub.Num)
if n.PartitionFrom == 1 {
ctx.WriteKeyWord(" TBPARTITION BY ")
if err := n.Sub.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore PartitionOptions.Sub")
}
if n.Sub.Num > 0 {
ctx.WriteKeyWord(" TBPARTITIONS ")
ctx.WritePlainf("%d", n.Sub.Num)
}
} else {
ctx.WriteKeyWord(" SUBPARTITION BY ")
if err := n.Sub.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore PartitionOptions.Sub")
}
if n.Sub.Num > 0 {
ctx.WriteKeyWord(" SUBPARTITIONS ")
ctx.WritePlainf("%d", n.Sub.Num)
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ var tokenMap = map[string]int{
"PARTITION": partition,
"PARTITIONING": partitioning,
"PARTITIONS": partitions,
"DBPARTITION": dbpartition,
"DBPARTITIONS": dbpartitions,
"PASSWORD": password,
"PERCENT": percent,
"PER_DB": per_db,
Expand Down Expand Up @@ -701,6 +703,8 @@ var tokenMap = map[string]int{
"SUBJECT": subject,
"SUBPARTITION": subpartition,
"SUBPARTITIONS": subpartitions,
"TBPARTITION": tbpartition,
"TBPARTITIONS": tbpartitions,
"SUBSTR": substring,
"SUBSTRING": substring,
"SUM": sum,
Expand Down
Loading