Skip to content

Commit

Permalink
parser: more meaningful words for placement rules
Browse files Browse the repository at this point in the history
follow
pingcap/tidb#18030 (comment).
However, "constraints" is used for "label". Because it is not
necessarily related to region/locality.
  • Loading branch information
xhebox committed Jul 21, 2020
1 parent 3dd0dd2 commit 34aea1b
Show file tree
Hide file tree
Showing 5 changed files with 7,886 additions and 7,877 deletions.
18 changes: 9 additions & 9 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3468,23 +3468,23 @@ const (
type PlacementSpec struct {
node

Tp PlacementActionType
Labels string
Role PlacementRole
Count uint64
Tp PlacementActionType
Constraints string
Role PlacementRole
Replicas uint64
}

func (n *PlacementSpec) Restore(ctx *format.RestoreCtx) error {
switch n.Tp {
case PlacementAdd:
ctx.WriteKeyWord("ADD PLACEMENT ")
ctx.WriteKeyWord("ADD PLACEMENT POLICY ")
default:
return errors.Errorf("invalid PlacementActionType: %d", n.Tp)
}

ctx.WriteKeyWord("LABEL")
ctx.WriteKeyWord("CONSTRAINTS")
ctx.WritePlain("=")
ctx.WriteString(n.Labels)
ctx.WriteString(n.Constraints)

ctx.WriteKeyWord(" ROLE")
ctx.WritePlain("=")
Expand All @@ -3501,8 +3501,8 @@ func (n *PlacementSpec) Restore(ctx *format.RestoreCtx) error {
return errors.Errorf("invalid PlacementRole: %d", n.Role)
}

ctx.WriteKeyWord(" COUNT")
ctx.WritePlainf("=%d", n.Count)
ctx.WriteKeyWord(" REPLICAS")
ctx.WritePlainf("=%d", n.Replicas)
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ var tokenMap = map[string]int{
"CONNECTION": connection,
"CONSISTENT": consistent,
"CONSTRAINT": constraint,
"CONSTRAINTS": constraints,
"CONTEXT": context,
"CONVERT": convert,
"COPY": copyKwd,
"COUNT": count,
"APPROX_COUNT_DISTINCT": approxCountDistinct,
"CPU": cpu,
"CREATE": create,
Expand Down Expand Up @@ -397,7 +397,6 @@ var tokenMap = map[string]int{
"KEY": key,
"KEYS": keys,
"KILL": kill,
"LABEL": label,
"LABELS": labels,
"LANGUAGE": language,
"LAST_BACKUP": lastBackup,
Expand Down Expand Up @@ -506,6 +505,7 @@ var tokenMap = map[string]int{
"PESSIMISTIC": pessimistic,
"PLACEMENT": placement,
"PLUGINS": plugins,
"POLICY": policy,
"POSITION": position,
"PRE_SPLIT_REGIONS": preSplitRegions,
"PRECEDING": preceding,
Expand Down Expand Up @@ -545,6 +545,7 @@ var tokenMap = map[string]int{
"REPEATABLE": repeatable,
"REPLACE": replace,
"REPLICA": replica,
"REPLICAS": replicas,
"REPLICATION": replication,
"REQUIRE": require,
"RESET": reset,
Expand Down
Loading

0 comments on commit 34aea1b

Please sign in to comment.