Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: implement vectorized evaluation for 'builtinCastDurationAsStringSig' #12541

Merged
merged 9 commits into from
Oct 9, 2019
35 changes: 33 additions & 2 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,42 @@ func (b *builtinCastDurationAsDurationSig) vecEvalDuration(input *chunk.Chunk, r
}

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

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

sc := b.ctx.GetSessionVars().StmtCtx
result.ReserveString(n)
for i := 0; i < n; i++ {
if buf.IsNull(i) {
result.AppendNull()
continue
}
res, e := types.ProduceStrWithSpecifiedTp(buf.GetDuration(i, 0).String(), b.tp, sc, false)
if e != nil {
return e
}
str, b, e1 := padZeroForBinaryType(res, b.tp, b.ctx)
qw4990 marked this conversation as resolved.
Show resolved Hide resolved
if e1 != nil {
return e1
}
if b {
result.AppendNull()
continue
}
result.AppendString(str)
}
return nil
}

func (b *builtinCastDecimalAsRealSig) 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.ETDuration}},
},
}

Expand Down