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 'builtinRandWithSeedSig' #12644

Merged
merged 14 commits into from
Nov 6, 2019
Merged
28 changes: 26 additions & 2 deletions expression/builtin_math_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package expression
import (
"fmt"
"math"
"math/rand"
"strconv"
"time"

"github.com/cznic/mathutil"
"github.com/pingcap/errors"
Expand Down Expand Up @@ -687,11 +689,33 @@ func (b *builtinRandSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) e
}

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

func (b *builtinRandWithSeedSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETInt, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalInt(b.ctx, input, buf); err != nil {
qw4990 marked this conversation as resolved.
Show resolved Hide resolved
return err
}

result.ResizeFloat64(n, false)
var randGen *rand.Rand
i64s := buf.Int64s()
f64s := result.Float64s()
for i := 0; i < n; i++ {
if buf.IsNull(i) {
randGen = rand.New(rand.NewSource(time.Now().UnixNano()))
qw4990 marked this conversation as resolved.
Show resolved Hide resolved
} else {
randGen = rand.New(rand.NewSource(i64s[i]))
qw4990 marked this conversation as resolved.
Show resolved Hide resolved
}
f64s[i] = randGen.Float64()
}
return nil
}

func (b *builtinCeilIntToDecSig) vectorized() bool {
Expand Down