github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/moengine/block.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 moengine 16 17 import ( 18 "bytes" 19 20 "github.com/matrixorigin/matrixone/pkg/container/batch" 21 "github.com/matrixorigin/matrixone/pkg/container/vector" 22 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/catalog" 23 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers" 24 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/handle" 25 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/model" 26 ) 27 28 func newBlock(h handle.Block) *txnBlock { 29 return &txnBlock{ 30 handle: h, 31 } 32 } 33 34 func (blk *txnBlock) Read(attrs []string, compressed []*bytes.Buffer, deCompressed []*bytes.Buffer) (*batch.Batch, error) { 35 var view *model.BlockView 36 var err error 37 bat := batch.New(true, attrs) 38 bat.Vecs = make([]*vector.Vector, len(attrs)) 39 view, err = blk.handle.GetColumnDataByNames(attrs, deCompressed) 40 if err != nil { 41 return nil, err 42 } 43 view.ApplyDeletes() 44 nameIdx := blk.handle.GetMeta().(*catalog.BlockEntry).GetSchema().NameIndex 45 for i, attr := range attrs { 46 colIdx := nameIdx[attr] 47 vec := view.GetColumnData(colIdx) 48 if vec.Allocated() > 0 { 49 bat.Vecs[i] = containers.CopyToMoVec(vec) 50 } else { 51 bat.Vecs[i] = containers.UnmarshalToMoVec(vec) 52 } 53 } 54 view.Close() 55 return bat, nil 56 }