68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
package expression
|
|
|
|
import (
|
|
"math"
|
|
"strings"
|
|
|
|
"github.com/pingcap/tidb/types"
|
|
"github.com/pingcap/tidb/util/chunk"
|
|
)
|
|
|
|
func (b *builtinRepeatSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
|
|
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
|
|
}
|
|
|
|
buf2, err := b.bufAllocator.get(types.ETInt, n)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer b.bufAllocator.put(buf2)
|
|
if err := b.args[1].VecEvalInt(b.ctx, input, buf2); err != nil {
|
|
return err
|
|
}
|
|
|
|
result.ReserveString(n)
|
|
nums := buf2.Int64s()
|
|
for i := 0; i < n; i++ {
|
|
// TODO: introduce vectorized null-bitmap to speed it up.
|
|
if buf.IsNull(i) || buf2.IsNull(i) {
|
|
result.AppendNull()
|
|
continue
|
|
}
|
|
num := nums[i]
|
|
if num < 1 {
|
|
result.AppendString("")
|
|
continue
|
|
}
|
|
if num > math.MaxInt32 {
|
|
// to avoid overflow when calculating uint64(byteLength)*uint64(num) later
|
|
num = math.MaxInt32
|
|
}
|
|
|
|
str := buf.GetString(i)
|
|
byteLength := len(str)
|
|
if uint64(byteLength)*uint64(num) > b.maxAllowedPacket {
|
|
b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenWithStackByArgs("repeat", b.maxAllowedPacket))
|
|
result.AppendNull()
|
|
continue
|
|
}
|
|
if int64(byteLength) > int64(b.tp.Flen)/num {
|
|
result.AppendNull()
|
|
continue
|
|
}
|
|
result.AppendString(strings.Repeat(str, int(num)))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (b *builtinRepeatSig) vectorized() bool {
|
|
return true
|
|
}
|