Skip to content

Commit

Permalink
expression: implement vectorized evaluation for `builtinCastRealAsJSO…
Browse files Browse the repository at this point in the history
…NSig` (#12673)
  • Loading branch information
js00070 authored and sre-bot committed Oct 14, 2019
1 parent 876e794 commit fb273d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 22 additions & 2 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/types/json"
"github.com/pingcap/tidb/util/chunk"
)

Expand Down Expand Up @@ -293,11 +294,30 @@ func (b *builtinCastIntAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk.
}

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

func (b *builtinCastRealAsJSONSig) vecEvalJSON(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETReal, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalReal(b.ctx, input, buf); err != nil {
return err
}
f64s := buf.Float64s()
result.ReserveJSON(n)
for i := 0; i < n; i++ {
// FIXME: `select json_type(cast(1111.11 as json))` should return `DECIMAL`, we return `DOUBLE` now.```
if buf.IsNull(i) {
result.AppendNull()
} else {
result.AppendJSON(json.CreateBinary(f64s[i]))
}
}
return nil
}

func (b *builtinCastJSONAsRealSig) vectorized() bool {
Expand Down
2 changes: 2 additions & 0 deletions expression/builtin_cast_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETReal}},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETJson}},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDecimal}},

{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETReal}},
},
}

Expand Down

0 comments on commit fb273d9

Please sign in to comment.