Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinIsIPv6Sig (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyCpp authored and qw4990 committed Oct 30, 2019
1 parent 9cae286 commit 08d26a3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
31 changes: 29 additions & 2 deletions expression/builtin_miscellaneous_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,38 @@ func (b *builtinStringAnyValueSig) vecEvalString(input *chunk.Chunk, result *chu
}

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

func (b *builtinIsIPv6Sig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalString(b.ctx, input, buf); err != nil {
return err
}
result.ResizeInt64(n, false)
i64s := result.Int64s()
for i := 0; i < n; i++ {
// Note that even when the i-th input string is null, the output is
// 0 instead of null, therefore we do not set the null bit mask in
// result's corresponding row.
// See https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_is-ipv6
if buf.IsNull(i) {
i64s[i] = 0
} else {
ipStr := buf.GetString(i)
if ip := net.ParseIP(ipStr); ip != nil && !isIPv4(ipStr) {
i64s[i] = 1
} else {
i64s[i] = 0
}
}
}
return nil
}

func (b *builtinNameConstStringSig) vectorized() bool {
Expand Down
4 changes: 3 additions & 1 deletion expression/builtin_miscellaneous_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ var vecBuiltinMiscellaneousCases = map[string][]vecExprBenchCase{
ast.Inet6Aton: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{&ipv6StrGener{}}},
},
ast.IsIPv6: {},
ast.IsIPv6: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString}},
},
ast.Sleep: {},
ast.UUID: {},
ast.Inet6Ntoa: {},
Expand Down

0 comments on commit 08d26a3

Please sign in to comment.