github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/model/colview.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 ColumnView struct {
    25  	*BaseView
    26  	ColIdx     int
    27  	data       containers.Vector
    28  	UpdateMask *roaring.Bitmap
    29  	UpdateVals map[uint32]any
    30  	LogIndexes []*wal.Index
    31  }
    32  
    33  func NewColumnView(ts types.TS, colIdx int) *ColumnView {
    34  	return &ColumnView{
    35  		BaseView: &BaseView{
    36  			Ts: ts,
    37  		},
    38  		ColIdx: colIdx,
    39  	}
    40  }
    41  
    42  func (view *ColumnView) Orphan() containers.Vector {
    43  	data := view.data
    44  	view.data = nil
    45  	return data
    46  }
    47  
    48  func (view *ColumnView) SetData(data containers.Vector) {
    49  	view.data = data
    50  }
    51  
    52  func (view *ColumnView) ApplyDeletes() containers.Vector {
    53  	if view.DeleteMask == nil {
    54  		return view.data
    55  	}
    56  	view.data.Compact(view.DeleteMask)
    57  	view.DeleteMask = nil
    58  	return view.data
    59  }
    60  
    61  func (view *ColumnView) Eval(clear bool) (err error) {
    62  	if view.UpdateMask == nil {
    63  		return
    64  	}
    65  	it := view.UpdateMask.Iterator()
    66  	for it.HasNext() {
    67  		row := it.Next()
    68  		view.data.Update(int(row), view.UpdateVals[row])
    69  	}
    70  	if clear {
    71  		view.UpdateMask = nil
    72  		view.UpdateVals = nil
    73  	}
    74  	return
    75  }
    76  
    77  func (view *ColumnView) GetData() containers.Vector {
    78  	return view.data
    79  }
    80  
    81  func (view *ColumnView) Length() int {
    82  	return view.data.Length()
    83  }
    84  
    85  func (view *ColumnView) String() string {
    86  	if view.data != nil {
    87  		return view.data.String()
    88  	}
    89  	return "empty"
    90  }
    91  
    92  func (view *ColumnView) GetValue(row int) any {
    93  	return view.data.Get(row)
    94  }
    95  
    96  func (view *ColumnView) IsDeleted(row int) bool {
    97  	if view.DeleteMask == nil {
    98  		return false
    99  	}
   100  	return view.DeleteMask.ContainsInt(row)
   101  }
   102  
   103  func (view *ColumnView) Close() {
   104  	if view.data != nil {
   105  		view.data.Close()
   106  	}
   107  	view.data = nil
   108  	view.UpdateMask = nil
   109  	view.UpdateVals = nil
   110  	view.DeleteMask = nil
   111  }