tidb: github.com/pingcap/tidb/types Index | Files | Directories

package types

import "github.com/pingcap/tidb/types"

Index

Package Files

binary_literal.go compare.go convert.go datum.go datum_eval.go enum.go errors.go etc.go eval_type.go field_name.go field_type.go fsp.go helper.go mydecimal.go mytime.go overflow.go set.go time.go

Constants

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.

const (
    // ETInt represents type INT in evaluation.
    ETInt = ast.ETInt
    // ETReal represents type REAL in evaluation.
    ETReal = ast.ETReal
    // ETDecimal represents type DECIMAL in evaluation.
    ETDecimal = ast.ETDecimal
    // ETString represents type STRING in evaluation.
    ETString = ast.ETString
    // ETDatetime represents type DATETIME in evaluation.
    ETDatetime = ast.ETDatetime
    // ETTimestamp represents type TIMESTAMP in evaluation.
    ETTimestamp = ast.ETTimestamp
    // ETDuration represents type DURATION in evaluation.
    ETDuration = ast.ETDuration
    // ETJson represents type JSON in evaluation.
    ETJson = ast.ETJson
)
const (
    // UnspecifiedFsp is the unspecified fractional seconds part.
    UnspecifiedFsp = int8(-1)
    // MaxFsp is the maximum digit of fractional seconds part.
    MaxFsp = int8(6)
    // MinFsp is the minimum digit of fractional seconds part.
    MinFsp = int8(0)
    // DefaultFsp is the default digit of fractional seconds part.
    // MySQL use 0 as the default Fsp.
    DefaultFsp = int8(0)
)
const (
    DateFormat = "2006-01-02"
    TimeFormat = "2006-01-02 15:04:05"
    // TimeFSPFormat is time format with fractional seconds precision.
    TimeFSPFormat = "2006-01-02 15:04:05.000000"
)

Time format without fractional seconds precision.

const (
    // MinYear is the minimum for mysql year type.
    MinYear int16 = 1901
    // MaxYear is the maximum for mysql year type.
    MaxYear int16 = 2155
    // MaxDuration is the maximum for duration.
    MaxDuration int64 = 838*10000 + 59*100 + 59
    // MinTime is the minimum for mysql time type.
    MinTime = -gotime.Duration(838*3600+59*60+59) * gotime.Second
    // MaxTime is the maximum for mysql time type.
    MaxTime = gotime.Duration(838*3600+59*60+59) * gotime.Second
    // ZeroDatetimeStr is the string representation of a zero datetime.
    ZeroDatetimeStr = "0000-00-00 00:00:00"
    // ZeroDateStr is the string representation of a zero date.
    ZeroDateStr = "0000-00-00"

    // TimeMaxHour is the max hour for mysql time type.
    TimeMaxHour = 838
    // TimeMaxMinute is the max minute for mysql time type.
    TimeMaxMinute = 59
    // TimeMaxSecond is the max second for mysql time type.
    TimeMaxSecond = 59
    // TimeMaxValue is the maximum value for mysql time type.
    TimeMaxValue = TimeMaxHour*10000 + TimeMaxMinute*100 + TimeMaxSecond
    // TimeMaxValueSeconds is the maximum second value for mysql time type.
    TimeMaxValueSeconds = TimeMaxHour*3600 + TimeMaxMinute*60 + TimeMaxSecond
)
const (
    // YearIndex is index of 'YEARS-MONTHS DAYS HOURS:MINUTES:SECONDS.MICROSECONDS' expr Format
    YearIndex = 0 + iota
    // MonthIndex is index of 'YEARS-MONTHS DAYS HOURS:MINUTES:SECONDS.MICROSECONDS' expr Format
    MonthIndex
    // DayIndex is index of 'YEARS-MONTHS DAYS HOURS:MINUTES:SECONDS.MICROSECONDS' expr Format
    DayIndex
    // HourIndex is index of 'YEARS-MONTHS DAYS HOURS:MINUTES:SECONDS.MICROSECONDS' expr Format
    HourIndex
    // MinuteIndex is index of 'YEARS-MONTHS DAYS HOURS:MINUTES:SECONDS.MICROSECONDS' expr Format
    MinuteIndex
    // SecondIndex is index of 'YEARS-MONTHS DAYS HOURS:MINUTES:SECONDS.MICROSECONDS' expr Format
    SecondIndex
    // MicrosecondIndex is index of 'YEARS-MONTHS DAYS HOURS:MINUTES:SECONDS.MICROSECONDS' expr Format
    MicrosecondIndex
)
const (
    // YearMonthMaxCnt is max parameters count 'YEARS-MONTHS' expr Format allowed
    YearMonthMaxCnt = 2
    // DayHourMaxCnt is max parameters count 'DAYS HOURS' expr Format allowed
    DayHourMaxCnt = 2
    // DayMinuteMaxCnt is max parameters count 'DAYS HOURS:MINUTES' expr Format allowed
    DayMinuteMaxCnt = 3
    // DaySecondMaxCnt is max parameters count 'DAYS HOURS:MINUTES:SECONDS' expr Format allowed
    DaySecondMaxCnt = 4
    // DayMicrosecondMaxCnt is max parameters count 'DAYS HOURS:MINUTES:SECONDS.MICROSECONDS' expr Format allowed
    DayMicrosecondMaxCnt = 5
    // HourMinuteMaxCnt is max parameters count 'HOURS:MINUTES' expr Format allowed
    HourMinuteMaxCnt = 2
    // HourSecondMaxCnt is max parameters count 'HOURS:MINUTES:SECONDS' expr Format allowed
    HourSecondMaxCnt = 3
    // HourMicrosecondMaxCnt is max parameters count 'HOURS:MINUTES:SECONDS.MICROSECONDS' expr Format allowed
    HourMicrosecondMaxCnt = 4
    // MinuteSecondMaxCnt is max parameters count 'MINUTES:SECONDS' expr Format allowed
    MinuteSecondMaxCnt = 2
    // MinuteMicrosecondMaxCnt is max parameters count 'MINUTES:SECONDS.MICROSECONDS' expr Format allowed
    MinuteMicrosecondMaxCnt = 3
    // SecondMicrosecondMaxCnt is max parameters count 'SECONDS.MICROSECONDS' expr Format allowed
    SecondMicrosecondMaxCnt = 2
    // TimeValueCnt is parameters count 'YEARS-MONTHS DAYS HOURS:MINUTES:SECONDS.MICROSECONDS' expr Format
    TimeValueCnt = 7
)
const (
    // GoDurationDay is the gotime.Duration which equals to a Day.
    GoDurationDay = gotime.Hour * 24
    // GoDurationWeek is the gotime.Duration which equals to a Week.
    GoDurationWeek = GoDurationDay * 7
)
const MyDecimalStructSize = 40

MyDecimalStructSize is the struct size of MyDecimal.

const (
    UnspecifiedLength = -1
)

UnspecifiedLength is unspecified length.

const VarStorageLen = ast.VarStorageLen

VarStorageLen indicates this column is a variable length column.

Variables

