Skip to content

Commit

Permalink
[parser] parser: add a state field for partitionDefinition (pingcap#927)
Browse files Browse the repository at this point in the history
* add schema state for partition definition

Signed-off-by: AilinKid <314806019@qq.com>

* add clone function

Signed-off-by: AilinKid <314806019@qq.com>

* change value copy to slice element self

Signed-off-by: AilinKid <314806019@qq.com>
  • Loading branch information
AilinKid authored and ti-chi-bot committed Oct 9, 2021
1 parent 2a676ef commit 8b78e03
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions parser/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,30 @@ func (pi *PartitionInfo) GetNameByID(id int64) string {

// PartitionDefinition defines a single partition.
type PartitionDefinition struct {
ID int64 `json:"id"`
Name CIStr `json:"name"`
LessThan []string `json:"less_than"`
Comment string `json:"comment,omitempty"`
ID int64 `json:"id"`
Name CIStr `json:"name"`
LessThan []string `json:"less_than"`
Comment string `json:"comment,omitempty"`
State SchemaState `json:"state"`
}

// Clone clones ConstraintInfo.
func (ci *PartitionDefinition) Clone() PartitionDefinition {
nci := *ci
nci.LessThan = make([]string, len(ci.LessThan))
copy(nci.LessThan, ci.LessThan)
return nci
}

// FindPartitionDefinitionByName finds PartitionDefinition by name.
func (t *TableInfo) FindPartitionDefinitionByName(partitionDefinitionName string) *PartitionDefinition {
lowConstrName := strings.ToLower(partitionDefinitionName)
for i, pd := range t.Partition.Definitions {
if pd.Name.L == lowConstrName {
return &t.Partition.Definitions[i]
}
}
return nil
}

// IndexColumn provides index column info.
Expand Down

0 comments on commit 8b78e03

Please sign in to comment.