github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/model/blkview.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 model
    16  
    17  import (
    18  	"github.com/RoaringBitmap/roaring"
    19  	"github.com/matrixorigin/matrixone/pkg/container/types"
    20  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers"
    21  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/wal"
    22  )
    23  
    24  type BaseView struct {
    25  	Ts         types.TS
    26  	DeleteMask *roaring.Bitmap
    27  }
    28  
    29  type BlockView struct {
    30  	*BaseView
    31  	Columns          map[int]*ColumnView
    32  	DeleteLogIndexes []*wal.Index
    33  }
    34  
    35  func NewBlockView(ts types.TS) *BlockView {
    36  	return &BlockView{
    37  		BaseView: &BaseView{
    38  			Ts: ts,
    39  		},
    40  		Columns: make(map[int]*ColumnView),
    41  	}
    42  }
    43  
    44  func (view *BlockView) Orphan(i int) containers.Vector {
    45  	col := view.Columns[i]
    46  	return col.Orphan()
    47  }
    48  
    49  func (view *BlockView) SetBatch(bat *containers.Batch) {
    50  	for i, col := range bat.Vecs {
    51  		view.SetData(i, col)
    52  	}
    53  }
    54  
    55  func (view *BlockView) GetColumnData(i int) containers.Vector {
    56  	return view.Columns[i].GetData()
    57  }
    58  
    59  func (view *BlockView) SetData(i int, data containers.Vector) {
    60  	col := view.Columns[i]
    61  	if col == nil {
    62  		col = NewColumnView(view.Ts, i)
    63  		view.Columns[i] = col
    64  	}
    65  	col.SetData(data)
    66  }
    67  
    68  func (view *BlockView) SetUpdates(i int, mask *roaring.Bitmap, vals map[uint32]any) {
    69  	col := view.Columns[i]
    70  	if col == nil {
    71  		col = NewColumnView(view.Ts, i)
    72  		view.Columns[i] = col
    73  	}
    74  	col.UpdateMask = mask
    75  	col.UpdateVals = vals
    76  }
    77  
    78  func (view *BlockView) SetLogIndexes(i int, indexes []*wal.Index) {
    79  	col := view.Columns[i]
    80  	if col == nil {
    81  		col = NewColumnView(view.Ts, i)
    82  		view.Columns[i] = col
    83  	}
    84  	col.LogIndexes = indexes
    85  }
    86  
    87  func (view *BlockView) Eval(clear bool) (err error) {
    88  	for _, col := range view.Columns {
    89  		if err = col.Eval(clear); err != nil {
    90  			break
    91  		}
    92  	}
    93  	return
    94  }
    95  
    96  func (view *BlockView) ApplyDeletes() {
    97  	if view.DeleteMask == nil {
    98  		return
    99  	}
   100  	for _, col := range view.Columns {
   101  		col.data.Compact(view.DeleteMask)
   102  	}
   103  	view.DeleteMask = nil
   104  }
   105  
   106  func (view *BlockView) Close() {
   107  	for _, col := range view.Columns {
   108  		col.Close()
   109  	}
   110  	view.DeleteMask = nil
   111  }