github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/dbs/memristed/memex/builtin_other_vec_generated_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  // Code generated by go generate in memex/generator; DO NOT EDIT.
    15  
    16  package memex
    17  
    18  import (
    19  	"fmt"
    20  	"math/rand"
    21  	"testing"
    22  	"time"
    23  
    24  	. "github.com/whtcorpsinc/check"
    25  	"github.com/whtcorpsinc/BerolinaSQL/ast"
    26  	"github.com/whtcorpsinc/BerolinaSQL/allegrosql"
    27  	"github.com/whtcorpsinc/milevadb/types"
    28  	"github.com/whtcorpsinc/milevadb/types/json"
    29  )
    30  
    31  type inGener struct {
    32  	defaultGener
    33  }
    34  
    35  func (g inGener) gen() interface{} {
    36  	if rand.Float64() < g.nullRation {
    37  		return nil
    38  	}
    39  	randNum := rand.Int63n(10)
    40  	switch g.eType {
    41  	case types.ETInt:
    42  		if rand.Float64() < 0.5 {
    43  			return -randNum
    44  		}
    45  		return randNum
    46  	case types.ETReal:
    47  		if rand.Float64() < 0.5 {
    48  			return -float64(randNum)
    49  		}
    50  		return float64(randNum)
    51  	case types.ETDecimal:
    52  		d := new(types.MyDecimal)
    53  		f := float64(randNum * 100000)
    54  		if err := d.FromFloat64(f); err != nil {
    55  			panic(err)
    56  		}
    57  		return d
    58  	case types.ETDatetime, types.ETTimestamp:
    59  		gt := types.FromDate(2020, 11, 2, 22, 00, int(randNum), rand.Intn(1000000))
    60  		t := types.NewTime(gt, convertETType(g.eType), 0)
    61  		return t
    62  	case types.ETDuration:
    63  		return types.Duration{Duration: time.Duration(randNum)}
    64  	case types.ETJson:
    65  		j := new(json.BinaryJSON)
    66  		jsonStr := fmt.Sprintf("{\"key\":%v}", randNum)
    67  		if err := j.UnmarshalJSON([]byte(jsonStr)); err != nil {
    68  			panic(err)
    69  		}
    70  		return *j
    71  	case types.ETString:
    72  		return fmt.Sprint(randNum)
    73  	}
    74  	return randNum
    75  }
    76  
    77  var vecBuiltinOtherGeneratedCases = map[string][]vecExprBenchCase{
    78  	ast.In: {
    79  		// builtinInIntSig
    80  		{
    81  			retEvalType: types.ETInt,
    82  			childrenTypes: []types.EvalType{
    83  				types.ETInt,
    84  				types.ETInt,
    85  				types.ETInt,
    86  				types.ETInt,
    87  			},
    88  			geners: []dataGenerator{
    89  				inGener{*newDefaultGener(0.2, types.ETInt)},
    90  				inGener{*newDefaultGener(0.2, types.ETInt)},
    91  				inGener{*newDefaultGener(0.2, types.ETInt)},
    92  				inGener{*newDefaultGener(0.2, types.ETInt)},
    93  			},
    94  		},
    95  		// builtinInStringSig
    96  		{
    97  			retEvalType: types.ETInt,
    98  			childrenTypes: []types.EvalType{
    99  				types.ETString,
   100  				types.ETString,
   101  				types.ETString,
   102  				types.ETString,
   103  			},
   104  			geners: []dataGenerator{
   105  				inGener{*newDefaultGener(0.2, types.ETString)},
   106  				inGener{*newDefaultGener(0.2, types.ETString)},
   107  				inGener{*newDefaultGener(0.2, types.ETString)},
   108  				inGener{*newDefaultGener(0.2, types.ETString)},
   109  			},
   110  		},
   111  		// builtinInDecimalSig
   112  		{
   113  			retEvalType: types.ETInt,
   114  			childrenTypes: []types.EvalType{
   115  				types.ETDecimal,
   116  				types.ETDecimal,
   117  				types.ETDecimal,
   118  				types.ETDecimal,
   119  			},
   120  			geners: []dataGenerator{
   121  				inGener{*newDefaultGener(0.2, types.ETDecimal)},
   122  				inGener{*newDefaultGener(0.2, types.ETDecimal)},
   123  				inGener{*newDefaultGener(0.2, types.ETDecimal)},
   124  				inGener{*newDefaultGener(0.2, types.ETDecimal)},
   125  			},
   126  		},
   127  		// builtinInRealSig
   128  		{
   129  			retEvalType: types.ETInt,
   130  			childrenTypes: []types.EvalType{
   131  				types.ETReal,
   132  				types.ETReal,
   133  				types.ETReal,
   134  				types.ETReal,
   135  			},
   136  			geners: []dataGenerator{
   137  				inGener{*newDefaultGener(0.2, types.ETReal)},
   138  				inGener{*newDefaultGener(0.2, types.ETReal)},
   139  				inGener{*newDefaultGener(0.2, types.ETReal)},
   140  				inGener{*newDefaultGener(0.2, types.ETReal)},
   141  			},
   142  		},
   143  		// builtinInTimeSig
   144  		{
   145  			retEvalType: types.ETInt,
   146  			childrenTypes: []types.EvalType{
   147  				types.ETDatetime,
   148  				types.ETDatetime,
   149  				types.ETDatetime,
   150  				types.ETDatetime,
   151  			},
   152  			geners: []dataGenerator{
   153  				inGener{*newDefaultGener(0.2, types.ETDatetime)},
   154  				inGener{*newDefaultGener(0.2, types.ETDatetime)},
   155  				inGener{*newDefaultGener(0.2, types.ETDatetime)},
   156  				inGener{*newDefaultGener(0.2, types.ETDatetime)},
   157  			},
   158  		},
   159  		// builtinInDurationSig
   160  		{
   161  			retEvalType: types.ETInt,
   162  			childrenTypes: []types.EvalType{
   163  				types.ETDuration,
   164  				types.ETDuration,
   165  				types.ETDuration,
   166  				types.ETDuration,
   167  			},
   168  			geners: []dataGenerator{
   169  				inGener{*newDefaultGener(0.2, types.ETDuration)},
   170  				inGener{*newDefaultGener(0.2, types.ETDuration)},
   171  				inGener{*newDefaultGener(0.2, types.ETDuration)},
   172  				inGener{*newDefaultGener(0.2, types.ETDuration)},
   173  			},
   174  		},
   175  		// builtinInJSONSig
   176  		{
   177  			retEvalType: types.ETInt,
   178  			childrenTypes: []types.EvalType{
   179  				types.ETJson,
   180  				types.ETJson,
   181  				types.ETJson,
   182  				types.ETJson,
   183  			},
   184  			geners: []dataGenerator{
   185  				inGener{*newDefaultGener(0.2, types.ETJson)},
   186  				inGener{*newDefaultGener(0.2, types.ETJson)},
   187  				inGener{*newDefaultGener(0.2, types.ETJson)},
   188  				inGener{*newDefaultGener(0.2, types.ETJson)},
   189  			},
   190  		},
   191  		// builtinInIntSig with const arguments
   192  		{
   193  			retEvalType: types.ETInt,
   194  			childrenTypes: []types.EvalType{
   195  				types.ETInt,
   196  				types.ETInt, types.ETInt,
   197  			},
   198  			constants: []*Constant{
   199  				nil,
   200  				{Value: types.NewCauset(1), RetType: types.NewFieldType(allegrosql.TypeInt24)},
   201  				{Value: types.NewCauset(2), RetType: types.NewFieldType(allegrosql.TypeInt24)},
   202  			},
   203  		},
   204  		// builtinInStringSig with const arguments
   205  		{
   206  			retEvalType: types.ETInt,
   207  			childrenTypes: []types.EvalType{
   208  				types.ETString,
   209  				types.ETString, types.ETString,
   210  			},
   211  			constants: []*Constant{
   212  				nil,
   213  				{Value: types.NewStringCauset("aaaa"), RetType: types.NewFieldType(allegrosql.TypeString)},
   214  				{Value: types.NewStringCauset("bbbb"), RetType: types.NewFieldType(allegrosql.TypeString)},
   215  			},
   216  		},
   217  		// builtinInDecimalSig with const arguments
   218  		{
   219  			retEvalType: types.ETInt,
   220  			childrenTypes: []types.EvalType{
   221  				types.ETDecimal,
   222  				types.ETDecimal, types.ETDecimal,
   223  			},
   224  			constants: []*Constant{
   225  				nil,
   226  				{Value: types.NewDecimalCauset(types.NewDecFromInt(10)), RetType: types.NewFieldType(allegrosql.TypeNewDecimal)},
   227  				{Value: types.NewDecimalCauset(types.NewDecFromInt(20)), RetType: types.NewFieldType(allegrosql.TypeNewDecimal)},
   228  			},
   229  		},
   230  		// builtinInRealSig with const arguments
   231  		{
   232  			retEvalType: types.ETInt,
   233  			childrenTypes: []types.EvalType{
   234  				types.ETReal,
   235  				types.ETReal, types.ETReal,
   236  			},
   237  			constants: []*Constant{
   238  				nil,
   239  				{Value: types.NewFloat64Causet(0.1), RetType: types.NewFieldType(allegrosql.TypeFloat)},
   240  				{Value: types.NewFloat64Causet(0.2), RetType: types.NewFieldType(allegrosql.TypeFloat)},
   241  			},
   242  		},
   243  		// builtinInTimeSig with const arguments
   244  		{
   245  			retEvalType: types.ETInt,
   246  			childrenTypes: []types.EvalType{
   247  				types.ETDatetime,
   248  				types.ETDatetime, types.ETDatetime,
   249  			},
   250  			constants: []*Constant{
   251  				nil,
   252  				{Value: types.NewTimeCauset(dateTimeFromString("2020-01-01")), RetType: types.NewFieldType(allegrosql.TypeDatetime)},
   253  				{Value: types.NewTimeCauset(dateTimeFromString("2020-01-01")), RetType: types.NewFieldType(allegrosql.TypeDatetime)},
   254  			},
   255  		},
   256  		// builtinInDurationSig with const arguments
   257  		{
   258  			retEvalType: types.ETInt,
   259  			childrenTypes: []types.EvalType{
   260  				types.ETDuration,
   261  				types.ETDuration, types.ETDuration,
   262  			},
   263  			constants: []*Constant{
   264  				nil,
   265  				{Value: types.NewDurationCauset(types.Duration{Duration: time.Duration(1000)}), RetType: types.NewFieldType(allegrosql.TypeDuration)},
   266  				{Value: types.NewDurationCauset(types.Duration{Duration: time.Duration(2000)}), RetType: types.NewFieldType(allegrosql.TypeDuration)},
   267  			},
   268  		},
   269  		// builtinInJSONSig with const arguments
   270  		{
   271  			retEvalType: types.ETInt,
   272  			childrenTypes: []types.EvalType{
   273  				types.ETJson,
   274  				types.ETJson, types.ETJson,
   275  			},
   276  			constants: []*Constant{
   277  				nil,
   278  				{Value: types.NewJSONCauset(json.CreateBinary("aaaa")), RetType: types.NewFieldType(allegrosql.TypeJSON)},
   279  				{Value: types.NewJSONCauset(json.CreateBinary("bbbb")), RetType: types.NewFieldType(allegrosql.TypeJSON)},
   280  			},
   281  		},
   282  	},
   283  }
   284  
   285  func (s *testEvaluatorSuite) TestVectorizedBuiltinOtherEvalOneVecGenerated(c *C) {
   286  	testVectorizedEvalOneVec(c, vecBuiltinOtherGeneratedCases)
   287  }
   288  
   289  func (s *testEvaluatorSuite) TestVectorizedBuiltinOtherFuncGenerated(c *C) {
   290  	testVectorizedBuiltinFunc(c, vecBuiltinOtherGeneratedCases)
   291  }
   292  
   293  func BenchmarkVectorizedBuiltinOtherEvalOneVecGenerated(b *testing.B) {
   294  	benchmarkVectorizedEvalOneVec(b, vecBuiltinOtherGeneratedCases)
   295  }
   296  
   297  func BenchmarkVectorizedBuiltinOtherFuncGenerated(b *testing.B) {
   298  	benchmarkVectorizedBuiltinFunc(b, vecBuiltinOtherGeneratedCases)
   299  }