github.com/matrixorigin/matrixone@v1.2.0/pkg/container/batch/tools.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 batch 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/container/vector" 19 "github.com/matrixorigin/matrixone/pkg/pb/api" 20 ) 21 22 func BatchToProtoBatch(bat *Batch) (*api.Batch, error) { 23 rbat := new(api.Batch) 24 rbat.Attrs = bat.Attrs 25 for _, vec := range bat.Vecs { 26 pbVector, err := vector.VectorToProtoVector(vec) 27 if err != nil { 28 return nil, err 29 } 30 rbat.Vecs = append(rbat.Vecs, pbVector) 31 } 32 return rbat, nil 33 34 } 35 36 func ProtoBatchToBatch(bat *api.Batch) (*Batch, error) { 37 rbat := NewWithSize(len(bat.Vecs)) 38 rbat.Attrs = append(rbat.Attrs, bat.Attrs...) 39 for i, v := range bat.Vecs { 40 vec, err := vector.ProtoVectorToVector(v) 41 if err != nil { 42 return nil, err 43 } 44 rbat.SetVector(int32(i), vec) 45 } 46 rbat.SetRowCount(rbat.GetVector(0).Length()) 47 return rbat, nil 48 }