github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/dbs/memristed/memex/builtin_other_vec_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package memex 15 16 import ( 17 "fmt" 18 "math/rand" 19 "testing" 20 21 . "github.com/whtcorpsinc/check" 22 "github.com/whtcorpsinc/BerolinaSQL/ast" 23 "github.com/whtcorpsinc/milevadb/types" 24 "github.com/whtcorpsinc/milevadb/soliton/chunk" 25 "github.com/whtcorpsinc/milevadb/soliton/mock" 26 ) 27 28 func dateTimeFromString(s string) types.Time { 29 t, err := types.ParseDate(nil, s) 30 if err != nil { 31 panic(err) 32 } 33 return t 34 } 35 36 var vecBuiltinOtherCases = map[string][]vecExprBenchCase{ 37 ast.SetVar: { 38 {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString}}, 39 }, 40 ast.GetVar: { 41 {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}}, 42 }, 43 ast.In: {}, 44 ast.BitCount: {{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}}}, 45 ast.GetParam: { 46 { 47 retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETInt}, 48 geners: []dataGenerator{newRangeInt64Gener(0, 10)}, 49 }, 50 }, 51 } 52 53 func (s *testEvaluatorSuite) TestVectorizedBuiltinOtherFunc(c *C) { 54 testVectorizedBuiltinFunc(c, vecBuiltinOtherCases) 55 } 56 57 func BenchmarkVectorizedBuiltinOtherFunc(b *testing.B) { 58 benchmarkVectorizedBuiltinFunc(b, vecBuiltinOtherCases) 59 } 60 61 func (s *testEvaluatorSuite) TestInDecimal(c *C) { 62 ctx := mock.NewContext() 63 ft := eType2FieldType(types.ETDecimal) 64 defCaus0 := &DeferredCauset{RetType: ft, Index: 0} 65 defCaus1 := &DeferredCauset{RetType: ft, Index: 1} 66 inFunc, err := funcs[ast.In].getFunction(ctx, []Expression{defCaus0, defCaus1}) 67 c.Assert(err, IsNil) 68 69 input := chunk.NewChunkWithCapacity([]*types.FieldType{ft, ft}, 1024) 70 for i := 0; i < 1024; i++ { 71 d0 := new(types.MyDecimal) 72 d1 := new(types.MyDecimal) 73 v := fmt.Sprintf("%d.%d", rand.Intn(1000), rand.Int31()) 74 c.Assert(d0.FromString([]byte(v)), IsNil) 75 v += "00" 76 c.Assert(d1.FromString([]byte(v)), IsNil) 77 input.DeferredCauset(0).AppendMyDecimal(d0) 78 input.DeferredCauset(1).AppendMyDecimal(d1) 79 c.Assert(input.DeferredCauset(0).GetDecimal(i).GetDigitsFrac(), Not(Equals), input.DeferredCauset(1).GetDecimal(i).GetDigitsFrac()) 80 } 81 result := chunk.NewDeferredCauset(ft, 1024) 82 c.Assert(inFunc.vecEvalInt(input, result), IsNil) 83 for i := 0; i < 1024; i++ { 84 c.Assert(result.GetInt64(0), Equals, int64(1)) 85 } 86 }