var (
    // ErrDataTooLong is returned when converts a string value that is longer than field type length.
    ErrDataTooLong = terror.ClassTypes.New(codeDataTooLong, "Data Too Long")
    // ErrIllegalValueForType is returned when value of type is illegal.
    ErrIllegalValueForType = terror.ClassTypes.New(codeIllegalValueForType, mysql.MySQLErrName[mysql.ErrIllegalValueForType])
    // ErrTruncated is returned when data has been truncated during conversion.
    ErrTruncated = terror.ClassTypes.New(codeTruncated, "Data Truncated")
    // ErrTruncatedWrongVal is returned when data has been truncated during conversion.
    ErrTruncatedWrongVal = terror.ClassTypes.New(codeTruncatedWrongValue, msgTruncatedWrongVal)
    // ErrOverflow is returned when data is out of range for a field type.
    ErrOverflow = terror.ClassTypes.New(codeOverflow, msgOverflow)
    // ErrDivByZero is return when do division by 0.
    ErrDivByZero = terror.ClassTypes.New(codeDivByZero, "Division by 0")
    // ErrTooBigDisplayWidth is return when display width out of range for column.
    ErrTooBigDisplayWidth = terror.ClassTypes.New(codeTooBigDisplayWidth, mysql.MySQLErrName[mysql.ErrTooBigDisplaywidth])
    // ErrTooBigFieldLength is return when column length too big for column.
    ErrTooBigFieldLength = terror.ClassTypes.New(codeTooBigFieldLength, "Too Big Field length")
    // ErrTooBigSet is returned when too many strings for column.
    ErrTooBigSet = terror.ClassTypes.New(codeTooBigSet, "Too Big Set")
    // ErrTooBigScale is returned when type DECIMAL/NUMERIC scale is bigger than mysql.MaxDecimalScale.
    ErrTooBigScale = terror.ClassTypes.New(codeTooBigScale, mysql.MySQLErrName[mysql.ErrTooBigScale])
    // ErrTooBigPrecision is returned when type DECIMAL/NUMERIC precision is bigger than mysql.MaxDecimalWidth
    ErrTooBigPrecision = terror.ClassTypes.New(codeTooBigPrecision, mysql.MySQLErrName[mysql.ErrTooBigPrecision])
    // ErrWrongFieldSpec is return when incorrect column specifier for column.
    ErrWrongFieldSpec = terror.ClassTypes.New(codeWrongFieldSpec, "Wrong Field Spec")
    // ErrBadNumber is return when parsing an invalid binary decimal number.
    ErrBadNumber = terror.ClassTypes.New(codeBadNumber, "Bad Number")
    // ErrInvalidDefault is returned when meet a invalid default value.
    ErrInvalidDefault = parser_types.ErrInvalidDefault
    // ErrInvalidFieldSize is returned when the precision of a column is out of range.
    ErrInvalidFieldSize = terror.ClassTypes.New(codeInvalidFieldSize, mysql.MySQLErrName[mysql.ErrInvalidFieldSize])
    // ErrCastAsSignedOverflow is returned when positive out-of-range integer, and convert to it's negative complement.
    ErrCastAsSignedOverflow = terror.ClassTypes.New(codeUnknown, msgCastAsSignedOverflow)
    // ErrCastNegIntAsUnsigned is returned when a negative integer be casted to an unsigned int.
    ErrCastNegIntAsUnsigned = terror.ClassTypes.New(codeUnknown, msgCastNegIntAsUnsigned)
    // ErrMBiggerThanD is returned when precision less than the scale.
    ErrMBiggerThanD = terror.ClassTypes.New(codeMBiggerThanD, mysql.MySQLErrName[mysql.ErrMBiggerThanD])
    // ErrWarnDataOutOfRange is returned when the value in a numeric column that is outside the permissible range of the column data type.
    // See https://dev.mysql.com/doc/refman/5.5/en/out-of-range-and-overflow.html for details
    ErrWarnDataOutOfRange = terror.ClassTypes.New(codeDataOutOfRange, mysql.MySQLErrName[mysql.ErrWarnDataOutOfRange])
    // ErrDuplicatedValueInType is returned when enum column has duplicated value.
    ErrDuplicatedValueInType = terror.ClassTypes.New(codeDuplicatedValueInType, mysql.MySQLErrName[mysql.ErrDuplicatedValueInType])
    // ErrDatetimeFunctionOverflow is returned when the calculation in datetime function cause overflow.
    ErrDatetimeFunctionOverflow = terror.ClassTypes.New(codeDatetimeFunctionOverflow, mysql.MySQLErrName[mysql.ErrDatetimeFunctionOverflow])
    // ErrInvalidTimeFormat is returned when the time format is not correct.
    ErrInvalidTimeFormat = terror.ClassTypes.New(mysql.ErrTruncatedWrongValue, "invalid time format: '%v'")
    // ErrInvalidWeekModeFormat is returned when the week mode is wrong.
    ErrInvalidWeekModeFormat = terror.ClassTypes.New(mysql.ErrTruncatedWrongValue, "invalid week mode format: '%v'")
    // ErrInvalidYearFormat is returned when the input is not a valid year format.
    ErrInvalidYearFormat = errors.New("invalid year format")
    // ErrInvalidYear is returned when the input value is not a valid year.
    ErrInvalidYear = errors.New("invalid year")
    // ErrIncorrectDatetimeValue is returned when the input is not valid date time value.
    ErrIncorrectDatetimeValue = terror.ClassTypes.New(mysql.ErrTruncatedWrongValue, "Incorrect datetime value: '%s'")
    // ErrTruncatedWrongValue is returned then
    ErrTruncatedWrongValue = terror.ClassTypes.New(mysql.ErrTruncatedWrongValue, mysql.MySQLErrName[mysql.ErrTruncatedWrongValue])
)
var (
    // ZeroDuration is the zero value for Duration type.
    ZeroDuration = Duration{Duration: gotime.Duration(0), Fsp: DefaultFsp}

    // ZeroTime is the zero value for TimeInternal type.
    ZeroTime = MysqlTime{}

    // ZeroDatetime is the zero value for datetime Time.
    ZeroDatetime = Time{
        Time: ZeroTime,
        Type: mysql.TypeDatetime,
        Fsp:  DefaultFsp,
    }

    // ZeroTimestamp is the zero value for timestamp Time.
    ZeroTimestamp = Time{
        Time: ZeroTime,
        Type: mysql.TypeTimestamp,
        Fsp:  DefaultFsp,
    }

    // ZeroDate is the zero value for date Time.
    ZeroDate = Time{
        Time: ZeroTime,
        Type: mysql.TypeDate,
        Fsp:  DefaultFsp,
    }
)

Zero values for different types.

var (
    // MinDatetime is the minimum for mysql datetime type.
    MinDatetime = FromDate(1000, 1, 1, 0, 0, 0, 0)
    // MaxDatetime is the maximum for mysql datetime type.
    MaxDatetime = FromDate(9999, 12, 31, 23, 59, 59, 999999)

    // BoundTimezone is the timezone for min and max timestamp.
    BoundTimezone = gotime.UTC
    // MinTimestamp is the minimum for mysql timestamp type.
    MinTimestamp = Time{
        Time: FromDate(1970, 1, 1, 0, 0, 1, 0),
        Type: mysql.TypeTimestamp,
        Fsp:  DefaultFsp,
    }
    // MaxTimestamp is the maximum for mysql timestamp type.
    MaxTimestamp = Time{
        Time: FromDate(2038, 1, 19, 3, 14, 7, 999999),
        Type: mysql.TypeTimestamp,
        Fsp:  DefaultFsp,
    }

    // WeekdayNames lists names of weekdays, which are used in builtin time function `dayname`.
    WeekdayNames = []string{
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
        "Sunday",
    }

    // MonthNames lists names of months, which are used in builtin time function `monthname`.
    MonthNames = []string{
        "January", "February",
        "March", "April",
        "May", "June",
        "July", "August",
        "September", "October",
        "November", "December",
    }
)
var IsTypeBlob = ast.IsTypeBlob

IsTypeBlob returns a boolean indicating whether the tp is a blob type.

var IsTypeChar = ast.IsTypeChar

IsTypeChar returns a boolean indicating whether the tp is the char type like a string type or a varchar type.

var TypeStr = ast.TypeStr

TypeStr converts tp to a string.

var TypeToStr = ast.TypeToStr

TypeToStr converts a field to a string. It is used for converting Text to Blob, or converting Char to Binary. Args:

tp: type enum
cs: charset
var ZeroBinaryLiteral = BinaryLiteral{}

ZeroBinaryLiteral is a BinaryLiteral literal with zero value.

func AddDate Uses

func AddDate(year, month, day int64, ot gotime.Time) (nt gotime.Time)

AddDate fix gap between mysql and golang api When we execute select date_add('2018-01-31',interval 1 month) in mysql we got 2018-02-28 but in tidb we got 2018-03-03. Dig it and we found it's caused by golang api time.Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time , it says October 32 converts to November 1 ,it conflits with mysql. See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-add

func AddInt64 Uses

func AddInt64(a int64, b int64) (int64, error)

