github.com/matrixorigin/matrixone@v0.7.0/pkg/testutil/types.go (about) 1 // Copyright 2021 Matrix Origin 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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package testutil 16 17 import ( 18 "math/rand" 19 20 "github.com/matrixorigin/matrixone/pkg/container/types" 21 ) 22 23 var ( 24 boolType = types.T_bool.ToType() 25 int8Type = types.T_int8.ToType() 26 int16Type = types.T_int16.ToType() 27 int32Type = types.T_int32.ToType() 28 int64Type = types.T_int64.ToType() 29 uint8Type = types.T_uint8.ToType() 30 uint16Type = types.T_uint16.ToType() 31 uint32Type = types.T_uint32.ToType() 32 uint64Type = types.T_uint64.ToType() 33 float32Type = types.T_float32.ToType() 34 float64Type = types.T_float64.ToType() 35 charType = types.T_char.ToType() 36 varcharType = types.T_varchar.ToType() 37 decimal64Type = types.T_decimal64.ToType() 38 decimal128Type = types.T_decimal128.ToType() 39 dateType = types.T_date.ToType() 40 timeType = types.T_time.ToType() 41 datetimeType = types.T_datetime.ToType() 42 timestampType = types.T_timestamp.ToType() 43 blobType = types.T_blob.ToType() 44 textType = types.T_text.ToType() 45 uuidType = types.T_uuid.ToType() 46 ) 47 48 func MakeDecimal64Type(precision, scalar int32) types.Type { 49 d64 := types.T_decimal64.ToType() 50 d64.Scale = scalar 51 d64.Width = precision 52 return d64 53 } 54 55 func MakeDecimal128Type(precision, scalar int32) types.Type { 56 d128 := types.T_decimal128.ToType() 57 d128.Scale = scalar 58 d128.Width = precision 59 return d128 60 } 61 62 func MakeBatchZs(n int, random bool) []int64 { 63 zs := make([]int64, n) 64 if random { 65 for i := 0; i < n; i++ { 66 v := rand.Intn(5) 67 zs[i] = int64(v) + 1 68 } 69 } else { 70 for i := 0; i < n; i++ { 71 zs[i] = 1 72 } 73 } 74 return zs 75 }