Skip to content

Commit

Permalink
util/chunk: fix incorrect result when set duration to MutRow (#8725) (
Browse files Browse the repository at this point in the history
  • Loading branch information
winoros authored and winkyao committed Dec 20, 2018
1 parent f0c0621 commit f8d7b03
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions util/chunk/mutrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func makeMutRowColumn(in interface{}) *column {
copy(col.data[1:], x.Value)
return col
case types.Duration:
col := newMutRowFixedLenColumn(16)
*(*types.Duration)(unsafe.Pointer(&col.data[0])) = x
col := newMutRowFixedLenColumn(8)
*(*int64)(unsafe.Pointer(&col.data[0])) = int64(x.Duration)
return col
case types.Enum:
col := newMutRowVarLenColumn(len(x.Name) + 8)
Expand Down Expand Up @@ -249,7 +249,7 @@ func (mr MutRow) SetValue(colIdx int, val interface{}) {
case types.BinaryLiteral:
setMutRowBytes(col, x)
case types.Duration:
*(*types.Duration)(unsafe.Pointer(&col.data[0])) = x
*(*int64)(unsafe.Pointer(&col.data[0])) = int64(x.Duration)
case *types.MyDecimal:
*(*types.MyDecimal)(unsafe.Pointer(&col.data[0])) = *x
case types.Time:
Expand Down Expand Up @@ -288,7 +288,7 @@ func (mr MutRow) SetDatum(colIdx int, d types.Datum) {
case types.KindMysqlTime:
writeTime(col.data, d.GetMysqlTime())
case types.KindMysqlDuration:
*(*types.Duration)(unsafe.Pointer(&col.data[0])) = d.GetMysqlDuration()
*(*int64)(unsafe.Pointer(&col.data[0])) = int64(d.GetMysqlDuration().Duration)
case types.KindMysqlDecimal:
*(*types.MyDecimal)(unsafe.Pointer(&col.data[0])) = *d.GetMysqlDecimal()
case types.KindMysqlJSON:
Expand Down
11 changes: 11 additions & 0 deletions util/chunk/mutrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ func (s *testChunkSuite) TestMutRow(c *check.C) {
row = mutRow.ToRow()
c.Assert(row.GetJSON(0), check.DeepEquals, j)
c.Assert(row.GetTime(1), check.DeepEquals, t)

retTypes := []*types.FieldType{types.NewFieldType(mysql.TypeDuration)}
chk := New(retTypes, 1, 1)
dur, err := types.ParseDuration(sc, "01:23:45", 0)
c.Assert(err, check.IsNil)
chk.AppendDuration(0, dur)
mutRow = MutRowFromTypes(retTypes)
mutRow.SetValue(0, dur)
c.Assert(chk.columns[0].data, check.BytesEquals, mutRow.c.columns[0].data)
mutRow.SetDatum(0, types.NewDurationDatum(dur))
c.Assert(chk.columns[0].data, check.BytesEquals, mutRow.c.columns[0].data)
}

func BenchmarkMutRowSetRow(b *testing.B) {
Expand Down

0 comments on commit f8d7b03

Please sign in to comment.