AddInt64 adds int64 a and b if no overflow, otherwise returns error.

func AddInteger Uses

func AddInteger(a uint64, b int64) (uint64, error)

AddInteger adds uint64 a and int64 b and returns uint64 if no overflow error.

func AddUint64 Uses

func AddUint64(a uint64, b uint64) (uint64, error)

AddUint64 adds uint64 a and b if no overflow, else returns error.

func AdjustYear Uses

func AdjustYear(y int64, shouldAdjust bool) (int64, error)

AdjustYear is used for adjusting year and checking its validation.

func CheckFsp Uses

func CheckFsp(fsp int) (int8, error)

CheckFsp checks whether fsp is in valid range.

func CompareFloat64 Uses

func CompareFloat64(x, y float64) int

CompareFloat64 returns an integer comparing the float64 x to y.

func CompareInt64 Uses

func CompareInt64(x, y int64) int

CompareInt64 returns an integer comparing the int64 x to y.

func CompareString Uses

func CompareString(x, y string) int

CompareString returns an integer comparing the string x to y.

func CompareUint64 Uses

func CompareUint64(x, y uint64) int

CompareUint64 returns an integer comparing the uint64 x to y.

func ConvertDecimalToUint Uses

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 Uses

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 Uses

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

ConvertFloatToUint converts a float value to an uint value.

func ConvertIntToInt Uses

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 Uses

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

ConvertIntToUint converts an int value to an uint value.

func ConvertJSONToFloat Uses

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

ConvertJSONToFloat casts JSON into float64.

func ConvertJSONToInt Uses

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

ConvertJSONToInt casts JSON into int64.

func ConvertUintToInt Uses

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

ConvertUintToInt converts an uint value to an int value.

func ConvertUintToUint Uses

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

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

func DateDiff Uses

func DateDiff(startTime, endTime MysqlTime) int

DateDiff calculates number of days between two days.

func DateFSP Uses

func DateFSP(date string) (fsp int)

DateFSP gets fsp from date string.

func DateTimeIsOverflow Uses

func DateTimeIsOverflow(sc *stmtctx.StatementContext, date Time) (bool, error)

DateTimeIsOverflow return if this date is overflow. See: https://dev.mysql.com/doc/refman/8.0/en/datetime.html

func DatumsToStrNoErr Uses

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 Uses

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

DatumsToString converts several datums to formatted string.

func DecimalAdd Uses

func DecimalAdd(from1, from2, to *MyDecimal) error

DecimalAdd adds two decimals, sets the result to 'to'. Note: DO NOT use `from1` or `from2` as `to` since the metadata of `to` may be changed during evaluating.

func DecimalBinSize Uses

func DecimalBinSize(precision, frac int) int

DecimalBinSize returns the size of array to hold a binary representation of a decimal.

func DecimalDiv Uses

func DecimalDiv(from1, from2, to *MyDecimal, fracIncr int) error

DecimalDiv does division of two decimals.

from1 - dividend from2 - divisor to - quotient fracIncr - increment of fraction

func DecimalMod Uses

func DecimalMod(from1, from2, to *MyDecimal) error

DecimalMod does modulus of two decimals.

    from1   - dividend
    from2   - divisor
    to      - modulus

RETURN VALUE
  E_DEC_OK/E_DEC_TRUNCATED/E_DEC_OVERFLOW/E_DEC_DIV_ZERO;

NOTES
  see do_div_mod()

DESCRIPTION
  the modulus R in    R = M mod N

 is defined as

   0 <= |R| < |M|
   sign R == sign M
   R = M - k*N, where k is integer

 thus, there's no requirement for M or N to be integers

func DecimalMul Uses

func DecimalMul(from1, from2, to *MyDecimal) error

DecimalMul multiplies two decimals.

    from1, from2 - factors
    to      - product

RETURN VALUE
  E_DEC_OK/E_DEC_TRUNCATED/E_DEC_OVERFLOW;

NOTES
  in this implementation, with wordSize=4 we have digitsPerWord=9,
  and 63-digit number will take only 7 words (basically a 7-digit
  "base 999999999" number).  Thus there's no need in fast multiplication
  algorithms, 7-digit numbers can be multiplied with a naive O(n*n)
  method.

  XXX if this library is to be used with huge numbers of thousands of
  digits, fast multiplication must be implemented.

func DecimalPeak Uses

func DecimalPeak(b []byte) (int, error)

DecimalPeak returns the length of the encoded decimal.

func DecimalSub Uses

func DecimalSub(from1, from2, to *MyDecimal) error

DecimalSub subs one decimal from another, sets the result to 'to'.

func DefaultCharsetForType Uses

func DefaultCharsetForType(tp byte) (string, string)

DefaultCharsetForType returns the default charset/collation for mysql type.

func DefaultParamTypeForValue Uses

func DefaultParamTypeForValue(value interface{}, tp *FieldType)

DefaultParamTypeForValue returns the default FieldType for the parameterized value.

func DefaultTypeForValue Uses

func DefaultTypeForValue(value interface{}, tp *FieldType)

DefaultTypeForValue returns the default FieldType for the value.

func DivInt64 Uses

func DivInt64(a int64, b int64) (int64, error)

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 Uses

func DivIntWithUint(a int64, b uint64) (uint64, error)

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 Uses

func DivUintWithInt(a uint64, b int64) (uint64, error)

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 EOFAsNil Uses

func EOFAsNil(err error) error

EOFAsNil filtrates errors, If err is equal to io.EOF returns nil.

func EqualDatums Uses

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

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

func ExtractDatetimeNum Uses

func ExtractDatetimeNum(t *Time, unit string) (int64, error)

ExtractDatetimeNum extracts time value number from datetime unit and format.

func ExtractDurationNum Uses

func ExtractDurationNum(d *Duration, unit string) (int64, error)

ExtractDurationNum extracts duration value number from duration unit and format.

func FormatIntWidthN Uses

func FormatIntWidthN(num, n int) string

FormatIntWidthN uses to format int with width. Insufficient digits are filled by 0.

func GetFormatType Uses

func GetFormatType(format string) (isDuration, isDate bool)

GetFormatType checks the type(Duration, Date or Datetime) of a format string.

func GetFracIndex Uses

func GetFracIndex(s string) (index int)

GetFracIndex finds the last '.' for get fracStr, index = -1 means fracStr not found. but for format like '2019.01.01 00:00:00', the index should be -1.

func GetFsp Uses

func GetFsp(s string) int8

GetFsp gets the fsp of a string.

func GetLastDay Uses

func GetLastDay(year, month int) int

GetLastDay returns the last day of the month

func GetMaxFloat Uses

func GetMaxFloat(flen int, decimal int) float64

GetMaxFloat gets the max float for given flen and decimal.

func IntergerSignedLowerBound Uses

func IntergerSignedLowerBound(intType byte) int64

IntergerSignedLowerBound indicates the min int64 values of different mysql types.

func IntergerSignedUpperBound Uses

func IntergerSignedUpperBound(intType byte) int64

IntergerSignedUpperBound indicates the max int64 values of different mysql types.

func IntergerUnsignedUpperBound Uses

func IntergerUnsignedUpperBound(intType byte) uint64

IntergerUnsignedUpperBound indicates the max uint64 values of different mysql types.

func InvOp2 Uses

func InvOp2(x, y interface{}, o opcode.Op) (interface{}, error)

InvOp2 returns an invalid operation error.

func IsBinaryStr Uses

func IsBinaryStr(ft *FieldType) bool

IsBinaryStr returns a boolean indicating whether the field type is a binary string type.

func IsClockUnit Uses

func IsClockUnit(unit string) bool

IsClockUnit returns true when unit is interval unit with hour, minute or second.

func IsDateFormat Uses

func IsDateFormat(format string) bool

IsDateFormat returns true when the specified time format could contain only date.

func IsNonBinaryStr Uses

func IsNonBinaryStr(ft *FieldType) bool

IsNonBinaryStr returns a boolean indicating whether the field type is a non-binary string type.

func IsString Uses

func IsString(tp byte) bool

IsString returns a boolean indicating whether the field type is a string type.

func IsTemporalWithDate Uses

