label

package
v0.0.0-...-503c688 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RuleIndexDefault is the default index for a rule.
	RuleIndexDefault int = iota
	// RuleIndexDatabase is the index for a rule of database.
	RuleIndexDatabase
	// RuleIndexTable is the index for a rule of table.
	RuleIndexTable
	// RuleIndexPartition is the index for a rule of partition.
	RuleIndexPartition
)
View Source
const (
	// IDPrefix is the prefix for label rule ID.
	IDPrefix = "schema"
)

Variables

View Source
var (
	// TableIDFormat is the format of the label rule ID for a table.
	// The format follows "schema/database_name/table_name".
	TableIDFormat = "%s/%s/%s"
	// PartitionIDFormat is the format of the label rule ID for a partition.
	// The format follows "schema/database_name/table_name/partition_name".
	PartitionIDFormat = "%s/%s/%s/%s"
)
View Source
var (
	// ErrInvalidAttributesFormat is from attributes.go
	ErrInvalidAttributesFormat = errors.New("attributes should be in format 'key=value'")
)

Functions

This section is empty.

Types

type AttributesCompatibility

type AttributesCompatibility byte

AttributesCompatibility is the return type of CompatibleWith.

const (
	// AttributesCompatible indicates two attributes are compatible.
	AttributesCompatible AttributesCompatibility = iota
	// AttributesIncompatible indicates two attributes are incompatible.
	AttributesIncompatible
	// AttributesDuplicated indicates two attributes are duplicated.
	AttributesDuplicated
)

type Label

type Label struct {
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

Label is used to describe attributes

func NewLabel

func NewLabel(attr string) (Label, error)

NewLabel creates a new label for a given string.

func (*Label) CompatibleWith

func (l *Label) CompatibleWith(o *Label) AttributesCompatibility

CompatibleWith will check if two constraints are compatible. Return (compatible, duplicated).

func (*Label) Restore

func (l *Label) Restore() string

Restore converts a Attribute to a string.

type Labels

type Labels []Label

Labels is a slice of Label.

func NewLabels

func NewLabels(attrs []string) (Labels, error)

NewLabels creates a slice of Label for given attributes.

func (*Labels) Add

func (labels *Labels) Add(label Label) error

Add will add a new attribute, with validation of all attributes.

func (*Labels) Restore

func (labels *Labels) Restore() string

Restore converts Attributes to a string.

type Rule

type Rule struct {
	ID       string        `json:"id"`
	Index    int           `json:"index"`
	Labels   Labels        `json:"labels"`
	RuleType string        `json:"rule_type"`
	Data     []interface{} `json:"data"`
}

Rule is used to establish the relationship between labels and a key range.

func NewRule

func NewRule() *Rule

NewRule creates a rule.

func (*Rule) ApplyAttributesSpec

func (r *Rule) ApplyAttributesSpec(spec *ast.AttributesSpec) error

ApplyAttributesSpec will transfer attributes defined in AttributesSpec to the labels.

func (*Rule) Clone

func (r *Rule) Clone() *Rule

Clone clones a rule.

func (*Rule) Reset

func (r *Rule) Reset(dbName, tableName, partName string, ids ...int64) *Rule

Reset will reset the label rule for a table/partition with a given ID and names.

func (*Rule) String

func (r *Rule) String() string

String implements fmt.Stringer.

type RulePatch

type RulePatch struct {
	SetRules    []*Rule  `json:"sets"`
	DeleteRules []string `json:"deletes"`
}

RulePatch is the patch to update the label rules.

func NewRulePatch

func NewRulePatch(setRules []*Rule, deleteRules []string) *RulePatch

NewRulePatch returns a patch of rules which need to be set or deleted.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL