expression: implement vectorized evaluation for 'builtinCastRealAsStringSig' (#12533)
This commit is contained in:
committed by
pingcap-github-bot
parent
af373988d8
commit
0127047db5
@ -156,11 +156,53 @@ func (b *builtinCastTimeAsJSONSig) vecEvalJSON(input *chunk.Chunk, result *chunk
|
||||
}
|
||||
|
||||
func (b *builtinCastRealAsStringSig) vectorized() bool {
|
||||
return false
|
||||
return true
|
||||
}
|
||||
|
||||
func (b *builtinCastRealAsStringSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
|
||||
return errors.Errorf("not implemented")
|
||||
n := input.NumRows()
|
||||
buf, err := b.bufAllocator.get(types.ETReal, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer b.bufAllocator.put(buf)
|
||||
if err := b.args[0].VecEvalReal(b.ctx, input, buf); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bits := 64
|
||||
if b.args[0].GetType().Tp == mysql.TypeFloat {
|
||||
// b.args[0].EvalReal() casts the value from float32 to float64, for example:
|
||||
// float32(208.867) is cast to float64(208.86700439)
|
||||
// If we strconv.FormatFloat the value with 64bits, the result is incorrect!
|
||||
bits = 32
|
||||
}
|
||||
|
||||
var isNull bool
|
||||
var res string
|
||||
f64s := buf.Float64s()
|
||||
result.ReserveString(n)
|
||||
sc := b.ctx.GetSessionVars().StmtCtx
|
||||
for i, v := range f64s {
|
||||
if buf.IsNull(i) {
|
||||
result.AppendNull()
|
||||
continue
|
||||
}
|
||||
res, err = types.ProduceStrWithSpecifiedTp(strconv.FormatFloat(v, 'f', -1, bits), 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 *builtinCastDecimalAsStringSig) vectorized() bool {
|
||||
|
||||
@ -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.ETReal}},
|
||||
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETJson}},
|
||||
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDecimal}},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user