From 8fb10934d015c28cfb4843f36474ecbbba2d8630 Mon Sep 17 00:00:00 2001 From: Zhang Zhiyi <909645105@qq.com> Date: Mon, 11 Nov 2019 15:42:13 +0800 Subject: [PATCH] expression: implement vectorized evaluation for `builtinHexIntArgSig` (#13330) --- expression/builtin_string_vec.go | 22 ++++++++++++++++++++-- expression/builtin_string_vec_test.go | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/expression/builtin_string_vec.go b/expression/builtin_string_vec.go index 6cbb4cf7d7824..e6eed321a320e 100644 --- a/expression/builtin_string_vec.go +++ b/expression/builtin_string_vec.go @@ -1808,11 +1808,29 @@ func (b *builtinSubstringBinary3ArgsSig) vecEvalString(input *chunk.Chunk, resul } func (b *builtinHexIntArgSig) vectorized() bool { - return false + return true } func (b *builtinHexIntArgSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error { - return errors.Errorf("not implemented") + n := input.NumRows() + buf, err := b.bufAllocator.get(types.ETInt, n) + if err != nil { + return err + } + defer b.bufAllocator.put(buf) + if err := b.args[0].VecEvalInt(b.ctx, input, buf); err != nil { + return err + } + result.ReserveString(n) + i64s := buf.Int64s() + for i := 0; i < n; i++ { + if buf.IsNull(i) { + result.AppendNull() + continue + } + result.AppendString(strings.ToUpper(fmt.Sprintf("%x", uint64(i64s[i])))) + } + return nil } func (b *builtinFieldIntSig) vectorized() bool { diff --git a/expression/builtin_string_vec_test.go b/expression/builtin_string_vec_test.go index b18004fc46910..3c18a6414a5f7 100644 --- a/expression/builtin_string_vec_test.go +++ b/expression/builtin_string_vec_test.go @@ -102,6 +102,7 @@ var vecBuiltinStringCases = map[string][]vecExprBenchCase{ }, ast.Hex: { {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{&randHexStrGener{10, 100}}}, + {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETInt}}, }, ast.Unhex: { {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{&randHexStrGener{10, 100}}},