func IsTemporalWithDate(tp byte) bool

IsTemporalWithDate returns a boolean indicating whether the tp is time type with date.

func IsTypeFractionable Uses

func IsTypeFractionable(tp byte) bool

IsTypeFractionable returns a boolean indicating whether the tp can has time fraction.

func IsTypeNumeric Uses

func IsTypeNumeric(tp byte) bool

IsTypeNumeric returns a boolean indicating whether the tp is numeric type.

func IsTypePrefixable Uses

func IsTypePrefixable(tp byte) bool

IsTypePrefixable returns a boolean indicating whether an index on a column with the tp can be defined with a prefix.

func IsTypeTemporal Uses

func IsTypeTemporal(tp byte) bool

IsTypeTemporal checks if a type is a temporal type.

func IsTypeTime Uses

func IsTypeTime(tp byte) bool

IsTypeTime returns a boolean indicating whether the tp is time type like datetime, date or timestamp.

func IsTypeUnspecified Uses

func IsTypeUnspecified(tp byte) bool

IsTypeUnspecified returns a boolean indicating whether the tp is the Unspecified type.

func IsTypeVarchar Uses

func IsTypeVarchar(tp byte) bool

IsTypeVarchar returns a boolean indicating whether the tp is the varchar type like a varstring type or a varchar type.

func KindStr Uses

func KindStr(kind byte) (r string)

KindStr converts kind to a string.

func MergeFieldType Uses

func MergeFieldType(a byte, b byte) byte

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 result 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 MulInt64 Uses

func MulInt64(a int64, b int64) (int64, error)

MulInt64 multiplies int64 a and b and returns int64 if no overflow error.

func MulInteger Uses

func MulInteger(a uint64, b int64) (uint64, error)

MulInteger multiplies uint64 a and int64 b, and returns uint64 if no overflow error.

func MulUint64 Uses

func MulUint64(a uint64, b uint64) (uint64, error)

MulUint64 multiplies uint64 a and b and returns uint64 if no overflow error.

func ParseDateFormat Uses

func ParseDateFormat(format string) []string

ParseDateFormat parses a formatted date string and returns separated components.

func ParseDurationValue Uses

func ParseDurationValue(unit string, format string) (y int64, m int64, d int64, n int64, _ error)

ParseDurationValue parses time value from time unit and format. Returns y years m months d days + n nanoseconds Nanoseconds will no longer than one day.

func ParseFrac Uses

func ParseFrac(s string, fsp int8) (v int, overflow bool, err error)

ParseFrac parses the input string according to fsp, returns the microsecond, and also a bool value to indice overflow. eg: "999" fsp=2 will overflow.

func ParseYear Uses

func ParseYear(str string) (int16, error)

ParseYear parses a formatted string and returns a year number.

func ProduceFloatWithSpecifiedTp Uses

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

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

func ProduceStrWithSpecifiedTp Uses

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 Round Uses

func Round(f float64, dec int) float64

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 Uses

func RoundFloat(f float64) float64

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 RoundFrac Uses

func RoundFrac(t gotime.Time, fsp int8) (gotime.Time, error)

RoundFrac rounds fractional seconds precision with new fsp and returns a new one. We will use the “round half up” rule, e.g, >= 0.5 -> 1, < 0.5 -> 0, so 2011:11:11 10:10:10.888888 round 0 -> 2011:11:11 10:10:11 and 2011:11:11 10:10:10.111111 round 0 -> 2011:11:11 10:10:10

func SetBinChsClnFlag Uses

func SetBinChsClnFlag(ft *FieldType)

SetBinChsClnFlag sets charset, collation as 'binary' and adds binaryFlag to FieldType.

func SortDatums Uses

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

SortDatums sorts a slice of datum.

func StrToDuration Uses

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 Uses

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

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

func StrToInt Uses

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

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

func StrToUint Uses

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

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

func SubInt64 Uses

func SubInt64(a int64, b int64) (int64, error)

SubInt64 subtracts int64 a with b and returns int64 if no overflow error.

func SubIntWithUint Uses

func SubIntWithUint(a int64, b uint64) (uint64, error)

SubIntWithUint subtracts int64 a with uint64 b and returns uint64 if no overflow error.

func SubUint64 Uses

func SubUint64(a uint64, b uint64) (uint64, error)

SubUint64 subtracts uint64 a with b and returns uint64 if no overflow error.

func SubUintWithInt Uses

func SubUintWithInt(a uint64, b int64) (uint64, error)

SubUintWithInt subtracts uint64 a with int64 b and returns uint64 if no overflow error.

func TimestampDiff Uses

func TimestampDiff(unit string, t1 Time, t2 Time) int64

TimestampDiff returns t2 - t1 where t1 and t2 are date or datetime expressions. The unit for the result (an integer) is given by the unit argument. The legal values for unit are "YEAR" "QUARTER" "MONTH" "DAY" "HOUR" "SECOND" and so on.

func ToString Uses

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

ToString converts an interface to a string.

func Truncate Uses

func Truncate(f float64, dec int) float64

Truncate truncates 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 TruncateFloat Uses

func TruncateFloat(f float64, flen int, decimal int) (float64, error)

TruncateFloat tries to truncate f. If the result exceeds the max/min float that flen/decimal allowed, returns the max/min float allowed.

func TruncateFrac Uses

func TruncateFrac(t gotime.Time, fsp int8) (gotime.Time, error)

TruncateFrac truncates fractional seconds precision with new fsp and returns a new one. 2011:11:11 10:10:10.888888 round 0 -> 2011:11:11 10:10:10 2011:11:11 10:10:10.111111 round 0 -> 2011:11:11 10:10:10

func TruncateOverflowMySQLTime Uses

func TruncateOverflowMySQLTime(d gotime.Duration) (gotime.Duration, error)

TruncateOverflowMySQLTime truncates d when it overflows, and return ErrTruncatedWrongVal.

type BinaryLiteral Uses

type BinaryLiteral []byte

BinaryLiteral is the internal type for storing bit / hex literal type.

func NewBinaryLiteralFromUint Uses

func NewBinaryLiteralFromUint(value uint64, byteSize int) BinaryLiteral

NewBinaryLiteralFromUint creates a new BinaryLiteral instance by the given uint value in BitEndian. byteSize will be used as the length of the new BinaryLiteral, with leading bytes filled to zero. If byteSize is -1, the leading zeros in new BinaryLiteral will be trimmed.

func ParseBitStr Uses

func ParseBitStr(s string) (BinaryLiteral, error)

ParseBitStr parses bit string. The string format can be b'val', B'val' or 0bval, val must be 0 or 1. See https://dev.mysql.com/doc/refman/5.7/en/bit-value-literals.html

func ParseHexStr Uses

func ParseHexStr(s string) (BinaryLiteral, error)

ParseHexStr parses hexadecimal string literal. See https://dev.mysql.com/doc/refman/5.7/en/hexadecimal-literals.html

func (BinaryLiteral) Compare Uses

func (b BinaryLiteral) Compare(b2 BinaryLiteral) int

Compare compares BinaryLiteral to another one

func (BinaryLiteral) String Uses

func (b BinaryLiteral) String() string

String implements fmt.Stringer interface.

func (BinaryLiteral) ToBitLiteralString Uses

func (b BinaryLiteral) ToBitLiteralString(trimLeadingZero bool) string

ToBitLiteralString returns the bit literal representation for the literal.

func (BinaryLiteral) ToInt Uses

func (b BinaryLiteral) ToInt(sc *stmtctx.StatementContext) (uint64, error)

ToInt returns the int value for the literal.

func (BinaryLiteral) ToString Uses

func (b BinaryLiteral) ToString() string

ToString returns the string representation for the literal.

type BitLiteral Uses

type BitLiteral BinaryLiteral

BitLiteral is the bit literal type.

func NewBitLiteral Uses

func NewBitLiteral(s string) (BitLiteral, error)

NewBitLiteral parses bit string as BitLiteral type.

func (BitLiteral) ToString Uses

func (b BitLiteral) ToString() string

ToString implement ast.BinaryLiteral interface

