Skip to content

Commit

Permalink
expression: implement vectorized evaluation for 'builtinCastDecimalAs…
Browse files Browse the repository at this point in the history
…JSONSig' (#12803)
  • Loading branch information
tsthght authored and sre-bot committed Oct 18, 2019
1 parent c047835 commit 48c1571
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
29 changes: 27 additions & 2 deletions expression/builtin_cast_vec.go
Expand Up @@ -1005,11 +1005,36 @@ func (b *builtinCastJSONAsDurationSig) vecEvalDuration(input *chunk.Chunk, resul
}

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

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

result.ReserveJSON(n)
f64s := buf.Decimals()
var f float64
for i := 0; i < n; i++ {
if buf.IsNull(i) {
result.AppendNull()
continue
}
// FIXME: `select json_type(cast(1111.11 as json))` should return `DECIMAL`, we return `DOUBLE` now.
f, err = f64s[i].ToFloat64()
if err != nil {
return err
}
result.AppendJSON(json.CreateBinary(f))
}
return nil
}

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

Expand Down

0 comments on commit 48c1571

Please sign in to comment.