github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/containers/factory.go (about) 1 // Copyright 2022 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 containers 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/container/types" 19 ) 20 21 func MakeVector(typ types.Type, nullable bool, opts ...Options) (vec Vector) { 22 switch typ.Oid { 23 case types.T_any: 24 vec = NewVector[any](typ, nullable, opts...) 25 case types.T_bool: 26 vec = NewVector[bool](typ, nullable, opts...) 27 case types.T_int8: 28 vec = NewVector[int8](typ, nullable, opts...) 29 case types.T_int16: 30 vec = NewVector[int16](typ, nullable, opts...) 31 case types.T_int32: 32 vec = NewVector[int32](typ, nullable, opts...) 33 case types.T_int64: 34 vec = NewVector[int64](typ, nullable, opts...) 35 case types.T_uint8: 36 vec = NewVector[uint8](typ, nullable, opts...) 37 case types.T_uint16: 38 vec = NewVector[uint16](typ, nullable, opts...) 39 case types.T_uint32: 40 vec = NewVector[uint32](typ, nullable, opts...) 41 case types.T_uint64: 42 vec = NewVector[uint64](typ, nullable, opts...) 43 case types.T_decimal64: 44 vec = NewVector[types.Decimal64](typ, nullable, opts...) 45 case types.T_decimal128: 46 vec = NewVector[types.Decimal128](typ, nullable, opts...) 47 case types.T_uuid: 48 vec = NewVector[types.Uuid](typ, nullable, opts...) 49 case types.T_float32: 50 vec = NewVector[float32](typ, nullable, opts...) 51 case types.T_float64: 52 vec = NewVector[float64](typ, nullable, opts...) 53 case types.T_date: 54 vec = NewVector[types.Date](typ, nullable, opts...) 55 case types.T_timestamp: 56 vec = NewVector[types.Timestamp](typ, nullable, opts...) 57 case types.T_datetime: 58 vec = NewVector[types.Datetime](typ, nullable, opts...) 59 case types.T_time: 60 vec = NewVector[types.Time](typ, nullable, opts...) 61 case types.T_TS: 62 vec = NewVector[types.TS](typ, nullable, opts...) 63 case types.T_Rowid: 64 vec = NewVector[types.Rowid](typ, nullable, opts...) 65 case types.T_char, types.T_varchar, types.T_json, types.T_blob, types.T_text: 66 vec = NewVector[[]byte](typ, nullable, opts...) 67 default: 68 panic("not support") 69 } 70 return 71 } 72 73 func BuildBatch( 74 attrs []string, 75 colTypes []types.Type, 76 nullables []bool, 77 opts Options) *Batch { 78 bat := &Batch{ 79 Attrs: make([]string, 0, len(attrs)), 80 nameidx: make(map[string]int, len(attrs)), 81 Vecs: make([]Vector, 0, len(attrs)), 82 } 83 for i, attr := range attrs { 84 vec := MakeVector(colTypes[i], nullables[i], opts) 85 bat.AddVector(attr, vec) 86 } 87 return bat 88 } 89 90 func NewEmptyBatch() *Batch { 91 return &Batch{ 92 Attrs: make([]string, 0), 93 Vecs: make([]Vector, 0), 94 nameidx: make(map[string]int), 95 } 96 }