Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,10 @@ func (b *builtinCastTimeAsDecimalSig) vecEvalDecimal(input *chunk.Chunk, result
if result.IsNull(i) {
continue
}
decimalValue, err := types.ProduceDecWithSpecifiedTp(times[i].ToNumber(), b.tp, sc)
if err != nil {
times[i].FillNumber(&decs[i])
if _, err := types.ProduceDecWithSpecifiedTp(&decs[i], b.tp, sc); err != nil {
return err
}
decs[i] = *decimalValue
}
return nil
}
Expand Down
14 changes: 10 additions & 4 deletions types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,17 @@ const dateFormat = "%Y%m%d"
// 2012-12-12T10:10:10 -> 20121212101010
// 2012-12-12T10:10:10.123456 -> 20121212101010.123456
func (t Time) ToNumber() *MyDecimal {
dec := new(MyDecimal)
t.FillNumber(dec)
return dec
}

// FillNumber is the same as ToNumber,
// but reuses input decimal instead of allocating one.
func (t Time) FillNumber(dec *MyDecimal) {
if t.IsZero() {
return &MyDecimal{}
dec.FromInt(0)
return
}

// Fix issue #1046
Expand All @@ -314,12 +323,9 @@ func (t Time) ToNumber() *MyDecimal {
s1 := fmt.Sprintf("%s.%06d", s, t.Time.Microsecond())
s = s1[:len(s)+int(t.Fsp)+1]
}

// We skip checking error here because time formatted string can be parsed certainly.
dec := new(MyDecimal)
err = dec.FromString([]byte(s))
terror.Log(errors.Trace(err))
return dec
}

// Convert converts t with type tp.
Expand Down