Documentation ¶
Index ¶
- Constants
- Variables
- func AddInt64(a int64, b int64) (int64, error)
- func AddInteger(a uint64, b int64) (uint64, error)
- func AddUint64(a uint64, b uint64) (uint64, error)
- func CalculateSum(sum interface{}, v interface{}) (interface{}, error)
- func Compare(a, b interface{}) (int, error)
- func CompareFloat64(x, y float64) int
- func CompareInt64(x, y int64) int
- func CompareString(x, y string) int
- func CompareUint64(x, y uint64) int
- func Convert(val interface{}, target *FieldType) (v interface{}, err error)
- func ConvertDatumToDecimal(d Datum) (mysql.Decimal, error)
- func DatumsToInterfaces(datums []Datum) []interface{}
- func DefaultCharsetForType(tp byte) (string, string)
- func DivInt64(a int64, b int64) (int64, error)
- func DivIntWithUint(a int64, b uint64) (uint64, error)
- func DivUintWithInt(a uint64, b int64) (uint64, error)
- func EOFAsNil(err error) error
- func EqualDatums(a []Datum, b []Datum) (bool, error)
- func InvOp2(x, y interface{}, o opcode.Op) (interface{}, error)
- func IsTypeBlob(tp byte) bool
- func IsTypeChar(tp byte) bool
- func MergeFieldType(a byte, b byte) byte
- func MulInt64(a int64, b int64) (int64, error)
- func MulInteger(a uint64, b int64) (uint64, error)
- func MulUint64(a uint64, b uint64) (uint64, error)
- func Round(f float64, dec int) float64
- func RoundFloat(f float64) float64
- func SortDatums(datums []Datum) error
- func StrToFloat(str string) (float64, error)
- func StrToInt(str string) (int64, error)
- func SubInt64(a int64, b int64) (int64, error)
- func SubIntWithUint(a int64, b uint64) (uint64, error)
- func SubUint64(a uint64, b uint64) (uint64, error)
- func SubUintWithInt(a uint64, b int64) (uint64, error)
- func ToString(value interface{}) (string, error)
- func TruncateFloat(f float64, flen int, decimal int) (float64, error)
- func TypeStr(tp byte) (r string)
- func TypeToStr(tp byte, cs string) (r string)
- type Datum
- func CoerceArithmetic(a Datum) (d Datum, err error)
- func CoerceDatum(a, b Datum) (x, y Datum)
- func ComputeDiv(a, b Datum) (d Datum, err error)
- func ComputeIntDiv(a, b Datum) (d Datum, err error)
- func ComputeMinus(a, b Datum) (d Datum, err error)
- func ComputeMod(a, b Datum) (d Datum, err error)
- func ComputeMul(a, b Datum) (d Datum, err error)
- func ComputePlus(a, b Datum) (d Datum, err error)
- func MakeDatums(args ...interface{}) []Datum
- func MaxValueDatum() Datum
- func MinNotNullDatum() Datum
- func NewBytesDatum(b []byte) (d Datum)
- func NewDatum(in interface{}) (d Datum)
- func NewDecimalDatum(dec mysql.Decimal) (d Datum)
- func NewDurationDatum(dur mysql.Duration) (d Datum)
- func NewFloat32Datum(f float32) (d Datum)
- func NewFloat64Datum(f float64) (d Datum)
- func NewIntDatum(i int64) (d Datum)
- func NewStringDatum(s string) (d Datum)
- func NewUintDatum(i uint64) (d Datum)
- func (d *Datum) Cast(target *FieldType) (ad Datum, err error)
- func (d *Datum) CompareDatum(ad Datum) (int, error)
- func (d *Datum) ConvertTo(target *FieldType) (Datum, error)
- func (d *Datum) GetBytes() []byte
- func (d *Datum) GetFloat32() float32
- func (d *Datum) GetFloat64() float64
- func (d *Datum) GetInt64() int64
- func (d *Datum) GetInterface() interface{}
- func (d *Datum) GetMysqlBit() mysql.Bit
- func (d *Datum) GetMysqlDecimal() mysql.Decimal
- func (d *Datum) GetMysqlDuration() mysql.Duration
- func (d *Datum) GetMysqlEnum() mysql.Enum
- func (d *Datum) GetMysqlHex() mysql.Hex
- func (d *Datum) GetMysqlSet() mysql.Set
- func (d *Datum) GetMysqlTime() mysql.Time
- func (d *Datum) GetRow() []Datum
- func (d *Datum) GetString() string
- func (d *Datum) GetUint64() uint64
- func (d *Datum) GetValue() interface{}
- func (d *Datum) IsNull() bool
- func (d *Datum) Kind() byte
- func (d *Datum) SetBytes(b []byte)
- func (d *Datum) SetBytesAsString(b []byte)
- func (d *Datum) SetFloat32(f float32)
- func (d *Datum) SetFloat64(f float64)
- func (d *Datum) SetInt64(i int64)
- func (d *Datum) SetInterface(x interface{})
- func (d *Datum) SetMysqlBit(b mysql.Bit)
- func (d *Datum) SetMysqlDecimal(b mysql.Decimal)
- func (d *Datum) SetMysqlDuration(b mysql.Duration)
- func (d *Datum) SetMysqlEnum(b mysql.Enum)
- func (d *Datum) SetMysqlHex(b mysql.Hex)
- func (d *Datum) SetMysqlSet(b mysql.Set)
- func (d *Datum) SetMysqlTime(b mysql.Time)
- func (d *Datum) SetNull()
- func (d *Datum) SetRow(ds []Datum)
- func (d *Datum) SetString(s string)
- func (d *Datum) SetUint64(i uint64)
- func (d *Datum) SetValue(val interface{})
- func (d *Datum) ToBool() (int64, error)
- func (d *Datum) ToDecimal() (mysql.Decimal, error)
- func (d *Datum) ToFloat64() (float64, error)
- func (d *Datum) ToInt64() (int64, error)
- func (d *Datum) ToString() (string, error)
- type FieldType
Constants ¶
const ( KindNull byte = 0 KindInt64 byte = iota + 1 KindUint64 KindFloat32 KindFloat64 KindString KindBytes KindMysqlBit KindMysqlDecimal KindMysqlDuration KindMysqlEnum KindMysqlHex KindMysqlSet KindMysqlTime KindRow KindInterface KindMinNotNull KindMaxValue )
Kind constants.
const (
UnspecifiedLength int = -1
)
UnspecifiedLength is unspecified length.
Variables ¶
var ErrArithOverflow = errors.New("operation overflow")
ErrArithOverflow is the error for arthimetic operation overflow.
var ( // ErrValueTruncated is used when a value has been truncated during conversion. ErrValueTruncated = errors.New("value has been truncated") )
Functions ¶
func AddInteger ¶
AddInteger adds uint64 a and int64 b and returns uint64 if no overflow error.
func CalculateSum ¶
func CalculateSum(sum interface{}, v interface{}) (interface{}, error)
CalculateSum adds v to sum.
func Compare ¶
Compare returns an integer comparing the interface a with b. a > b -> 1 a = b -> 0 a < b -> -1
func CompareFloat64 ¶
CompareFloat64 returns an integer comparing the float64 x to y.
func CompareInt64 ¶
CompareInt64 returns an integer comparing the int64 x to y.
func CompareString ¶
CompareString returns an integer comparing the string x to y.
func CompareUint64 ¶
CompareUint64 returns an integer comparing the uint64 x to y.
func ConvertDatumToDecimal ¶
ConvertDatumToDecimal converts datum to decimal.
func DatumsToInterfaces ¶
func DatumsToInterfaces(datums []Datum) []interface{}
DatumsToInterfaces converts a datum slice to interface slice.
func DefaultCharsetForType ¶
DefaultCharsetForType returns the default charset/collation for mysql type.
func DivInt64 ¶
DivInt64 divides int64 a with b, returns int64 if no overflow error. It just checks overflow, if b is zero, a "divide by zero" panic throws.
func DivIntWithUint ¶
DivIntWithUint divides int64 a with uint64 b, returns uint64 if no overflow error. It just checks overflow, if b is zero, a "divide by zero" panic throws.
func DivUintWithInt ¶
DivUintWithInt divides uint64 a with int64 b, returns uint64 if no overflow error. It just checks overflow, if b is zero, a "divide by zero" panic throws.
func EqualDatums ¶
EqualDatums compare if a and b contains the same datum values.
func IsTypeBlob ¶
IsTypeBlob returns a boolean indicating whether the tp is a blob type.
func IsTypeChar ¶
IsTypeChar returns a boolean indicating whether the tp is the char type like a string type or a varchar type.
func MergeFieldType ¶
MergeFieldType merges two MySQL type to a new type. This is used in hybrid field type expression. For example "select case c when 1 then 2 when 2 then 'tidb' from t;" The resule field type of the case expression is the merged type of the two when clause. See https://github.com/mysql/mysql-server/blob/5.7/sql/field.cc#L1042
func MulInteger ¶
MulInteger multiplies uint64 a and int64 b, and returns uint64 if no overflow error.
func Round ¶
Round rounds the argument f to dec decimal places. dec defaults to 0 if not specified. dec can be negative to cause dec digits left of the decimal point of the value f to become zero.
func RoundFloat ¶
RoundFloat rounds float val to the nearest integer value with float64 format, like MySQL Round function. RoundFloat uses default rounding mode, see https://dev.mysql.com/doc/refman/5.7/en/precision-math-rounding.html so rounding use "round half away from zero". e.g, 1.5 -> 2, -1.5 -> -2.
func StrToFloat ¶
StrToFloat converts a string to a float64 in best effort.
func StrToInt ¶
StrToInt converts a string to an integer in best effort. TODO: handle overflow and add unittest.
func SubIntWithUint ¶
SubIntWithUint subtracts int64 a with uint64 b and returns uint64 if no overflow error.
func SubUintWithInt ¶
SubUintWithInt subtracts uint64 a with int64 b and returns uint64 if no overflow error.
func TruncateFloat ¶
TruncateFloat tries to truncate f. If the result exceeds the max/min float that flen/decimal allowed, returns the max/min float allowed.
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 CoerceArithmetic ¶
CoerceArithmetic converts datum to appropriate datum for arithmetic computing.
func CoerceDatum ¶
CoerceDatum changes type. If a or b is Decimal, changes the both to Decimal. Else if a or b is Float, changes the both to Float.
func ComputeDiv ¶
ComputeDiv computes the result of a/b.
func ComputeIntDiv ¶
ComputeIntDiv computes the result of a / b, both a and b are integer.
func ComputeMinus ¶
ComputeMinus computes the result of a-b.
func ComputeMod ¶
ComputeMod computes the result of a mod b.
func ComputeMul ¶
ComputeMul computes the result of a*b.
func ComputePlus ¶
ComputePlus computes the result of a+b.
func MakeDatums ¶
func MakeDatums(args ...interface{}) []Datum
MakeDatums creates datum slice from interfaces.
func MinNotNullDatum ¶
func MinNotNullDatum() Datum
MinNotNullDatum returns a datum represents minimum not null value.
func NewBytesDatum ¶
NewBytesDatum creates a new Datum from a byte slice.
func NewDatum ¶
func NewDatum(in interface{}) (d Datum)
NewDatum creates a new Datum from an interface{}.
func NewDecimalDatum ¶
NewDecimalDatum creates a new Datum form a mysql.Decimal value.
func NewDurationDatum ¶
NewDurationDatum creates a new Datum from a mysql.Duration value.
func NewFloat32Datum ¶
NewFloat32Datum creates a new Datum from a float32 value.
func NewFloat64Datum ¶
NewFloat64Datum creates a new Datum from a float64 value.
func NewIntDatum ¶
NewIntDatum creates a new Datum from an int64 value.
func NewStringDatum ¶
NewStringDatum creates a new Datum from a string.
func NewUintDatum ¶
NewUintDatum creates a new Datum from an uint64 value.
func (*Datum) CompareDatum ¶
CompareDatum compares datum to another datum. TODO: return error properly.
func (*Datum) GetInterface ¶
func (d *Datum) GetInterface() interface{}
GetInterface gets interface value.
func (*Datum) GetMysqlBit ¶
GetMysqlBit gets mysql.Bit value
func (*Datum) GetMysqlDecimal ¶
GetMysqlDecimal gets mysql.Decimal value
func (*Datum) GetMysqlDuration ¶
GetMysqlDuration gets mysql.Duration value
func (*Datum) GetMysqlEnum ¶
GetMysqlEnum gets mysql.Enum value
func (*Datum) GetMysqlHex ¶
GetMysqlHex gets mysql.Hex value
func (*Datum) GetMysqlSet ¶
GetMysqlSet gets mysql.Set value
func (*Datum) GetMysqlTime ¶
GetMysqlTime gets mysql.Time value
func (*Datum) GetValue ¶
func (d *Datum) GetValue() interface{}
GetValue gets the value of the datum of any kind.
func (*Datum) SetBytesAsString ¶
SetBytesAsString sets bytes value to datum as string type.
func (*Datum) SetInterface ¶
func (d *Datum) SetInterface(x interface{})
SetInterface sets interface to datum.
func (*Datum) SetMysqlBit ¶
SetMysqlBit sets mysql.Bit value
func (*Datum) SetMysqlDecimal ¶
SetMysqlDecimal sets mysql.Decimal value
func (*Datum) SetMysqlDuration ¶
SetMysqlDuration sets mysql.Duration value
func (*Datum) SetMysqlEnum ¶
SetMysqlEnum sets mysql.Enum value
func (*Datum) SetMysqlHex ¶
SetMysqlHex sets mysql.Hex value
func (*Datum) SetMysqlSet ¶
SetMysqlSet sets mysql.Set value
func (*Datum) SetMysqlTime ¶
SetMysqlTime sets mysql.Time value
type FieldType ¶
type FieldType struct { Tp byte Flag uint Flen int Decimal int Charset string Collate string // Elems is the element list for enum and set type. Elems []string }
FieldType records field type information.
func DefaultTypeForValue ¶
func DefaultTypeForValue(value interface{}) *FieldType
DefaultTypeForValue returns the default FieldType for the value.
func NewFieldType ¶
NewFieldType returns a FieldType, with a type and other information about field type.
func (*FieldType) CompactStr ¶
CompactStr only considers Tp/CharsetBin/Flen/Deimal. This is used for showing column type in infoschema.