Skip to content

Commit

Permalink
expression: implement vectorized evaluation for 'builtinCastTimeAsJSO…
Browse files Browse the repository at this point in the history
…NSig' (pingcap#12795)
  • Loading branch information
tsthght authored and XiaTianliang committed Dec 21, 2019
1 parent ec2b33c commit 4155b3b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
28 changes: 26 additions & 2 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,35 @@ func (b *builtinCastRealAsRealSig) vectorized() bool {
}

func (b *builtinCastTimeAsJSONSig) vectorized() bool {
return false
return true
}

func (b *builtinCastTimeAsJSONSig) vecEvalJSON(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETDatetime, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err = b.args[0].VecEvalTime(b.ctx, input, buf); err != nil {
return err
}

result.ReserveJSON(n)
tms := buf.Times()
for i := 0; i < n; i++ {
if buf.IsNull(i) {
result.AppendNull()
continue
}

tp := tms[i].Type
if tp == mysql.TypeDatetime || tp == mysql.TypeTimestamp {
tms[i].Fsp = types.MaxFsp
}
result.AppendJSON(json.CreateBinary(tms[i].String()))
}
return nil
}

func (b *builtinCastRealAsStringSig) vectorized() bool {
Expand Down
1 change: 1 addition & 0 deletions expression/builtin_cast_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETDuration, childrenTypes: []types.EvalType{types.ETDuration}},
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETInt}},
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETReal}},
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETDatetime}},
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETJson}},
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETDecimal}},
},
Expand Down

0 comments on commit 4155b3b

Please sign in to comment.