types

package
v0.0.0-...-eed5818 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2020 License: Apache-2.0 Imports: 19 Imported by: 74

Documentation

Index

Constants

View Source
const (
	KindNull          byte = 0
	KindInt64         byte = 1
	KindUint64        byte = 2
	KindFloat32       byte = 3
	KindFloat64       byte = 4
	KindString        byte = 5
	KindBytes         byte = 6
	KindBinaryLiteral byte = 7 // Used for BIT / HEX literals.
	KindMysqlDecimal  byte = 8
	KindMysqlDuration byte = 9
	KindMysqlEnum     byte = 10
	KindMysqlBit      byte = 11 // Used for BIT table column values.
	KindMysqlSet      byte = 12
	KindMysqlTime     byte = 13
	KindInterface     byte = 14
	KindMinNotNull    byte = 15
	KindMaxValue      byte = 16
	KindRaw           byte = 17
	KindMysqlJSON     byte = 18
)

Kind constants.

Variables

This section is empty.

Functions

func CompareDuration

func CompareDuration(x, y time.Duration) int

CompareDuration returns an integer comparing the duration x to y.

func CompareFloat64

func CompareFloat64(x, y float64) int

CompareFloat64 returns an integer comparing the float64 x to y.

func CompareInt64

func CompareInt64(x, y int64) int

CompareInt64 returns an integer comparing the int64 x to y.

func CompareString

func CompareString(x, y, collation string) int

CompareString returns an integer comparing the string x to y with the specified collation and length.

func CompareUint64

func CompareUint64(x, y uint64) int

CompareUint64 returns an integer comparing the uint64 x to y.

func ConvertDecimalToUint

func ConvertDecimalToUint(sc *stmtctx.StatementContext, d *MyDecimal, upperBound uint64, tp byte) (uint64, error)

