collate

package
v1.1.0-beta.0...-ec288d9 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultLen is set for datum if the string datum don't know its length.
	DefaultLen = 0
)

Variables

View Source
var (

	// ErrUnsupportedCollation is returned when an unsupported collation is specified.
	ErrUnsupportedCollation = dbterror.ClassDDL.NewStdErr(mysql.ErrUnknownCollation, mysql.Message("Unsupported collation when new collation is enabled: '%-.64s'", nil))
	// ErrIllegalMixCollation is returned when illegal mix of collations.
	ErrIllegalMixCollation = dbterror.ClassExpression.NewStd(mysql.ErrCantAggregateNcollations)
	// ErrIllegalMix2Collation is returned when illegal mix of 2 collations.
	ErrIllegalMix2Collation = dbterror.ClassExpression.NewStd(mysql.ErrCantAggregate2collations)
	// ErrIllegalMix3Collation is returned when illegal mix of 3 collations.
	ErrIllegalMix3Collation = dbterror.ClassExpression.NewStd(mysql.ErrCantAggregate3collations)
)

Functions

func CanUseRawMemAsKey

func CanUseRawMemAsKey(c Collator) bool

CanUseRawMemAsKey returns true if current collator can use the original raw memory as the key only return true for binCollator and derivedBinCollator

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 CollationName2ID

func CollationName2ID(name string) int

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

func CollationToProto

func CollationToProto(c string) int32

CollationToProto converts collation from string to int32(used by protocol).

func CompatibleCollate

func CompatibleCollate(collate1, collate2 string) bool

CompatibleCollate checks whether the two collate are the same.

func ConvertAndGetBinCollation

func ConvertAndGetBinCollation(collate string) string

ConvertAndGetBinCollation converts collation to binary 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 IsBinCollation

func IsBinCollation(collate string) bool

IsBinCollation returns if the collation is 'xx_bin' or 'bin'. The function is to determine whether the sortkey of a char type of data under the collation is equal to the data itself, and both xx_bin and collationBin are satisfied.

func IsCICollation

func IsCICollation(collate string) bool

IsCICollation returns if the collation is case-insensitive

func IsDefaultCollationForUTF8MB4

func IsDefaultCollationForUTF8MB4(collate string) bool

IsDefaultCollationForUTF8MB4 returns if the collation is DefaultCollationForUTF8MB4.

func IsPadSpaceCollation

func IsPadSpaceCollation(collation string) bool

IsPadSpaceCollation returns whether the collation is a PAD SPACE collation.

func NewCollationEnabled

func NewCollationEnabled() bool

NewCollationEnabled returns if the new collations are enabled.

func ProtoToCollation

func ProtoToCollation(c int32) string

ProtoToCollation converts collation from int32(used by protocol) to string.

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.

func SubstituteMissingCollationToDefault

func SubstituteMissingCollationToDefault(co string) string

SubstituteMissingCollationToDefault will switch to the default collation if new collations are enabled and the specified collation is not supported.

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
	// KeyWithoutTrimRightSpace returns the collate key for str. The difference with Key is str will not be trimed.
	KeyWithoutTrimRightSpace(str string) []byte
	// Pattern get a collation-aware WildcardPattern.
	Pattern() WildcardPattern
	// Clone returns a copy of the collator.
	Clone() Collator
}

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

func ConvertAndGetBinCollator

func ConvertAndGetBinCollator(collate string) Collator

ConvertAndGetBinCollator converts collation to binary collator

func GetBinaryCollator

func GetBinaryCollator() Collator

GetBinaryCollator gets the binary collator, it is often used when we want to apply binary compare.

func GetBinaryCollatorSlice

func GetBinaryCollatorSlice(n int) []Collator

GetBinaryCollatorSlice gets the binary collator slice with len n.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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