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

expression: bug fix for vectorized casting real as time #19485

Merged
merged 7 commits into from
Aug 29, 2020
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
7 changes: 6 additions & 1 deletion expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,12 @@ func (b *builtinCastRealAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk
if buf.IsNull(i) {
continue
}
tm, err := types.ParseTime(stmt, strconv.FormatFloat(f64s[i], 'f', -1, 64), b.tp.Tp, fsp)
fv := strconv.FormatFloat(f64s[i], 'f', -1, 64)
if fv == "0" {
times[i] = types.ZeroTime
continue
}
tm, err := types.ParseTime(stmt, fv, b.tp.Tp, fsp)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
return err
Expand Down
41 changes: 41 additions & 0 deletions expression/builtin_cast_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,47 @@ func (s *testEvaluatorSuite) TestVectorizedBuiltinCastFunc(c *C) {
testVectorizedBuiltinFunc(c, vecBuiltinCastCases)
}

func (s *testEvaluatorSuite) TestVectorizedCastRealAsTime(c *C) {
col := &Column{RetType: types.NewFieldType(mysql.TypeDouble), Index: 0}
baseFunc, err := newBaseBuiltinFunc(mock.NewContext(), "", []Expression{col})
if err != nil {
panic(err)
}
cast := &builtinCastRealAsTimeSig{baseFunc}

inputs := []*chunk.Chunk{
genCastRealAsTime(),
}

for _, input := range inputs {
result := chunk.NewColumn(types.NewFieldType(mysql.TypeDatetime), input.NumRows())
c.Assert(cast.vecEvalTime(input, result), IsNil)
for i := 0; i < input.NumRows(); i++ {
res, isNull, err := cast.evalTime(input.GetRow(i))
c.Assert(err, IsNil)
if isNull {
c.Assert(result.IsNull(i), IsTrue)
continue
}
c.Assert(result.IsNull(i), IsFalse)
c.Assert(result.GetTime(i).Compare(res), Equals, 0)
}
}
}

func genCastRealAsTime() *chunk.Chunk {
input := chunk.NewChunkWithCapacity([]*types.FieldType{types.NewFieldType(mysql.TypeDouble)}, 10)
gen := newDefaultRandGen()
for i := 0; i < 10; i++ {
if i < 5 {
input.AppendFloat64(0, 0)
} else {
input.AppendFloat64(0, gen.Float64()*100000)
}
}
return input
}

// for issue https://github.com/pingcap/tidb/issues/16825
func (s *testEvaluatorSuite) TestVectorizedCastStringAsDecimalWithUnsignedFlagInUnion(c *C) {
col := &Column{RetType: types.NewFieldType(mysql.TypeString), Index: 0}
Expand Down