Skip to content

Commit

Permalink
expression: implement vectorized evaluation for 'builtinCastStringAsS…
Browse files Browse the repository at this point in the history
…tringSig' (#12538)
  • Loading branch information
tsthght authored and qw4990 committed Oct 9, 2019
1 parent 8bd484b commit b22ff44
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
37 changes: 35 additions & 2 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,11 +792,44 @@ func (b *builtinCastDecimalAsDurationSig) vecEvalDuration(input *chunk.Chunk, re
}

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

func (b *builtinCastStringAsStringSig) vecEvalString(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
}

var res string
var isNull bool
sc := b.ctx.GetSessionVars().StmtCtx
result.ReserveString(n)
for i := 0; i < n; i++ {
if buf.IsNull(i) {
result.AppendNull()
continue
}
res, err = types.ProduceStrWithSpecifiedTp(buf.GetString(i), b.tp, sc, false)
if err != nil {
return err
}
res, isNull, err = padZeroForBinaryType(res, b.tp, b.ctx)
if err != nil {
return err
}
if isNull {
result.AppendNull()
continue
}
result.AppendString(res)
}
return nil
}

func (b *builtinCastJSONAsDurationSig) vectorized() bool {
Expand Down
1 change: 1 addition & 0 deletions expression/builtin_cast_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{
},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETInt}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDatetime}},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDuration}},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDatetime}},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETTimestamp}},
Expand Down

0 comments on commit b22ff44

Please sign in to comment.