MCPcopy Create free account
hub / github.com/pingcap/tidb / flatten

Function flatten

pkg/tablecodec/tablecodec.go:399–435  ·  view source on GitHub ↗
(loc *time.Location, data types.Datum, ret *types.Datum)

Source from the content-addressed store, hash-verified

397}
398
399func flatten(loc *time.Location, data types.Datum, ret *types.Datum) error {
400 switch data.Kind() {
401 case types.KindMysqlTime:
402 // for mysql datetime, timestamp and date type
403 t := data.GetMysqlTime()
404 if t.Type() == mysql.TypeTimestamp && loc != nil && loc != time.UTC {
405 err := t.ConvertTimeZone(loc, time.UTC)
406 if err != nil {
407 return errors.Trace(err)
408 }
409 }
410 v, err := t.ToPackedUint()
411 ret.SetUint64(v)
412 return errors.Trace(err)
413 case types.KindMysqlDuration:
414 // for mysql time type
415 ret.SetInt64(int64(data.GetMysqlDuration().Duration))
416 return nil
417 case types.KindMysqlEnum:
418 ret.SetUint64(data.GetMysqlEnum().Value)
419 return nil
420 case types.KindMysqlSet:
421 ret.SetUint64(data.GetMysqlSet().Value)
422 return nil
423 case types.KindBinaryLiteral, types.KindMysqlBit:
424 // We don't need to handle errors here since the literal is ensured to be able to store in uint64 in convertToMysqlBit.
425 val, err := data.GetBinaryLiteral().ToInt(types.StrictContext)
426 if err != nil {
427 return errors.Trace(err)
428 }
429 ret.SetUint64(val)
430 return nil
431 default:
432 *ret = data
433 return nil
434 }
435}
436
437// DecodeColumnValue decodes data to a Datum according to the column info.
438func DecodeColumnValue(data []byte, ft *types.FieldType, loc *time.Location) (types.Datum, error) {

Callers 2

EncodeValueFunction · 0.70
EncodeOldRowFunction · 0.70

Calls 12

GetMysqlTimeMethod · 0.80
ConvertTimeZoneMethod · 0.80
ToPackedUintMethod · 0.80
GetMysqlDurationMethod · 0.80
GetMysqlEnumMethod · 0.80
GetMysqlSetMethod · 0.80
TypeMethod · 0.65
KindMethod · 0.45
SetUint64Method · 0.45
SetInt64Method · 0.45
ToIntMethod · 0.45
GetBinaryLiteralMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…