types

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MaxDateYear    = 9999
	MinDateYear    = 1
	MaxMonthInYear = 12
	MinMonthInYear = 1
)
View Source
const (
	DateType      = 0
	DateTimeType  = 1
	TimeStampType = 2
)
View Source
const (

	//secsPerWeek   = 7 * secsPerDay
	//microSecondBitMask = 0xfffff
	MaxDatetimeYear = 9999
	MinDatetimeYear = 1
)
View Source
const IntervalInt64MAX = int64(^uint64(0) >> 1)
View Source
const IntervalNumMAX = int32(^uint32(0) >> 1)

Variables

View Source
var (
	ErrIncorrectDateValue = errors.New(errno.DataException, "Incorrect date format")

	//regDate = regexp.MustCompile(`^(?P<year>[0-9]+)[-](?P<month>[0-9]+)[-](?P<day>[0-9]+)$`)
	ErrInvalidDateAddInterval = errors.New(errno.DataException, "Beyond the range of date")
)
View Source
var (
	ErrIncorrectDatetimeValue     = errors.New(errno.DataException, "Incorrect datetime format")
	ErrInvalidDatetimeAddInterval = errors.New(errno.DataException, "Beyond the range of datetime")
)
View Source
var Decimal128Max = Decimal128{}
View Source
var Decimal128Min = Decimal128{}
View Source
var (
	ErrIntervalNumOverflow = errors.New(errno.DataException, "Interval num overflow")
)
View Source
var (
	ErrInvalidTimestampAddInterval = errors.New(errno.DataException, "Beyond the range of timestamp")
)
View Source
var OneSecInMicroSeconds = uint32(1000000)
View Source
var Types map[string]T = map[string]T{
	"bool": T_bool,

	"tinyint":  T_int8,
	"smallint": T_int16,
	"int":      T_int32,
	"integer":  T_int32,
	"bigint":   T_int64,

	"tinyint unsigned":  T_uint8,
	"smallint unsigned": T_uint16,
	"int unsigned":      T_uint32,
	"integer unsigned":  T_uint32,
	"bigint unsigned":   T_uint64,

	"decimal64":  T_decimal64,
	"decimal128": T_decimal128,

	"float":  T_float32,
	"double": T_float64,

	"date":      T_date,
	"datetime":  T_datetime,
	"timestamp": T_timestamp,
	"interval":  T_interval,

	"char":    T_char,
	"varchar": T_varchar,

	"json": T_json,
}

Functions

func AlignDecimal128UsingScaleDiffBatch added in v0.5.0

func AlignDecimal128UsingScaleDiffBatch(src, dst []Decimal128, scaleDiff int32)

