Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util/chunk: fix incorrect result when set duration to MutRow #8725

Merged
merged 9 commits into from
Dec 19, 2018
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