-
Notifications
You must be signed in to change notification settings - Fork 524
/
Copy pathbuiltin_op_vec_test.go
118 lines (106 loc) · 3.31 KB
/
builtin_op_vec_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package expression
import (
"math"
"testing"
. "github.com/pingcap/check"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/types"
)
var vecBuiltinOpCases = map[string][]vecExprBenchCase{
ast.LogicOr: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: makeBinaryLogicOpDataGeners()},
},
ast.LogicAnd: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: makeBinaryLogicOpDataGeners()},
},
ast.UnaryNot: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETReal}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}},
},
ast.UnaryMinus: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}},
{
retEvalType: types.ETInt,
childrenTypes: []types.EvalType{types.ETInt},
childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag}},
geners: []dataGenerator{&rangeInt64Gener{0, math.MaxInt64}},
},
},
ast.IsNull: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETReal}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}},
},
}
// givenValsGener returns the items sequentially from the slice given at
// the construction time. If this slice is exhausted, it falls back to
// the fallback generator.
type givenValsGener struct {
given []interface{}
idx int
fallback dataGenerator
}
func (g *givenValsGener) gen() interface{} {
if g.idx >= len(g.given) {
return g.fallback.gen()
}
v := g.given[g.idx]
g.idx++
return v
}
func makeGivenValsOrDefaultGener(vals []interface{}, eType types.EvalType) *givenValsGener {
g := &givenValsGener{}
g.given = vals
g.fallback = &defaultGener{0.2, eType}
return g
}
func makeBinaryLogicOpDataGeners() []dataGenerator {
// TODO: rename this to makeBinaryOpDataGenerator, since the BIT ops are also using it?
pairs := [][]interface{}{
{nil, nil},
{0, nil},
{nil, 0},
{1, nil},
{nil, 1},
{0, 0},
{0, 1},
{1, 0},
{1, 1},
{-1, 1},
}
maybeToInt64 := func(v interface{}) interface{} {
if v == nil {
return nil
}
return int64(v.(int))
}
n := len(pairs)
arg0s := make([]interface{}, n)
arg1s := make([]interface{}, n)
for i, p := range pairs {
arg0s[i] = maybeToInt64(p[0])
arg1s[i] = maybeToInt64(p[1])
}
return []dataGenerator{
makeGivenValsOrDefaultGener(arg0s, types.ETInt),
makeGivenValsOrDefaultGener(arg1s, types.ETInt)}
}
func (s *testEvaluatorSuite) TestVectorizedBuiltinOpFunc(c *C) {
testVectorizedBuiltinFunc(c, vecBuiltinOpCases)
}
func BenchmarkVectorizedBuiltinOpFunc(b *testing.B) {
benchmarkVectorizedBuiltinFunc(b, vecBuiltinOpCases)
}