github.com/matrixorigin/matrixone@v1.2.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/common/mpool" 19 "github.com/matrixorigin/matrixone/pkg/container/types" 20 ) 21 22 func MakeVector(typ types.Type, mp *mpool.MPool) (vec Vector) { 23 return NewVector(typ, Options{Allocator: mp}) 24 } 25 26 func BuildBatchWithPool( 27 attrs []string, colTypes []types.Type, capacity int, pool *VectorPool, 28 ) *Batch { 29 bat := &Batch{ 30 Attrs: make([]string, 0, len(attrs)), 31 Nameidx: make(map[string]int, len(attrs)), 32 Vecs: make([]Vector, 0, len(attrs)), 33 Pool: pool, 34 } 35 for i, attr := range attrs { 36 vec := pool.GetVector(&colTypes[i]) 37 if capacity > 0 { 38 vec.PreExtend(capacity) 39 } 40 bat.AddVector(attr, vec) 41 } 42 return bat 43 } 44 45 func BuildBatch(attrs []string, colTypes []types.Type, opts Options) *Batch { 46 bat := &Batch{ 47 Attrs: make([]string, 0, len(attrs)), 48 Nameidx: make(map[string]int, len(attrs)), 49 Vecs: make([]Vector, 0, len(attrs)), 50 } 51 for i, attr := range attrs { 52 vec := NewVector(colTypes[i], opts) 53 bat.AddVector(attr, vec) 54 } 55 return bat 56 } 57 58 func NewEmptyBatch() *Batch { 59 return &Batch{ 60 Attrs: make([]string, 0), 61 Vecs: make([]Vector, 0), 62 Nameidx: make(map[string]int), 63 } 64 }