type Datum Uses

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 CloneDatum Uses

func CloneDatum(datum Datum) Datum

CloneDatum returns a new copy of the datum. TODO: Abandon this function.

func CloneRow Uses

func CloneRow(dr []Datum) []Datum

CloneRow deep copies a Datum slice.

func ComputePlus Uses

func ComputePlus(a, b Datum) (d Datum, err error)

ComputePlus computes the result of a+b.

func MakeDatums Uses

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

MakeDatums creates datum slice from interfaces.

func MaxValueDatum Uses

func MaxValueDatum() Datum

MaxValueDatum returns a datum represents max value.

func MinNotNullDatum Uses

func MinNotNullDatum() Datum

MinNotNullDatum returns a datum represents minimum not null value.

func NewBinaryLiteralDatum Uses

func NewBinaryLiteralDatum(b BinaryLiteral) (d Datum)

NewBinaryLiteralDatum creates a new BinaryLiteral Datum for a BinaryLiteral value.

func NewBytesDatum Uses

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

NewBytesDatum creates a new Datum from a byte slice.

func NewDatum Uses

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

NewDatum creates a new Datum from an interface{}.

func NewDecimalDatum Uses

func NewDecimalDatum(dec *MyDecimal) (d Datum)

NewDecimalDatum creates a new Datum form a MyDecimal value.

func NewDurationDatum Uses

func NewDurationDatum(dur Duration) (d Datum)

NewDurationDatum creates a new Datum from a Duration value.

func NewFloat32Datum Uses

func NewFloat32Datum(f float32) (d Datum)

NewFloat32Datum creates a new Datum from a float32 value.

func NewFloat64Datum Uses

func NewFloat64Datum(f float64) (d Datum)

NewFloat64Datum creates a new Datum from a float64 value.

func NewIntDatum Uses

func NewIntDatum(i int64) (d Datum)

NewIntDatum creates a new Datum from an int64 value.

func NewMysqlBitDatum Uses

func NewMysqlBitDatum(b BinaryLiteral) (d Datum)

NewMysqlBitDatum creates a new MysqlBit Datum for a BinaryLiteral value.

func NewMysqlEnumDatum Uses

func NewMysqlEnumDatum(e Enum) (d Datum)

NewMysqlEnumDatum creates a new MysqlEnum Datum for a Enum value.

func NewStringDatum Uses

func NewStringDatum(s string) (d Datum)

NewStringDatum creates a new Datum from a string.

func NewTimeDatum Uses

func NewTimeDatum(t Time) (d Datum)

NewTimeDatum creates a new Time from a Time value.

func NewUintDatum Uses

func NewUintDatum(i uint64) (d Datum)

NewUintDatum creates a new Datum from an uint64 value.

func (*Datum) Collation Uses

func (d *Datum) Collation() byte

Collation gets the collation of the datum.

func (*Datum) CompareDatum Uses

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

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

func (*Datum) ConvertTo Uses

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

ConvertTo converts a datum to the target field type.

func (*Datum) Copy Uses

func (d *Datum) Copy() *Datum

Copy deep copies a Datum.

func (*Datum) Frac Uses

func (d *Datum) Frac() int

Frac gets the frac of the datum.

func (*Datum) GetBinaryLiteral Uses

func (d *Datum) GetBinaryLiteral() BinaryLiteral

GetBinaryLiteral gets Bit value

func (*Datum) GetBytes Uses

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

GetBytes gets bytes value.

func (*Datum) GetFloat32 Uses

func (d *Datum) GetFloat32() float32

GetFloat32 gets float32 value.

func (*Datum) GetFloat64 Uses

func (d *Datum) GetFloat64() float64

GetFloat64 gets float64 value.

func (*Datum) GetInt64 Uses

func (d *Datum) GetInt64() int64

GetInt64 gets int64 value.

func (*Datum) GetInterface Uses

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

GetInterface gets interface value.

func (*Datum) GetMysqlBit Uses

func (d *Datum) GetMysqlBit() BinaryLiteral

GetMysqlBit gets MysqlBit value

func (*Datum) GetMysqlDecimal Uses

func (d *Datum) GetMysqlDecimal() *MyDecimal

GetMysqlDecimal gets Decimal value

func (*Datum) GetMysqlDuration Uses

func (d *Datum) GetMysqlDuration() Duration

GetMysqlDuration gets Duration value

func (*Datum) GetMysqlEnum Uses

func (d *Datum) GetMysqlEnum() Enum

GetMysqlEnum gets Enum value

func (*Datum) GetMysqlJSON Uses

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

GetMysqlJSON gets json.BinaryJSON value

func (*Datum) GetMysqlSet Uses

func (d *Datum) GetMysqlSet() Set

GetMysqlSet gets Set value

func (*Datum) GetMysqlTime Uses

func (d *Datum) GetMysqlTime() Time

GetMysqlTime gets types.Time value

func (*Datum) GetRaw Uses

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

GetRaw gets raw value.

func (*Datum) GetString Uses

func (d *Datum) GetString() string

GetString gets string value.

func (*Datum) GetUint64 Uses

func (d *Datum) GetUint64() uint64

GetUint64 gets uint64 value.

func (*Datum) GetValue Uses

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

GetValue gets the value of the datum of any kind.

func (*Datum) IsNull Uses

func (d *Datum) IsNull() bool

IsNull checks if datum is null.

func (*Datum) Kind Uses

func (d *Datum) Kind() byte

Kind gets the kind of the datum.

func (*Datum) Length Uses

func (d *Datum) Length() int

Length gets the length of the datum.

func (*Datum) SetAutoID Uses

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

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

func (*Datum) SetBinaryLiteral Uses

func (d *Datum) SetBinaryLiteral(b BinaryLiteral)

SetBinaryLiteral sets Bit value

func (*Datum) SetBytes Uses

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

SetBytes sets bytes value to datum.

func (*Datum) SetBytesAsString Uses

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

SetBytesAsString sets bytes value to datum as string type.

func (*Datum) SetCollation Uses

func (d *Datum) SetCollation(collation byte)

SetCollation sets the collation of the datum.

func (*Datum) SetFloat32 Uses

func (d *Datum) SetFloat32(f float32)

SetFloat32 sets float32 value.

func (*Datum) SetFloat64 Uses

func (d *Datum) SetFloat64(f float64)

SetFloat64 sets float64 value.

func (*Datum) SetFrac Uses

func (d *Datum) SetFrac(frac int)

SetFrac sets the frac of the datum.

func (*Datum) SetInt64 Uses

func (d *Datum) SetInt64(i int64)

SetInt64 sets int64 value.

func (*Datum) SetInterface Uses

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

SetInterface sets interface to datum.

func (*Datum) SetLength Uses

func (d *Datum) SetLength(l int)

SetLength sets the length of the datum.

func (*Datum) SetMinNotNull Uses

func (d *Datum) SetMinNotNull()

SetMinNotNull sets datum to minNotNull value.

func (*Datum) SetMysqlBit Uses

func (d *Datum) SetMysqlBit(b BinaryLiteral)

SetMysqlBit sets MysqlBit value

func (*Datum) SetMysqlDecimal Uses

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

SetMysqlDecimal sets Decimal value

func (*Datum) SetMysqlDuration Uses

func (d *Datum) SetMysqlDuration(b Duration)

SetMysqlDuration sets Duration value

func (*Datum) SetMysqlEnum Uses

func (d *Datum) SetMysqlEnum(b Enum)

SetMysqlEnum sets Enum value

func (*Datum) SetMysqlJSON Uses

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

SetMysqlJSON sets json.BinaryJSON value

func (*Datum) SetMysqlSet Uses

func (d *Datum) SetMysqlSet(b Set)

SetMysqlSet sets Set value

func (*Datum) SetMysqlTime Uses

func (d *Datum) SetMysqlTime(b Time)

SetMysqlTime sets types.Time value

func (*Datum) SetNull Uses

func (d *Datum) SetNull()

SetNull sets datum to nil.

func (*Datum) SetRaw Uses

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

SetRaw sets raw value.

func (*Datum) SetString Uses

func (d *Datum) SetString(s string)

