本文整理汇总了Golang中github.com/pingcap/tidb/util/types.Datum.GetMysqlDuration方法的典型用法代码示例。如果您正苦于以下问题:Golang Datum.GetMysqlDuration方法的具体用法?Golang Datum.GetMysqlDuration怎么用?Golang Datum.GetMysqlDuration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/util/types.Datum
的用法示例。
在下文中一共展示了Datum.GetMysqlDuration方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: flatten
func flatten(data types.Datum) (types.Datum, error) {
switch data.Kind() {
case types.KindMysqlTime:
// for mysql datetime, timestamp and date type
v, err := data.GetMysqlTime().ToPackedUint()
return types.NewUintDatum(v), errors.Trace(err)
case types.KindMysqlDuration:
// for mysql time type
data.SetInt64(int64(data.GetMysqlDuration().Duration))
return data, nil
case types.KindMysqlEnum:
data.SetUint64(data.GetMysqlEnum().Value)
return data, nil
case types.KindMysqlSet:
data.SetUint64(data.GetMysqlSet().Value)
return data, nil
case types.KindMysqlBit:
data.SetUint64(data.GetMysqlBit().Value)
return data, nil
case types.KindMysqlHex:
data.SetInt64(data.GetMysqlHex().Value)
return data, nil
default:
return data, nil
}
}
示例2: datumExpr
func datumExpr(d types.Datum) *tipb.Expr {
expr := new(tipb.Expr)
switch d.Kind() {
case types.KindInt64:
expr.Tp = tipb.ExprType_Int64
expr.Val = codec.EncodeInt(nil, d.GetInt64())
case types.KindUint64:
expr.Tp = tipb.ExprType_Uint64
expr.Val = codec.EncodeUint(nil, d.GetUint64())
case types.KindString:
expr.Tp = tipb.ExprType_String
expr.Val = d.GetBytes()
case types.KindBytes:
expr.Tp = tipb.ExprType_Bytes
expr.Val = d.GetBytes()
case types.KindFloat32:
expr.Tp = tipb.ExprType_Float32
expr.Val = codec.EncodeFloat(nil, d.GetFloat64())
case types.KindFloat64:
expr.Tp = tipb.ExprType_Float64
expr.Val = codec.EncodeFloat(nil, d.GetFloat64())
case types.KindMysqlDuration:
expr.Tp = tipb.ExprType_MysqlDuration
expr.Val = codec.EncodeInt(nil, int64(d.GetMysqlDuration().Duration))
case types.KindMysqlDecimal:
expr.Tp = tipb.ExprType_MysqlDecimal
expr.Val = codec.EncodeDecimal(nil, d)
default:
expr.Tp = tipb.ExprType_Null
}
return expr
}
示例3: flatten
func flatten(data types.Datum) (types.Datum, error) {
switch data.Kind() {
case types.KindMysqlTime:
// for mysql datetime, timestamp and date type
b, err := data.GetMysqlTime().Marshal()
if err != nil {
return types.NewDatum(nil), errors.Trace(err)
}
return types.NewDatum(b), nil
case types.KindMysqlDuration:
// for mysql time type
data.SetInt64(int64(data.GetMysqlDuration().Duration))
return data, nil
case types.KindMysqlDecimal:
data.SetString(data.GetMysqlDecimal().String())
return data, nil
case types.KindMysqlEnum:
data.SetUint64(data.GetMysqlEnum().Value)
return data, nil
case types.KindMysqlSet:
data.SetUint64(data.GetMysqlSet().Value)
return data, nil
case types.KindMysqlBit:
data.SetUint64(data.GetMysqlBit().Value)
return data, nil
case types.KindMysqlHex:
data.SetInt64(data.GetMysqlHex().Value)
return data, nil
default:
return data, nil
}
}
示例4: dumpTextValue
func dumpTextValue(mysqlType uint8, value types.Datum) ([]byte, error) {
switch value.Kind() {
case types.KindInt64:
return strconv.AppendInt(nil, value.GetInt64(), 10), nil
case types.KindUint64:
return strconv.AppendUint(nil, value.GetUint64(), 10), nil
case types.KindFloat32:
return strconv.AppendFloat(nil, value.GetFloat64(), 'f', -1, 32), nil
case types.KindFloat64:
return strconv.AppendFloat(nil, value.GetFloat64(), 'f', -1, 64), nil
case types.KindString, types.KindBytes:
return value.GetBytes(), nil
case types.KindMysqlTime:
return hack.Slice(value.GetMysqlTime().String()), nil
case types.KindMysqlDuration:
return hack.Slice(value.GetMysqlDuration().String()), nil
case types.KindMysqlDecimal:
return hack.Slice(value.GetMysqlDecimal().String()), nil
case types.KindMysqlEnum:
return hack.Slice(value.GetMysqlEnum().String()), nil
case types.KindMysqlSet:
return hack.Slice(value.GetMysqlSet().String()), nil
case types.KindMysqlBit:
return hack.Slice(value.GetMysqlBit().ToString()), nil
case types.KindMysqlHex:
return hack.Slice(value.GetMysqlHex().ToString()), nil
default:
return nil, errInvalidType.Gen("invalid type %T", value)
}
}
示例5: coerceArithmetic
func coerceArithmetic(a types.Datum) (d types.Datum, err error) {
switch a.Kind() {
case types.KindString, types.KindBytes:
// MySQL will convert string to float for arithmetic operation
f, err := types.StrToFloat(a.GetString())
if err != nil {
return d, errors.Trace(err)
}
d.SetFloat64(f)
return d, errors.Trace(err)
case types.KindMysqlTime:
// if time has no precision, return int64
t := a.GetMysqlTime()
de := t.ToNumber()
if t.Fsp == 0 {
d.SetInt64(de.IntPart())
return d, nil
}
d.SetMysqlDecimal(de)
return d, nil
case types.KindMysqlDuration:
// if duration has no precision, return int64
du := a.GetMysqlDuration()
de := du.ToNumber()
if du.Fsp == 0 {
d.SetInt64(de.IntPart())
return d, nil
}
d.SetMysqlDecimal(de)
return d, nil
case types.KindMysqlHex:
d.SetFloat64(a.GetMysqlHex().ToNumber())
return d, nil
case types.KindMysqlBit:
d.SetFloat64(a.GetMysqlBit().ToNumber())
return d, nil
case types.KindMysqlEnum:
d.SetFloat64(a.GetMysqlEnum().ToNumber())
return d, nil
case types.KindMysqlSet:
d.SetFloat64(a.GetMysqlSet().ToNumber())
return d, nil
default:
return a, nil
}
}
示例6: datumToPBExpr
func (b *executorBuilder) datumToPBExpr(client kv.Client, d types.Datum) *tipb.Expr {
var tp tipb.ExprType
var val []byte
switch d.Kind() {
case types.KindNull:
tp = tipb.ExprType_Null
case types.KindInt64:
tp = tipb.ExprType_Int64
val = codec.EncodeInt(nil, d.GetInt64())
case types.KindUint64:
tp = tipb.ExprType_Uint64
val = codec.EncodeUint(nil, d.GetUint64())
case types.KindString:
tp = tipb.ExprType_String
val = d.GetBytes()
case types.KindBytes:
tp = tipb.ExprType_Bytes
val = d.GetBytes()
case types.KindFloat32:
tp = tipb.ExprType_Float32
val = codec.EncodeFloat(nil, d.GetFloat64())
case types.KindFloat64:
tp = tipb.ExprType_Float64
val = codec.EncodeFloat(nil, d.GetFloat64())
case types.KindMysqlDuration:
tp = tipb.ExprType_MysqlDuration
val = codec.EncodeInt(nil, int64(d.GetMysqlDuration().Duration))
case types.KindMysqlDecimal:
tp = tipb.ExprType_MysqlDecimal
val = codec.EncodeDecimal(nil, d.GetMysqlDecimal())
default:
return nil
}
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tp)) {
return nil
}
return &tipb.Expr{Tp: tp.Enum(), Val: val}
}
示例7: convertDateFormat
func convertDateFormat(ctx context.Context, arg types.Datum, b byte) (types.Datum, error) {
var d types.Datum
var err error
switch b {
case 'b':
d, err = builtinMonthName([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(d.GetString()[:3])
}
case 'M':
d, err = builtinMonthName([]types.Datum{arg}, ctx)
case 'm':
d, err = builtinMonth([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'c':
d, err = builtinMonth([]types.Datum{arg}, ctx)
case 'D':
d, err = abbrDayOfMonth(arg, ctx)
case 'd':
d, err = builtinDayOfMonth([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'e':
d, err = builtinDayOfMonth([]types.Datum{arg}, ctx)
case 'j':
d, err = builtinDayOfYear([]types.Datum{arg}, ctx)
if err == nil {
d.SetString(fmt.Sprintf("%03d", d.GetInt64()))
}
case 'H', 'k':
d, err = builtinHour([]types.Datum{arg}, ctx)
if err == nil && b == 'H' && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'h', 'I', 'l':
d, err = builtinHour([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
if d.GetInt64() > 12 {
d.SetInt64(d.GetInt64() - 12)
} else if d.GetInt64() == 0 {
d.SetInt64(12)
}
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'i':
d, err = builtinMinute([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'p':
d, err = builtinHour([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
if d.GetInt64() < 12 {
d.SetString("AM")
break
}
d.SetString("PM")
}
case 'r':
d, err = to12Hour(arg, ctx)
case 'T':
d, err = builtinTime([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
duration := types.Duration{
Duration: d.GetMysqlDuration().Duration,
Fsp: 0}
d.SetMysqlDuration(duration)
}
case 'S', 's':
d, err = builtinSecond([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'f':
d, err = builtinMicroSecond([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%06d", d.GetInt64()))
}
case 'U':
d, err = builtinWeek([]types.Datum{arg, types.NewIntDatum(0)}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'u':
d, err = builtinWeek([]types.Datum{arg, types.NewIntDatum(1)}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'V':
d, err = builtinWeek([]types.Datum{arg, types.NewIntDatum(2)}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'v':
d, err = builtinWeek([]types.Datum{arg, types.NewIntDatum(3)}, ctx)
if err == nil && !d.IsNull() {
//.........这里部分代码省略.........