Skip to content

Commit

Permalink
expression: implement vectorized evaluation for `builtinJSONUnquoteSi…
Browse files Browse the repository at this point in the history
…g` (#12841)
  • Loading branch information
js00070 authored and ngaut committed Oct 23, 2019
1 parent 7447361 commit a9c92e4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
26 changes: 24 additions & 2 deletions expression/builtin_json_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,31 @@ func (b *builtinJSONArrayAppendSig) vecEvalJSON(input *chunk.Chunk, result *chun
}

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

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

result.ReserveString(n)
for i := 0; i < n; i++ {
if buf.IsNull(i) {
result.AppendNull()
continue
}
res, err := buf.GetJSON(i).Unquote()
if err != nil {
return err
}
result.AppendString(res)
}
return nil
}
10 changes: 6 additions & 4 deletions expression/builtin_json_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ var vecBuiltinJSONCases = map[string][]vecExprBenchCase{
ast.JSONSearch: {},
ast.JSONReplace: {},
ast.JSONDepth: {{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETJson}}},
ast.JSONUnquote: {},
ast.JSONRemove: {},
ast.JSONMerge: {},
ast.JSONInsert: {},
ast.JSONUnquote: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{&jsonStringGener{}}},
},
ast.JSONRemove: {},
ast.JSONMerge: {},
ast.JSONInsert: {},
ast.JSONQuote: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETJson}},
},
Expand Down

0 comments on commit a9c92e4

Please sign in to comment.