SetString sets string value.

func (*Datum) SetUint64 Uses

func (d *Datum) SetUint64(i uint64)

SetUint64 sets uint64 value.

func (*Datum) SetValue Uses

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

SetValue sets any kind of value.

func (*Datum) ToBool Uses

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 Uses

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

ToBytes gets the bytes representation of the datum.

func (*Datum) ToDecimal Uses

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

ToDecimal converts to a decimal.

func (*Datum) ToFloat64 Uses

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

ToFloat64 converts to a float64

func (*Datum) ToInt64 Uses

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

ToInt64 converts to a int64.

func (*Datum) ToMysqlJSON Uses

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 Uses

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

ToString gets the string representation of the datum.

type Duration Uses

type Duration struct {
    gotime.Duration
    // Fsp is short for Fractional Seconds Precision.
    // See http://dev.mysql.com/doc/refman/5.7/en/fractional-seconds.html
    Fsp int8
}

Duration is the type for MySQL TIME type.

func ExtractDurationValue Uses

func ExtractDurationValue(unit string, format string) (Duration, error)

ExtractDurationValue extract the value from format to Duration.

func NumberToDuration Uses

func NumberToDuration(number int64, fsp int8) (Duration, error)

NumberToDuration converts number to Duration.

func ParseDuration Uses

func ParseDuration(sc *stmtctx.StatementContext, str string, fsp int8) (Duration, error)

ParseDuration parses the time form a formatted string with a fractional seconds part, returns the duration type Time value. See http://dev.mysql.com/doc/refman/5.7/en/fractional-seconds.html

func (Duration) Add Uses

func (d Duration) Add(v Duration) (Duration, error)

Add adds d to d, returns a duration value.

func (Duration) Compare Uses

func (d Duration) Compare(o Duration) int

Compare returns an integer comparing the Duration instant t to o. If d is after o, return 1, equal o, return 0, before o, return -1.

func (Duration) CompareString Uses

func (d Duration) CompareString(sc *stmtctx.StatementContext, str string) (int, error)

CompareString is like Compare, but parses str to Duration then compares.

func (Duration) ConvertToTime Uses

func (d Duration) ConvertToTime(sc *stmtctx.StatementContext, tp uint8) (Time, error)

ConvertToTime converts duration to Time. Tp is TypeDatetime, TypeTimestamp and TypeDate.

func (Duration) Hour Uses

func (d Duration) Hour() int

Hour returns current hour. e.g, hour("11:11:11") -> 11

func (Duration) MicroSecond Uses

func (d Duration) MicroSecond() int

MicroSecond returns current microsecond. e.g, hour("11:11:11.11") -> 110000

func (Duration) Minute Uses

func (d Duration) Minute() int

Minute returns current minute. e.g, hour("11:11:11") -> 11

func (Duration) RoundFrac Uses

func (d Duration) RoundFrac(fsp int8) (Duration, error)

RoundFrac rounds fractional seconds precision with new fsp and returns a new one. We will use the “round half up” rule, e.g, >= 0.5 -> 1, < 0.5 -> 0, so 10:10:10.999999 round 0 -> 10:10:11 and 10:10:10.000000 round 0 -> 10:10:10

func (Duration) Second Uses

func (d Duration) Second() int

Second returns current second. e.g, hour("11:11:11") -> 11

func (Duration) String Uses

func (d Duration) String() string

String returns the time formatted using default TimeFormat and fsp.

func (Duration) Sub Uses

func (d Duration) Sub(v Duration) (Duration, error)

Sub subtracts d to d, returns a duration value.

func (Duration) ToNumber Uses

func (d Duration) ToNumber() *MyDecimal

ToNumber changes duration to number format. e.g, 10:10:10 -> 101010

type Enum Uses

type Enum struct {
    Name  string
    Value uint64
}

Enum is for MySQL enum type.

func ParseEnumName Uses

func ParseEnumName(elems []string, name string) (Enum, error)

ParseEnumName creates a Enum with item name.

func ParseEnumValue Uses

func ParseEnumValue(elems []string, number uint64) (Enum, error)

ParseEnumValue creates a Enum with special number.

func (Enum) String Uses

func (e Enum) String() string

String implements fmt.Stringer interface.

func (Enum) ToNumber Uses

func (e Enum) ToNumber() float64

ToNumber changes enum index to float64 for numeric operation.

type EvalType Uses

type EvalType = ast.EvalType

EvalType indicates the specified types that arguments and result of a built-in function should be.

func AggregateEvalType Uses

func AggregateEvalType(fts []*FieldType, flag *uint) EvalType

AggregateEvalType aggregates arguments' EvalType of a multi-argument function.

type FieldName Uses

type FieldName struct {
    OrigTblName model.CIStr
    OrigColName model.CIStr
    DBName      model.CIStr
    TblName     model.CIStr
    ColName     model.CIStr
}

FieldName records the names used for mysql protocol.

func (*FieldName) String Uses

func (name *FieldName) String() string

String implements Stringer interface.

type FieldType Uses

type FieldType = ast.FieldType

FieldType records field type information.

func AggFieldType Uses

func AggFieldType(tps []*FieldType) *FieldType

AggFieldType aggregates field types for a multi-argument function like `IF`, `IFNULL`, `COALESCE` whose return type is determined by the arguments' FieldTypes. Aggregation is performed by MergeFieldType function.

func NewFieldType Uses

func NewFieldType(tp byte) *FieldType

NewFieldType returns a FieldType, with a type and other information about field type.

type HexLiteral Uses

type HexLiteral BinaryLiteral

HexLiteral is the hex literal type.

func NewHexLiteral Uses

func NewHexLiteral(s string) (HexLiteral, error)

NewHexLiteral parses hexadecimal string as HexLiteral type.

func (HexLiteral) ToString Uses

func (b HexLiteral) ToString() string

ToString implement ast.BinaryLiteral interface

type MyDecimal Uses

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

MyDecimal represents a decimal value.

func ConvertDatumToDecimal Uses

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

ConvertDatumToDecimal converts datum to decimal.

func ConvertJSONToDecimal Uses

func ConvertJSONToDecimal(sc *stmtctx.StatementContext, j json.BinaryJSON) (*MyDecimal, error)

ConvertJSONToDecimal casts JSON into decimal.

func DecimalNeg Uses

func DecimalNeg(from *MyDecimal) *MyDecimal

DecimalNeg reverses decimal's sign.

func NewDecFromFloatForTest Uses

func NewDecFromFloatForTest(f float64) *MyDecimal

NewDecFromFloatForTest creates a MyDecimal from float, as it returns no error, it should only be used in test.

func NewDecFromInt Uses

func NewDecFromInt(i int64) *MyDecimal

NewDecFromInt creates a MyDecimal from int.

func NewDecFromStringForTest Uses

func NewDecFromStringForTest(s string) *MyDecimal

NewDecFromStringForTest creates a MyDecimal from string, as it returns no error, it should only be used in test.

func NewDecFromUint Uses

func NewDecFromUint(i uint64) *MyDecimal

NewDecFromUint creates a MyDecimal from uint.

func NewMaxOrMinDec Uses

func NewMaxOrMinDec(negative bool, prec, frac int) *MyDecimal

NewMaxOrMinDec returns the max or min value decimal for given precision and fraction.

func ProduceDecWithSpecifiedTp Uses

func ProduceDecWithSpecifiedTp(dec *MyDecimal, tp *FieldType, sc *stmtctx.StatementContext) (_ *MyDecimal, err error)

ProduceDecWithSpecifiedTp produces a new decimal according to `flen` and `decimal`.

func (*MyDecimal) Compare Uses

func (d *MyDecimal) Compare(to *MyDecimal) int

Compare compares one decimal to another, returns -1/0/1.

func (*MyDecimal) Copy Uses

func (d *MyDecimal) Copy() *MyDecimal

Copy copies a new *MyDecimal from itself.

func (*MyDecimal) FromBin Uses

func (d *MyDecimal) FromBin(bin []byte, precision, frac int) (binSize int, err error)

FromBin Restores decimal from its binary fixed-length representation.