void align_int128_using_scale_diff(void* src, void* dst, void* length, void* scale_diff) {

func AppendBoolToByteArray added in v0.5.0

func AppendBoolToByteArray(b bool, arr []byte) []byte

func CompareDecimal128Decimal128

func CompareDecimal128Decimal128(a, b Decimal128, aScale, bScale int32) (result int64)

func CompareDecimal128Decimal128Aligned

func CompareDecimal128Decimal128Aligned(a, b Decimal128) (result int64)

func CompareDecimal64Decimal64

func CompareDecimal64Decimal64(a, b Decimal64, aScale, bScale int32) (result int64)

CompareDecimal64Decimal64 returns -1 if a < b, returns 1 if a > b, returns 0 if a == b

func CompareDecimal64Decimal64Aligned

func CompareDecimal64Decimal64Aligned(a, b Decimal64) (result int64)

func Decimal128IsNegative

func Decimal128IsNegative(a Decimal128) (result bool)

func Decimal128IsNotZero

func Decimal128IsNotZero(a Decimal128) (result bool)

func Decimal128IsPositive added in v0.5.0

func Decimal128IsPositive(a Decimal128) (result bool)

func Decimal128IsZero

func Decimal128IsZero(a Decimal128) (result bool)

func JudgeIntervalNumOverflow added in v0.5.0

func JudgeIntervalNumOverflow(num int64, it IntervalType) error

func LastDay added in v0.5.0

func LastDay(year uint16, month uint8) int

func ModDecimal128By10Abs

func ModDecimal128By10Abs(a Decimal128) (result int64)

func ParseBool added in v0.5.0

func ParseBool(s string) (bool, error)

func ParseValueToBool added in v0.5.0

func ParseValueToBool(num *tree.NumVal) (bool, error)

func TypeSize added in v0.5.0

func TypeSize(oid T) int

func UnitIsDayOrLarger added in v0.5.0

func UnitIsDayOrLarger(it IntervalType) bool

if interval type unit is day or larger, we return true else return false use to judge a string whether need to become date/datetime type when we use date_add/sub(str string, interval type)

func ValidTimestamp added in v0.5.0

func ValidTimestamp(timestamp Timestamp) bool

Types

type Bytes

type Bytes struct {
	Data    []byte
	Offsets []uint32
	Lengths []uint32
}

func (*Bytes) Append

func (a *Bytes) Append(vs [][]byte) error

func (*Bytes) AppendOnce added in v0.5.0

func (a *Bytes) AppendOnce(v []byte)

func (*Bytes) Get

func (a *Bytes) Get(n int64) []byte

func (*Bytes) Reset

func (a *Bytes) Reset()

func (*Bytes) String

func (a *Bytes) String() string

func (*Bytes) Swap

func (a *Bytes) Swap(i, j int64)

func (*Bytes) Window

func (a *Bytes) Window(start, end int) *Bytes

type Date

type Date int32

func FromCalendar

func FromCalendar(year int32, month, day uint8) Date

func ParseDate

func ParseDate(s string) (Date, error)

ParseDate will parse a string to be a Date Support Format: `yyyy-mm-dd` `yyyy-mm-d` `yyyy-m-dd` `yyyy-m-d` `yyyymmdd`

func ParseDateCast added in v0.5.0

func ParseDateCast(s string) (Date, error)

ParseDate will parse a string to be a Date (this is used for cast string to date,it's different from above) Support Format: we exchange '.' with '-' anyway. `yyyy-mm-dd` `yyyymmdd` `yyyy-mm.dd` `yyyy-mm.dd hh` `yyyy-mm.dd hh:mm:ss` `yyyy-mm.dd hh:mm:ss.(msc)`

func Today

func Today() Date

Holds number of days since January 1, year 1 in Gregorian calendar

func (Date) Calendar

func (d Date) Calendar(full bool) (year int32, month, day uint8, yday uint16)

func (Date) Day added in v0.5.0

func (d Date) Day() uint8

func (Date) DayOfWeek

func (d Date) DayOfWeek() Weekday

func (Date) DayOfYear

func (d Date) DayOfYear() uint16

func (Date) Month

func (d Date) Month() uint8

func (Date) Quarter added in v0.5.0

func (d Date) Quarter() uint32

func (Date) String

func (d Date) String() string

func (Date) ToTime

func (d Date) ToTime() Datetime

func (Date) ToTimeUTC added in v0.5.0

func (d Date) ToTimeUTC() Timestamp

func (Date) WeekOfYear

func (d Date) WeekOfYear() (year int32, week uint8)

func (Date) WeekOfYear2 added in v0.5.0

func (d Date) WeekOfYear2() uint8

func (Date) Year

func (d Date) Year() uint16

Year takes a date and returns an uint16 number as the year of this date

func (Date) YearMonth added in v0.5.0

func (d Date) YearMonth() uint32

func (Date) YearMonthStr added in v0.5.0

func (d Date) YearMonthStr() string

type Datetime

type Datetime int64

func FromClock

func FromClock(year int32, month, day, hour, min, sec uint8, msec uint32) Datetime

func FromUnix added in v0.5.0

func FromUnix(time int64) Datetime

func Now

func Now() Datetime

func ParseDatetime

func ParseDatetime(s string, precision int32) (Datetime, error)

ParseDatetime will parse a string to be a Datetime Support Format: 1. all the Date value 2. yyyy-mm-dd hh:mm:ss(.msec) now support mm/dd/hh/mm/ss can be single number 3. yyyymmddhhmmss(.msec) during parsing, the Datetime value will be rounded(away from zero) to the predefined precision, for example: Datetime(3) input string parsing result

"1999-09-09 11:11:11.1234"		"1999-09-09 11:11:11.123"
"1999-09-09 11:11:11.1235"		"1999-09-09 11:11:11.124"
"1999-09-09 11:11:11.9994"      "1999-09-09 11:11:11.999"
"1999-09-09 11:11:11.9995"      "1999-09-09 11:11:12.000"

func TimestampToDatetime added in v0.5.0

func TimestampToDatetime(xs []Timestamp, rs []Datetime) ([]Datetime, error)

func (Datetime) AddDateTime added in v0.5.0

func (dt Datetime) AddDateTime(date gotime.Time, addMsec, addSec, addMin, addHour, addDay, addMonth, addYear int64, timeType TimeType) (Datetime, bool)

func (Datetime) AddInterval added in v0.5.0

func (dt Datetime) AddInterval(nums int64, its IntervalType, timeType TimeType) (Datetime, bool)

AddInterval now date or datetime use the function to add/sub date, we need a bool arg to tell isDate/isDatetime date/datetime have different regions, so we don't use same valid function return type bool means the if the date/datetime is valid

func (Datetime) Clock

func (dt Datetime) Clock() (hour, min, sec int8)

func (Datetime) ConvertToGoTime added in v0.5.0

func (dt Datetime) ConvertToGoTime() gotime.Time

func (Datetime) Day added in v0.5.0

func (dt Datetime) Day() uint8

func (Datetime) DayHourStr added in v0.5.0

func (dt Datetime) DayHourStr() string

func (Datetime) DayMicrosecondStr added in v0.5.0

func (dt Datetime) DayMicrosecondStr() string

func (Datetime) DayMinuteStr added in v0.5.0

func (dt Datetime) DayMinuteStr() string

func (Datetime) DaySecondStr added in v0.5.0

func (dt Datetime) DaySecondStr() string

func (Datetime) Hour added in v0.5.0

func (dt Datetime) Hour() int8

func (Datetime) HourMicrosecondStr added in v0.5.0

func (dt Datetime) HourMicrosecondStr() string

func (Datetime) HourMinuteStr added in v0.5.0

func (dt Datetime) HourMinuteStr() string

func (Datetime) HourSecondStr added in v0.5.0

func (dt Datetime) HourSecondStr() string

func (Datetime) MicroSec added in v0.5.0

func (dt Datetime) MicroSec() int64

func (Datetime) Minute added in v0.5.0

func (dt Datetime) Minute() int8

func (Datetime) MinuteMicrosecondStr added in v0.5.0

func (dt Datetime) MinuteMicrosecondStr() string

func (Datetime) MinuteSecondStr added in v0.5.0

func (dt Datetime) MinuteSecondStr() string

func (Datetime) Month

func (dt Datetime) Month() uint8

func (Datetime) Sec added in v0.5.0

func (dt Datetime) Sec() int8

func (Datetime) SecondMicrosecondStr added in v0.5.0

func (dt Datetime) SecondMicrosecondStr() string

func (Datetime) String

func (dt Datetime) String() string

func (Datetime) String2 added in v0.5.0

func (dt Datetime) String2(precision int32) string

func (Datetime) ToDate

func (dt Datetime) ToDate() Date

func (Datetime) ToInt64 added in v0.5.0

func (dt Datetime) ToInt64() int64

func (Datetime) UTC

func (dt Datetime) UTC() Datetime

UTC turn local datetime to utc datetime

func (Datetime) UnixTimestamp added in v0.5.0

func (dt Datetime) UnixTimestamp() int64

func (Datetime) WeekOfYear added in v0.5.0

func (dt Datetime) WeekOfYear() (int32, uint8)

func (Datetime) Year

func (dt Datetime) Year() uint16

func (Datetime) YearMonthStr added in v0.5.0

func (dt Datetime) YearMonthStr() string

type Decimal added in v0.5.0

type Decimal interface {
	Decimal64 | Decimal128
}

type Decimal128

type Decimal128 struct {
	Lo int64
	Hi int64
}

func AddDecimal128ByInt64

func AddDecimal128ByInt64(a Decimal128, value int64) (result Decimal128)

func Decimal128Add

func Decimal128Add(a, b Decimal128, aScale, bScale int32) (result Decimal128)

func Decimal128AddAligned

func Decimal128AddAligned(a, b Decimal128) (result Decimal128)

func Decimal128Decimal128Div

func Decimal128Decimal128Div(a, b Decimal128, aScale, bScale int32) (result Decimal128)

func Decimal128Decimal128DivAligned added in v0.5.0

func Decimal128Decimal128DivAligned(a, b Decimal128) (result Decimal128)

func Decimal128Decimal128Mul

func Decimal128Decimal128Mul(a Decimal128, b Decimal128) (result Decimal128)

func Decimal128Int64Div added in v0.5.0

func Decimal128Int64Div(a Decimal128, b int64) (result Decimal128)

func Decimal128Int64Mul added in v0.5.0

func Decimal128Int64Mul(a Decimal128, b int64) (result Decimal128)

func Decimal128Sub

func Decimal128Sub(a, b Decimal128, aScale, bScale int32) (result Decimal128)

func Decimal128SubAligned

func Decimal128SubAligned(a, b Decimal128) (result Decimal128)

func Decimal64Decimal64Div

func Decimal64Decimal64Div(a, b Decimal64, aScale, bScale int32) (result Decimal128)

func Decimal64Decimal64Mul

func Decimal64Decimal64Mul(a Decimal64, b Decimal64) (result Decimal128)

func Decimal64ToDecimal128

func Decimal64ToDecimal128(a Decimal64) (result Decimal128)

func DivideDecimal128By10

func DivideDecimal128By10(a Decimal128) (result Decimal128)

func InitDecimal128

func InitDecimal128(value int64) (result Decimal128)

func InitDecimal128UsingUint added in v0.5.0

func InitDecimal128UsingUint(value uint64) (result Decimal128)

func NegDecimal128

func NegDecimal128(a Decimal128) (result Decimal128)

func ParseStringToDecimal128

func ParseStringToDecimal128(s string, precision, scale int32) (result Decimal128, err error)

func ParseStringToDecimal128WithoutTable

func ParseStringToDecimal128WithoutTable(s string) (result Decimal128, scale int32, err error)

func ScaleDecimal128By10

func ScaleDecimal128By10(a Decimal128) (result Decimal128)

func (Decimal128) Decimal128ToString

func (a Decimal128) Decimal128ToString(scale int32) []byte

type Decimal64

type Decimal64 int64

func AlignDecimal64UsingScaleDiffBatch added in v0.5.0

func AlignDecimal64UsingScaleDiffBatch(src, dst []Decimal64, scaleDiff int32) []Decimal64

func Decimal64Add

func Decimal64Add(a, b Decimal64, aScale, bScale int32) (result Decimal64)

func Decimal64AddAligned

func Decimal64AddAligned(a, b Decimal64) (result Decimal64)

func Decimal64Int64Mul added in v0.5.0

func Decimal64Int64Mul(a Decimal64, b int64) (result Decimal64)

func Decimal64Sub

func Decimal64Sub(a, b Decimal64, aScale, bScale int32) (result Decimal64)

func Decimal64SubAligned

func Decimal64SubAligned(a, b Decimal64) (result Decimal64)

func InitDecimal64 added in v0.5.0

func InitDecimal64(value int64, scale int64) (result Decimal64)

func ParseStringToDecimal64

func ParseStringToDecimal64(s string, precision, scale int32) (result Decimal64, err error)

todo: use strconv to simplify this code

func ScaleDecimal64

func ScaleDecimal64(a Decimal64, b int64) (result Decimal64)

func ScaleDecimal64By10

func ScaleDecimal64By10(a Decimal64) (result Decimal64)

func (Decimal64) Decimal64ToString

func (a Decimal64) Decimal64ToString(scale int32) []byte

type Floats added in v0.5.0

type Floats interface {
	float32 | float64
}

type Generic added in v0.5.0

type Generic interface {
	Ints | UInts | Floats | Date | Datetime | Timestamp | Decimal64
}

type IntervalType added in v0.5.0

type IntervalType int8
const (
	IntervalTypeInvalid IntervalType = iota
	MicroSecond
	Second
	Minute
	Hour
	Day
	Week
	Month
	Quarter
	Year
	Second_MicroSecond
	Minute_MicroSecond
	Minute_Second
	Hour_MicroSecond
	Hour_Second
	Hour_Minute
	Day_MicroSecond
	Day_Second
	Day_Minute
	Day_Hour
	Year_Month
	IntervalTypeMax
)

func IntervalTypeOf added in v0.5.0

func IntervalTypeOf(s string) (IntervalType, error)

func NormalizeInterval added in v0.5.0

func NormalizeInterval(s string, it IntervalType) (ret int64, rettype IntervalType, err error)

func (IntervalType) String added in v0.5.0

func (it IntervalType) String() string

type Ints added in v0.5.0

type Ints interface {
	int8 | int16 | int32 | int64
}

type Number added in v0.5.0

type Number interface {
	Ints | UInts | Floats | Decimal
}

type String added in v0.5.0

type String interface {
	Get(int64) []byte
}

type T

type T uint8
const (
	// any family
	T_any T = T(plan.Type_ANY)

	// bool family
	T_bool T = T(plan.Type_BOOL)

	// numeric/integer family
	T_int8   T = T(plan.Type_INT8)
	T_int16  T = T(plan.Type_INT16)
	T_int32  T = T(plan.Type_INT32)
	T_int64  T = T(plan.Type_INT64)
	T_uint8  T = T(plan.Type_UINT8)
	T_uint16 T = T(plan.Type_UINT16)
	T_uint32 T = T(plan.Type_UINT32)
	T_uint64 T = T(plan.Type_UINT64)

	// numeric/float family - unsigned attribute is deprecated
	T_float32 T = T(plan.Type_FLOAT32)
	T_float64 T = T(plan.Type_FLOAT64)

	// date family
	T_date      T = T(plan.Type_DATE)
	T_datetime  T = T(plan.Type_DATETIME)
	T_timestamp T = T(plan.Type_TIMESTAMP)
	T_interval  T = T(plan.Type_INTERVAL)
	T_time      T = T(plan.Type_TIME)

	// string family
	T_char    T = T(plan.Type_CHAR)
	T_varchar T = T(plan.Type_VARCHAR)

	// json family
	T_json T = T(plan.Type_JSON)

	// numeric/decimal family - unsigned attribute is deprecated
	T_decimal64  = T(plan.Type_DECIMAL64)
	T_decimal128 = T(plan.Type_DECIMAL128)

	// system family
	T_sel   T = T(plan.Type_SEL)   //selection
	T_tuple T = T(plan.Type_TUPLE) // immutable, size = 24
)

func (T) FixedLength

func (t T) FixedLength() int

dangerous code, use TypeLen() if you don't want -8, -16, -24

func (T) GoGoType

func (t T) GoGoType() string

GoGoType returns special go type string for T

func (T) GoType

func (t T) GoType() string

GoType returns go type string for T

func (T) OidString

func (t T) OidString() string

OidString returns T string

func (T) String

func (t T) String() string

func (T) ToType

func (t T) ToType() Type

func (T) TypeLen

func (t T) TypeLen() int

TypeLen returns type's length whose type oid is T

type TimeType added in v0.5.0

type TimeType int32

type Timestamp added in v0.5.0

type Timestamp int64
var TimestampMaxValue Timestamp
var TimestampMinValue Timestamp

func DateToTimestamp added in v0.5.0

func DateToTimestamp(xs []Date, rs []Timestamp) ([]Timestamp, error)

func DatetimeToTimestamp added in v0.5.0

func DatetimeToTimestamp(xs []Datetime, rs []Timestamp) ([]Timestamp, error)

func FromClockUTC added in v0.5.0

func FromClockUTC(year int32, month, day, hour, min, sec uint8, msec uint32) Timestamp

FromClockUTC gets the utc time value in Timestamp

func NowUTC added in v0.5.0

func NowUTC() Timestamp

func ParseTimestamp added in v0.5.0

func ParseTimestamp(s string, precision int32) (Timestamp, error)

ParseTimestamp will parse a string to be a Timestamp Support Format: 1. all the Date value 2. yyyy-mm-dd hh:mm:ss(.msec) 3. yyyymmddhhmmss(.msec)

func UnixToTimestamp added in v0.5.0

func UnixToTimestamp(time int64) Timestamp

func (Timestamp) String added in v0.5.0

func (ts Timestamp) String() string

func (Timestamp) String2 added in v0.5.0

func (ts Timestamp) String2(precision int32) string

String2 stringify timestamp, including its fractional seconds precision part(fsp)

type Type

type Type struct {
	Oid  T     `json:"oid,string"`
	Size int32 `json:"size,string"` // e.g. int8.Size = 1, int16.Size = 2, char.Size = 24(SliceHeader size)

	// Width means max Display width for float and double, char and varchar // todo: need to add new attribute DisplayWidth ?
	Width int32 `json:"width,string"`

	Scale int32 `json:"Scale,string"`

	Precision int32 `json:"Precision,string"`
}

func New added in v0.5.0

func New(oid T, width, scale, precision int32) Type

func (Type) Eq

func (a Type) Eq(b Type) bool

func (Type) IsString added in v0.5.1

func (t Type) IsString() bool

func (Type) String

func (t Type) String() string

func (Type) TypeSize added in v0.5.1

func (t Type) TypeSize() int

type UInts added in v0.5.0

type UInts interface {
	uint8 | uint16 | uint32 | uint64
}

type Weekday

type Weekday uint8
const (
	Sunday Weekday = iota
	Monday
	Tuesday
	Wednesday
	Thursday
	Friday
	Saturday
)

Jump to

Keyboard shortcuts

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