ConvertDecimalToUint converts a decimal to a uint by converting it to a string first to avoid float overflow (#10181).

func ConvertFloatToInt

func ConvertFloatToInt(fval float64, lowerBound, upperBound int64, tp byte) (int64, error)

ConvertFloatToInt converts a float64 value to a int value. `tp` is used in err msg, if there is overflow, this func will report err according to `tp`

func ConvertFloatToUint

func ConvertFloatToUint(sc *stmtctx.StatementContext, fval float64, upperBound uint64, tp byte) (uint64, error)

ConvertFloatToUint converts a float value to an uint value.

func ConvertIntToInt

func ConvertIntToInt(val int64, lowerBound int64, upperBound int64, tp byte) (int64, error)

ConvertIntToInt converts an int value to another int value of different precision.

func ConvertIntToUint

func ConvertIntToUint(sc *stmtctx.StatementContext, val int64, upperBound uint64, tp byte) (uint64, error)

ConvertIntToUint converts an int value to an uint value.

func ConvertJSONToFloat

func ConvertJSONToFloat(sc *stmtctx.StatementContext, j json.BinaryJSON) (float64, error)

ConvertJSONToFloat casts JSON into float64.

func ConvertJSONToInt

func ConvertJSONToInt(sc *stmtctx.StatementContext, j json.BinaryJSON, unsigned bool) (int64, error)

ConvertJSONToInt casts JSON into int64.

func ConvertUintToInt

func ConvertUintToInt(val uint64, upperBound int64, tp byte) (int64, error)

ConvertUintToInt converts an uint value to an int value.

func ConvertUintToUint

func ConvertUintToUint(val uint64, upperBound uint64, tp byte) (uint64, error)

ConvertUintToUint converts an uint value to another uint value of different precision.

func DatumsToStrNoErr

func DatumsToStrNoErr(datums []Datum) string

DatumsToStrNoErr converts some datums to a formatted string. If an error occurs, it will print a log instead of returning an error.

func DatumsToString

func DatumsToString(datums []Datum, handleSpecialValue bool) (string, error)

DatumsToString converts several datums to formatted string.

func EqualDatums

func EqualDatums(sc *stmtctx.StatementContext, a []Datum, b []Datum) (bool, error)

EqualDatums compare if a and b contains the same datum values.

func EstimatedMemUsage

func EstimatedMemUsage(array []Datum, numOfRows int) int64

EstimatedMemUsage returns the estimated bytes consumed of a one-dimensional or two-dimensional datum array.

func IntergerSignedLowerBound

func IntergerSignedLowerBound(intType byte) int64

IntergerSignedLowerBound indicates the min int64 values of different mysql types.

func IntergerSignedUpperBound

func IntergerSignedUpperBound(intType byte) int64

IntergerSignedUpperBound indicates the max int64 values of different mysql types.

func IntergerUnsignedUpperBound

func IntergerUnsignedUpperBound(intType byte) uint64

IntergerUnsignedUpperBound indicates the max uint64 values of different mysql types.

func ProduceFloatWithSpecifiedTp

func ProduceFloatWithSpecifiedTp(f float64, target *FieldType, sc *stmtctx.StatementContext) (_ float64, err error)

ProduceFloatWithSpecifiedTp produces a new float64 according to `flen` and `decimal`.

func ProduceStrWithSpecifiedTp

func ProduceStrWithSpecifiedTp(s string, tp *FieldType, sc *stmtctx.StatementContext, padZero bool) (_ string, err error)

ProduceStrWithSpecifiedTp produces a new string according to `flen` and `chs`. Param `padZero` indicates whether we should pad `\0` for `binary(flen)` type.

func SortDatums

func SortDatums(sc *stmtctx.StatementContext, datums []Datum) error

SortDatums sorts a slice of datum.

func StrToDuration

func StrToDuration(sc *stmtctx.StatementContext, str string, fsp int8) (d Duration, t Time, isDuration bool, err error)

StrToDuration converts str to Duration. It returns Duration in normal case, and returns Time when str is in datetime format. when isDuration is true, the d is returned, when it is false, the t is returned. See https://dev.mysql.com/doc/refman/5.5/en/date-and-time-literals.html.

func StrToFloat

func StrToFloat(sc *stmtctx.StatementContext, str string, isFuncCast bool) (float64, error)

StrToFloat converts a string to a float64 at the best-effort.

func StrToInt

func StrToInt(sc *stmtctx.StatementContext, str string, isFuncCast bool) (int64, error)

StrToInt converts a string to an integer at the best-effort.

func StrToUint

func StrToUint(sc *stmtctx.StatementContext, str string, isFuncCast bool) (uint64, error)

StrToUint converts a string to an unsigned integer at the best-effortt.

func ToString

func ToString(value interface{}) (string, error)

ToString converts an interface to a string.

func VecCompareII

func VecCompareII(x, y, res []int64)

VecCompareII returns []int64 comparing the []int64 x to []int64 y

func VecCompareIU

func VecCompareIU(x []int64, y []uint64, res []int64)

VecCompareIU returns []int64 comparing the []int64 x to []uint64y

func VecCompareUI

func VecCompareUI(x []uint64, y, res []int64)

VecCompareUI returns []int64 comparing the []uint64 x to []int64y

func VecCompareUU

func VecCompareUU(x, y []uint64, res []int64)

VecCompareUU returns []int64 comparing the []uint64 x to []uint64 y

Types

type Datum

type Datum struct {
	// contains filtered or unexported fields
}

Datum is a data box holds different kind of data. It has better performance and is easier to use than `interface{}`.

func ChangeReverseResultByUpperLowerBound

func ChangeReverseResultByUpperLowerBound(
	sc *stmtctx.StatementContext,
	retType *FieldType,
	res Datum,
	rType RoundingType) (Datum, error)

ChangeReverseResultByUpperLowerBound is for expression's reverse evaluation. Here is an example for what's effort for the function: CastRealAsInt(t.a),

		if the type of column `t.a` is mysql.TypeDouble, and there is a row that t.a == MaxFloat64
		then the cast function will arrive a result MaxInt64. But when we do the reverse evaluation,
     if the result is MaxInt64, and the rounding type is ceiling. Then we should get the MaxFloat64
     instead of float64(MaxInt64).

Another example: cast(1.1 as signed) = 1,

when we get the answer 1, we can only reversely evaluate 1.0 as the column value. So in this
case, we should judge whether the rounding type are ceiling. If it is, then we should plus one for
1.0 and get the reverse result 2.0.

func CloneRow

func CloneRow(dr []Datum) []Datum

CloneRow deep copies a Datum slice.

func GetMaxValue

func GetMaxValue(ft *FieldType) (max Datum)

GetMaxValue returns the max value datum for each type.

func GetMinValue

func GetMinValue(ft *FieldType) (min Datum)

GetMinValue returns the min value datum for each type.

func MakeDatums

func MakeDatums(args ...interface{}) []Datum

MakeDatums creates datum slice from interfaces.

func MaxValueDatum

func MaxValueDatum() Datum

MaxValueDatum returns a datum represents max value.

func MinNotNullDatum

func MinNotNullDatum() Datum

MinNotNullDatum returns a datum represents minimum not null value.

func NewBinaryLiteralDatum

func NewBinaryLiteralDatum(b BinaryLiteral) (d Datum)

NewBinaryLiteralDatum creates a new BinaryLiteral Datum for a BinaryLiteral value.

func NewBytesDatum

func NewBytesDatum(b []byte) (d Datum)

NewBytesDatum creates a new Datum from a byte slice.

func NewCollateMysqlEnumDatum

func NewCollateMysqlEnumDatum(e Enum, collation string) (d Datum)

NewCollateMysqlEnumDatum create a new MysqlEnum Datum for a Enum value with collation information.

func NewCollationStringDatum

func NewCollationStringDatum(s string, collation string, length int) (d Datum)

NewCollationStringDatum creates a new Datum from a string with collation and length info.

func NewDatum

func NewDatum(in interface{}) (d Datum)

NewDatum creates a new Datum from an interface{}.

func NewDecimalDatum

func NewDecimalDatum(dec *MyDecimal) (d Datum)

NewDecimalDatum creates a new Datum from a MyDecimal value.

func NewDurationDatum

func NewDurationDatum(dur Duration) (d Datum)

NewDurationDatum creates a new Datum from a Duration value.

func NewFloat32Datum

func NewFloat32Datum(f float32) (d Datum)

NewFloat32Datum creates a new Datum from a float32 value.

func NewFloat64Datum

func NewFloat64Datum(f float64) (d Datum)

NewFloat64Datum creates a new Datum from a float64 value.

func NewIntDatum

func NewIntDatum(i int64) (d Datum)

NewIntDatum creates a new Datum from an int64 value.

func NewJSONDatum

func NewJSONDatum(j json.BinaryJSON) (d Datum)

NewJSONDatum creates a new Datum from a BinaryJSON value

func NewMysqlBitDatum

func NewMysqlBitDatum(b BinaryLiteral) (d Datum)

NewMysqlBitDatum creates a new MysqlBit Datum for a BinaryLiteral value.

func NewMysqlEnumDatum

func NewMysqlEnumDatum(e Enum) (d Datum)

NewMysqlEnumDatum creates a new MysqlEnum Datum for a Enum value.

func NewMysqlSetDatum

func NewMysqlSetDatum(e Set, collation string) (d Datum)

NewMysqlSetDatum creates a new MysqlSet Datum for a Enum value.

func NewStringDatum

func NewStringDatum(s string) (d Datum)

NewStringDatum creates a new Datum from a string.

func NewTimeDatum

func NewTimeDatum(t Time) (d Datum)

NewTimeDatum creates a new Time from a Time value.

func NewUintDatum

func NewUintDatum(i uint64) (d Datum)

NewUintDatum creates a new Datum from an uint64 value.

func (*Datum) Clone

func (d *Datum) Clone() *Datum

Clone create a deep copy of the Datum.

func (*Datum) Collation

func (d *Datum) Collation() string

Collation gets the collation of the datum.

func (*Datum) CompareDatum

func (d *Datum) CompareDatum(sc *stmtctx.StatementContext, ad *Datum) (int, error)

CompareDatum compares datum to another datum. TODO: return error properly.

func (*Datum) ConvertTo

func (d *Datum) ConvertTo(sc *stmtctx.StatementContext, target *FieldType) (Datum, error)

ConvertTo converts a datum to the target field type. change this method need sync modification to type2Kind in rowcodec/types.go

func (*Datum) Copy

func (d *Datum) Copy(dst *Datum)

Copy deep copies a Datum into destination.

func (*Datum) Frac

func (d *Datum) Frac() int

Frac gets the frac of the datum.

func (*Datum) GetBinaryLiteral

func (d *Datum) GetBinaryLiteral() BinaryLiteral

GetBinaryLiteral gets Bit value

func (*Datum) GetBytes

func (d *Datum) GetBytes() []byte

GetBytes gets bytes value.

func (*Datum) GetFloat32

func (d *Datum) GetFloat32() float32

GetFloat32 gets float32 value.

func (*Datum) GetFloat64

func (d *Datum) GetFloat64() float64

GetFloat64 gets float64 value.

func (*Datum) GetInt64

func (d *Datum) GetInt64() int64

GetInt64 gets int64 value.

func (*Datum) GetInterface

func (d *Datum) GetInterface() interface{}

GetInterface gets interface value.

func (*Datum) GetMysqlBit

func (d *Datum) GetMysqlBit() BinaryLiteral

GetMysqlBit gets MysqlBit value

func (*Datum) GetMysqlDecimal

func (d *Datum) GetMysqlDecimal() *MyDecimal

GetMysqlDecimal gets Decimal value

func (*Datum) GetMysqlDuration

func (d *Datum) GetMysqlDuration() Duration

GetMysqlDuration gets Duration value

func (*Datum) GetMysqlEnum

func (d *Datum) GetMysqlEnum() Enum

GetMysqlEnum gets Enum value

func (*Datum) GetMysqlJSON

func (d *Datum) GetMysqlJSON() json.BinaryJSON

GetMysqlJSON gets json.BinaryJSON value

func (*Datum) GetMysqlSet

func (d *Datum) GetMysqlSet() Set

GetMysqlSet gets Set value

func (*Datum) GetMysqlTime

func (d *Datum) GetMysqlTime() Time

GetMysqlTime gets types.Time value

func (*Datum) GetRaw

func (d *Datum) GetRaw() []byte

GetRaw gets raw value.

func (*Datum) GetString

func (d *Datum) GetString() string

GetString gets string value.

func (*Datum) GetUint64

func (d *Datum) GetUint64() uint64

GetUint64 gets uint64 value.

func (*Datum) GetValue

func (d *Datum) GetValue() interface{}

GetValue gets the value of the datum of any kind.

func (*Datum) IsNull

func (d *Datum) IsNull() bool

IsNull checks if datum is null.

func (*Datum) Kind

func (d *Datum) Kind() byte

Kind gets the kind of the datum.

func (*Datum) Length

func (d *Datum) Length() int

Length gets the length of the datum.

func (*Datum) SetAutoID

func (d *Datum) SetAutoID(id int64, flag uint)

SetAutoID set the auto increment ID according to its int flag.

func (*Datum) SetBinaryLiteral

func (d *Datum) SetBinaryLiteral(b BinaryLiteral)

SetBinaryLiteral sets Bit value

func (*Datum) SetBytes

func (d *Datum) SetBytes(b []byte)

SetBytes sets bytes value to datum.

func (*Datum) SetBytesAsString

func (d *Datum) SetBytesAsString(b []byte, collation string, length uint32)

SetBytesAsString sets bytes value to datum as string type.

func (*Datum) SetFloat32

func (d *Datum) SetFloat32(f float32)

SetFloat32 sets float32 value.

func (*Datum) SetFloat64

func (d *Datum) SetFloat64(f float64)

SetFloat64 sets float64 value.

func (*Datum) SetFrac

func (d *Datum) SetFrac(frac int)

SetFrac sets the frac of the datum.

func (*Datum) SetInt64

func (d *Datum) SetInt64(i int64)

SetInt64 sets int64 value.

func (*Datum) SetInterface

func (d *Datum) SetInterface(x interface{})

SetInterface sets interface to datum.

func (*Datum) SetLength

func (d *Datum) SetLength(l int)

SetLength sets the length of the datum.

func (*Datum) SetMinNotNull

func (d *Datum) SetMinNotNull()

SetMinNotNull sets datum to minNotNull value.

func (*Datum) SetMysqlBit

func (d *Datum) SetMysqlBit(b BinaryLiteral)

SetMysqlBit sets MysqlBit value

func (*Datum) SetMysqlDecimal

func (d *Datum) SetMysqlDecimal(b *MyDecimal)

SetMysqlDecimal sets Decimal value

func (*Datum) SetMysqlDuration

func (d *Datum) SetMysqlDuration(b Duration)

SetMysqlDuration sets Duration value

func (*Datum) SetMysqlEnum

func (d *Datum) SetMysqlEnum(b Enum, collation string)

SetMysqlEnum sets Enum value

func (*Datum) SetMysqlJSON

func (d *Datum) SetMysqlJSON(b json.BinaryJSON)

SetMysqlJSON sets json.BinaryJSON value

func (*Datum) SetMysqlSet

func (d *Datum) SetMysqlSet(b Set, collation string)

SetMysqlSet sets Set value

func (*Datum) SetMysqlTime

func (d *Datum) SetMysqlTime(b Time)

SetMysqlTime sets types.Time value

func (*Datum) SetNull

func (d *Datum) SetNull()

SetNull sets datum to nil.

func (*Datum) SetRaw

func (d *Datum) SetRaw(b []byte)

SetRaw sets raw value.

func (*Datum) SetString

func (d *Datum) SetString(s string, collation string)

SetString sets string value.

func (*Datum) SetUint64

func (d *Datum) SetUint64(i uint64)

SetUint64 sets uint64 value.

func (*Datum) SetValue

func (d *Datum) SetValue(val interface{}, tp *types.FieldType)

SetValue sets any kind of value.

func (*Datum) SetValueWithDefaultCollation

func (d *Datum) SetValueWithDefaultCollation(val interface{})

SetValueWithDefaultCollation sets any kind of value.

func (Datum) String

func (d Datum) String() string

String returns a human-readable description of Datum. It is intended only for debugging.

func (*Datum) ToBool

func (d *Datum) ToBool(sc *stmtctx.StatementContext) (int64, error)

ToBool converts to a bool. We will use 1 for true, and 0 for false.

func (*Datum) ToBytes

func (d *Datum) ToBytes() ([]byte, error)

ToBytes gets the bytes representation of the datum.

func (*Datum) ToDecimal

func (d *Datum) ToDecimal(sc *stmtctx.StatementContext) (*MyDecimal, error)

ToDecimal converts to a decimal.

func (*Datum) ToFloat64

func (d *Datum) ToFloat64(sc *stmtctx.StatementContext) (float64, error)

ToFloat64 converts to a float64

func (*Datum) ToInt64

func (d *Datum) ToInt64(sc *stmtctx.StatementContext) (int64, error)

ToInt64 converts to a int64.

func (*Datum) ToMysqlJSON

func (d *Datum) ToMysqlJSON() (j json.BinaryJSON, err error)

ToMysqlJSON is similar to convertToMysqlJSON, except the latter parses from string, but the former uses it as primitive.

func (*Datum) ToString

func (d *Datum) ToString() (string, error)

ToString gets the string representation of the datum.

type RoundingType

type RoundingType uint8

RoundingType is used to indicate the rounding type for reversing evaluation.

const (
	// Ceiling means rounding up.
	Ceiling RoundingType = iota
	// Floor means rounding down.
	Floor
)

Jump to

Keyboard shortcuts

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