func (*MyDecimal) FromFloat64 Uses

func (d *MyDecimal) FromFloat64(f float64) error

FromFloat64 creates a decimal from float64 value.

func (*MyDecimal) FromInt Uses

func (d *MyDecimal) FromInt(val int64) *MyDecimal

FromInt sets the decimal value from int64.

func (*MyDecimal) FromString Uses

func (d *MyDecimal) FromString(str []byte) error

FromString parses decimal from string.

func (*MyDecimal) FromUint Uses

func (d *MyDecimal) FromUint(val uint64) *MyDecimal

FromUint sets the decimal value from uint64.

func (*MyDecimal) GetDigitsFrac Uses

func (d *MyDecimal) GetDigitsFrac() int8

GetDigitsFrac returns the digitsFrac.

func (*MyDecimal) IsNegative Uses

func (d *MyDecimal) IsNegative() bool

IsNegative returns whether a decimal is negative.

func (*MyDecimal) IsZero Uses

func (d *MyDecimal) IsZero() bool

IsZero checks whether it's a zero decimal.

func (*MyDecimal) PrecisionAndFrac Uses

func (d *MyDecimal) PrecisionAndFrac() (precision, frac int)

PrecisionAndFrac returns the internal precision and frac number.

func (*MyDecimal) Round Uses

func (d *MyDecimal) Round(to *MyDecimal, frac int, roundMode RoundMode) (err error)

Round rounds the decimal to "frac" digits.

   to			- result buffer. d == to is allowed
   frac			- to what position after fraction point to round. can be negative!
   roundMode		- round to nearest even or truncate
			ModeHalfEven rounds normally.
			Truncate just truncates the decimal.

NOTES

scale can be negative !
one TRUNCATED error (line XXX below) isn't treated very logical :(

RETURN VALUE

eDecOK/eDecTruncated

func (*MyDecimal) Shift Uses

func (d *MyDecimal) Shift(shift int) error

Shift shifts decimal digits in given number (with rounding if it need), shift > 0 means shift to left shift, shift < 0 means right shift. In fact it is multiplying on 10^shift.

RETURN

eDecOK          OK
eDecOverflow    operation lead to overflow, number is untoched
eDecTruncated   number was rounded to fit into buffer

func (*MyDecimal) String Uses

func (d *MyDecimal) String() string

String returns the decimal string representation rounded to resultFrac.

func (*MyDecimal) ToBin Uses

func (d *MyDecimal) ToBin(precision, frac int) ([]byte, error)

ToBin converts decimal to its binary fixed-length representation two representations of the same length can be compared with memcmp with the correct -1/0/+1 result

  PARAMS
		precision/frac - if precision is 0, internal value of the decimal will be used,
		then the encoded value is not memory comparable.

  NOTE
    the buffer is assumed to be of the size DecimalBinSize(precision, frac)

  RETURN VALUE
  	bin     - binary value
    errCode - eDecOK/eDecTruncate/eDecOverflow

  DESCRIPTION
    for storage decimal numbers are converted to the "binary" format.

    This format has the following properties:
      1. length of the binary representation depends on the {precision, frac}
      as provided by the caller and NOT on the digitsInt/digitsFrac of the decimal to
      convert.
      2. binary representations of the same {precision, frac} can be compared
      with memcmp - with the same result as DecimalCompare() of the original
      decimals (not taking into account possible precision loss during
      conversion).

    This binary format is as follows:
      1. First the number is converted to have a requested precision and frac.
      2. Every full digitsPerWord digits of digitsInt part are stored in 4 bytes
         as is
      3. The first digitsInt % digitesPerWord digits are stored in the reduced
         number of bytes (enough bytes to store this number of digits -
         see dig2bytes)
      4. same for frac - full word are stored as is,
         the last frac % digitsPerWord digits - in the reduced number of bytes.
      5. If the number is negative - every byte is inversed.
      5. The very first bit of the resulting byte array is inverted (because
         memcmp compares unsigned bytes, see property 2 above)

    Example:

      1234567890.1234

    internally is represented as 3 words

      1 234567890 123400000

    (assuming we want a binary representation with precision=14, frac=4)
    in hex it's

      00-00-00-01  0D-FB-38-D2  07-5A-EF-40

    now, middle word is full - it stores 9 decimal digits. It goes
    into binary representation as is:

      ...........  0D-FB-38-D2 ............

    First word has only one decimal digit. We can store one digit in
    one byte, no need to waste four:

                01 0D-FB-38-D2 ............

    now, last word. It's 123400000. We can store 1234 in two bytes:

                01 0D-FB-38-D2 04-D2

    So, we've packed 12 bytes number in 7 bytes.
    And now we invert the highest bit to get the final result:

                81 0D FB 38 D2 04 D2

    And for -1234567890.1234 it would be

                7E F2 04 C7 2D FB 2D

func (*MyDecimal) ToFloat64 Uses

func (d *MyDecimal) ToFloat64() (float64, error)

ToFloat64 converts decimal to float64 value.

func (*MyDecimal) ToHashKey Uses

func (d *MyDecimal) ToHashKey() ([]byte, error)

ToHashKey removes the leading and trailing zeros and generates a hash key. Two Decimals dec0 and dec1 with different fraction will generate the same hash keys if dec0.Compare(dec1) == 0.

func (*MyDecimal) ToInt Uses

func (d *MyDecimal) ToInt() (int64, error)

ToInt returns int part of the decimal, returns the result and errcode.

func (*MyDecimal) ToString Uses

func (d *MyDecimal) ToString() (str []byte)

ToString converts decimal to its printable string representation without rounding.

RETURN VALUE

    str       - result string
    errCode   - eDecOK/eDecTruncate/eDecOverflow

func (*MyDecimal) ToUint Uses

func (d *MyDecimal) ToUint() (uint64, error)

ToUint returns int part of the decimal, returns the result and errcode.

type MysqlTime Uses

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

MysqlTime is the internal struct type for Time. The order of the attributes is refined to reduce the memory overhead considering memory alignment.

func FromDate Uses

func FromDate(year int, month int, day int, hour int, minute int, second int, microsecond int) MysqlTime

FromDate makes a internal time representation from the given date.

func FromGoTime Uses

func FromGoTime(t gotime.Time) MysqlTime

FromGoTime translates time.Time to mysql time internal representation.

func (MysqlTime) Day Uses

func (t MysqlTime) Day() int

Day returns the day value.

func (MysqlTime) GoTime Uses

func (t MysqlTime) GoTime(loc *gotime.Location) (gotime.Time, error)

GoTime converts MysqlTime to GoTime.

func (MysqlTime) Hour Uses

func (t MysqlTime) Hour() int

Hour returns the hour value.

func (MysqlTime) IsLeapYear Uses

func (t MysqlTime) IsLeapYear() bool

IsLeapYear returns if it's leap year.

func (MysqlTime) Microsecond Uses

func (t MysqlTime) Microsecond() int

Microsecond returns the microsecond value.

func (MysqlTime) Minute Uses

func (t MysqlTime) Minute() int

Minute returns the minute value.

func (MysqlTime) Month Uses

func (t MysqlTime) Month() int

Month returns the month value.

func (MysqlTime) Second Uses

func (t MysqlTime) Second() int

Second returns the second value.

func (MysqlTime) String Uses

func (t MysqlTime) String() string

String implements fmt.Stringer.

func (MysqlTime) Week Uses

func (t MysqlTime) Week(mode int) int

Week returns the week value.

func (MysqlTime) Weekday Uses

func (t MysqlTime) Weekday() gotime.Weekday

Weekday returns the Weekday value.

func (MysqlTime) Year Uses

func (t MysqlTime) Year() int

Year returns the year value.

func (MysqlTime) YearDay Uses

func (t MysqlTime) YearDay() int

YearDay returns day in year.

func (MysqlTime) YearWeek Uses

func (t MysqlTime) YearWeek(mode int) (int, int)

YearWeek return year and week.

type RoundMode Uses

type RoundMode int32

RoundMode is the type for round mode.

const (
    DivFracIncr = 4

    // ModeHalfEven rounds normally.
    ModeHalfEven RoundMode = 5
    // Truncate just truncates the decimal.
    ModeTruncate RoundMode = 10
)

