collate

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLen = 0
)

DefaultLen is set for datum if the string datum don't know its length.

Variables

View Source
var (

	// ErrUnsupportedCollation is returned when an unsupported collation is specified.
	ErrUnsupportedCollation = terror.ClassDDL.New(mysql.ErrUnknownCollation, "Unsupported collation when new collation is enabled: '%-.64s'")
	// ErrIllegalMixCollation is returned when illegal mix of collations.
	ErrIllegalMixCollation = terror.ClassExpression.New(mysql.ErrCantAggregate2collations, mysql.MySQLErrName[mysql.ErrCantAggregate2collations])
)

Functions

func CollationID2Name

func CollationID2Name(id int32) string

CollationID2Name return the collation name by the given id. If the id is not found in the map, the default collation is returned.

func CompatibleCollate

func CompatibleCollate(collate1, collate2 string) bool

CompatibleCollate checks whether the two collate are the same.

func EnableNewCollations

func EnableNewCollations()

EnableNewCollations enables the new collation.

func GetCollationByName

func GetCollationByName(name string) (coll *charset.Collation, err error)

GetCollationByName wraps charset.GetCollationByName, it checks the collation.

func GetSupportedCollations

func GetSupportedCollations() []*charset.Collation

GetSupportedCollations gets information for all collations supported so far.

func IsCICollation

func IsCICollation(collate string) bool

IsCICollation returns if the collation is case-sensitive

func NewCollationEnabled

func NewCollationEnabled() bool

NewCollationEnabled returns if the new collations are enabled.

func RestoreCollationIDIfNeeded

func RestoreCollationIDIfNeeded(id int32) int32

RestoreCollationIDIfNeeded restores a collation id if the new collations are enabled.

func RewriteNewCollationIDIfNeeded

func RewriteNewCollationIDIfNeeded(id int32) int32

RewriteNewCollationIDIfNeeded rewrites a collation id if the new collations are enabled. When new collations are enabled, we turn the collation id to negative so that other the components of the cluster(for example, TiKV) is able to aware of it without any change to the protocol definition. When new collations are not enabled, collation id remains the same.

func SetNewCollationEnabledForTest

func SetNewCollationEnabledForTest(flag bool)

SetNewCollationEnabledForTest sets if the new collation are enabled in test. Note: Be careful to use this function, if this functions is used in tests, make sure the tests are serial.

Types

type Collator

type Collator interface {
	// Compare returns an integer comparing the two strings. The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
	Compare(a, b string) int
	// Key returns the collate key for str. If the collation is padding, make sure the PadLen >= len(rune[]str) in opt.
	Key(str string) []byte
	// Pattern get a collation-aware WildcardPattern.
	Pattern() WildcardPattern
}

Collator provides functionality for comparing strings for a given collation order.

func GetCollator

func GetCollator(collate string) Collator

GetCollator get the collator according to collate, it will return the binary collator if the corresponding collator doesn't exist.

func GetCollatorByID

func GetCollatorByID(id int) Collator

GetCollatorByID get the collator according to id, it will return the binary collator if the corresponding collator doesn't exist.

type WildcardPattern

type WildcardPattern interface {
	// Compile compiles the patternStr with specified escape character.
	Compile(patternStr string, escape byte)
	// DoMatch tries to match the str with compiled pattern, `Compile()` must be called before calling it.
	DoMatch(str string) bool
}

WildcardPattern is the interface used for wildcard pattern match.

Jump to

Keyboard shortcuts

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