constant values.

type Set Uses

type Set struct {
    Name  string
    Value uint64
}

Set is for MySQL Set type.

func ParseSetName Uses

func ParseSetName(elems []string, name string) (Set, error)

ParseSetName creates a Set with name.

func ParseSetValue Uses

func ParseSetValue(elems []string, number uint64) (Set, error)

ParseSetValue creates a Set with special number.

func (Set) String Uses

func (e Set) String() string

String implements fmt.Stringer interface.

func (Set) ToNumber Uses

func (e Set) ToNumber() float64

ToNumber changes Set to float64 for numeric operation.

type Time Uses

type Time struct {
    Time MysqlTime
    Type uint8
    // Fsp is short for Fractional Seconds Precision.
    // See http://dev.mysql.com/doc/refman/5.7/en/fractional-seconds.html
    Fsp int8
}

Time is the struct for handling datetime, timestamp and date. TODO: check if need a NewTime function to set Fsp default value?

func CurrentTime Uses

func CurrentTime(tp uint8) Time

CurrentTime returns current time with type tp.

func MaxMySQLTime Uses

func MaxMySQLTime(fsp int8) Time

MaxMySQLTime returns Time with maximum mysql time type.

func ParseDate Uses

func ParseDate(sc *stmtctx.StatementContext, str string) (Time, error)

ParseDate is a helper function wrapping ParseTime with date type.

func ParseDateFromNum Uses

func ParseDateFromNum(sc *stmtctx.StatementContext, num int64) (Time, error)

ParseDateFromNum is a helper function wrapping ParseTimeFromNum with date type.

func ParseDatetime Uses

func ParseDatetime(sc *stmtctx.StatementContext, str string) (Time, error)

ParseDatetime is a helper function wrapping ParseTime with datetime type and default fsp.

func ParseDatetimeFromNum Uses

func ParseDatetimeFromNum(sc *stmtctx.StatementContext, num int64) (Time, error)

ParseDatetimeFromNum is a helper function wrapping ParseTimeFromNum with datetime type and default fsp.

func ParseTime Uses

func ParseTime(sc *stmtctx.StatementContext, str string, tp byte, fsp int8) (Time, error)

ParseTime parses a formatted string with type tp and specific fsp. Type is TypeDatetime, TypeTimestamp and TypeDate. Fsp is in range [0, 6]. MySQL supports many valid datetime format, but still has some limitation. If delimiter exists, the date part and time part is separated by a space or T, other punctuation character can be used as the delimiter between date parts or time parts. If no delimiter, the format must be YYYYMMDDHHMMSS or YYMMDDHHMMSS If we have fractional seconds part, we must use decimal points as the delimiter. The valid datetime range is from '1000-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999'. The valid timestamp range is from '1970-01-01 00:00:01.000000' to '2038-01-19 03:14:07.999999'. The valid date range is from '1000-01-01' to '9999-12-31'

func ParseTimeFromFloatString Uses

func ParseTimeFromFloatString(sc *stmtctx.StatementContext, str string, tp byte, fsp int8) (Time, error)

ParseTimeFromFloatString is similar to ParseTime, except that it's used to parse a float converted string.

func ParseTimeFromInt64 Uses

func ParseTimeFromInt64(sc *stmtctx.StatementContext, num int64) (Time, error)

ParseTimeFromInt64 parses mysql time value from int64.

func ParseTimeFromNum Uses

func ParseTimeFromNum(sc *stmtctx.StatementContext, num int64, tp byte, fsp int8) (Time, error)

ParseTimeFromNum parses a formatted int64, returns the value which type is tp.

func ParseTimestamp Uses

func ParseTimestamp(sc *stmtctx.StatementContext, str string) (Time, error)

ParseTimestamp is a helper function wrapping ParseTime with timestamp type and default fsp.

func ParseTimestampFromNum Uses

func ParseTimestampFromNum(sc *stmtctx.StatementContext, num int64) (Time, error)

ParseTimestampFromNum is a helper function wrapping ParseTimeFromNum with timestamp type and default fsp.

func StrToDateTime Uses

func StrToDateTime(sc *stmtctx.StatementContext, str string, fsp int8) (Time, error)

StrToDateTime converts str to MySQL DateTime.

func TimeFromDays Uses

func TimeFromDays(num int64) Time

TimeFromDays Converts a day number to a date.

func (*Time) Add Uses

func (t *Time) Add(sc *stmtctx.StatementContext, d Duration) (Time, error)

Add adds d to t, returns the result time value.

func (*Time) Check Uses

func (t *Time) Check(sc *stmtctx.StatementContext) error

Check if 't' is valid

func (Time) Clock Uses

func (t Time) Clock() (hour int, minute int, second int)

Clock returns the hour, minute, and second within the day specified by t.

func (Time) Compare Uses

func (t Time) Compare(o Time) int

Compare returns an integer comparing the time instant t to o. If t is after o, return 1, equal o, return 0, before o, return -1.

func (Time) CompareString Uses

func (t Time) CompareString(sc *stmtctx.StatementContext, str string) (int, error)

CompareString is like Compare, but parses string to Time then compares.

func (Time) Convert Uses

func (t Time) Convert(sc *stmtctx.StatementContext, tp uint8) (Time, error)

Convert converts t with type tp.

func (*Time) ConvertTimeZone Uses

func (t *Time) ConvertTimeZone(from, to *gotime.Location) error

ConvertTimeZone converts the time value from one timezone to another. The input time should be a valid timestamp.

func (Time) ConvertToDuration Uses

func (t Time) ConvertToDuration() (Duration, error)

ConvertToDuration converts mysql datetime, timestamp and date to mysql time type. e.g, 2012-12-12T10:10:10 -> 10:10:10 2012-12-12 -> 0

func (Time) DateFormat Uses

func (t Time) DateFormat(layout string) (string, error)

DateFormat returns a textual representation of the time value formatted according to layout. See http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format

func (*Time) FromPackedUint Uses

func (t *Time) FromPackedUint(packed uint64) error

FromPackedUint decodes Time from a packed uint64 value.

func (Time) InvalidZero Uses

func (t Time) InvalidZero() bool

InvalidZero returns a boolean indicating whether the month or day is zero.

func (Time) IsZero Uses

func (t Time) IsZero() bool

IsZero returns a boolean indicating whether the time is equal to ZeroTime.

func (Time) RoundFrac Uses

func (t Time) RoundFrac(sc *stmtctx.StatementContext, fsp int8) (Time, error)

RoundFrac rounds the fraction part of a time-type value according to `fsp`.

func (*Time) StrToDate Uses

func (t *Time) StrToDate(sc *stmtctx.StatementContext, date, format string) bool

StrToDate converts date string according to format. See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format

func (Time) String Uses

func (t Time) String() string

func (*Time) Sub Uses

func (t *Time) Sub(sc *stmtctx.StatementContext, t1 *Time) Duration

Sub subtracts t1 from t, returns a duration value. Note that sub should not be done on different time types.

func (Time) ToNumber Uses

func (t Time) ToNumber() *MyDecimal

ToNumber returns a formatted number. e.g, 2012-12-12 -> 20121212 2012-12-12T10:10:10 -> 20121212101010 2012-12-12T10:10:10.123456 -> 20121212101010.123456

func (Time) ToPackedUint Uses

func (t Time) ToPackedUint() (uint64, error)

ToPackedUint encodes Time to a packed uint64 value.

 1 bit  0
17 bits year*13+month   (year 0-9999, month 0-12)
 5 bits day             (0-31)
 5 bits hour            (0-23)
 6 bits minute          (0-59)
 6 bits second          (0-59)
24 bits microseconds    (0-999999)

Total: 64 bits = 8 bytes

0YYYYYYY.YYYYYYYY.YYdddddh.hhhhmmmm.mmssssss.ffffffff.ffffffff.ffffffff

Directories

PathSynopsis
json
parser_driver

Package types imports 27 packages (graph) and is imported by 221 packages. Updated 2019-09-18. Refresh now. Tools for package owners.