github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/iface/handle/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 handle
    16  
    17  import (
    18  	"bytes"
    19  	"io"
    20  
    21  	"github.com/RoaringBitmap/roaring"
    22  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common"
    23  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers"
    24  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/model"
    25  )
    26  
    27  type BlockIt interface {
    28  	Iterator
    29  	GetBlock() Block
    30  }
    31  
    32  type FilterOp int16
    33  
    34  type MetaUpdateNode interface{}
    35  
    36  const (
    37  	FilterEq FilterOp = iota
    38  	FilterBatchEq
    39  	FilterBtw
    40  )
    41  
    42  type Filter struct {
    43  	Op  FilterOp
    44  	Val any
    45  }
    46  
    47  func NewEQFilter(v any) *Filter {
    48  	return &Filter{
    49  		Op:  FilterEq,
    50  		Val: v,
    51  	}
    52  }
    53  
    54  type BlockReader interface {
    55  	io.Closer
    56  	ID() uint64
    57  	String() string
    58  	IsUncommitted() bool
    59  	GetByFilter(filter *Filter) (uint32, error)
    60  	GetColumnDataByNames(attrs []string, buffers []*bytes.Buffer) (*model.BlockView, error)
    61  	GetColumnDataByIds(colIdxes []int, buffers []*bytes.Buffer) (*model.BlockView, error)
    62  	GetColumnDataByName(string, *bytes.Buffer) (*model.ColumnView, error)
    63  	GetColumnDataById(int, *bytes.Buffer) (*model.ColumnView, error)
    64  	GetMeta() any
    65  	GetMetaLoc() string
    66  	GetDeltaLoc() string
    67  	Fingerprint() *common.ID
    68  	Rows() int
    69  
    70  	// Why need rowmask?
    71  	// We don't update the index until committing the transaction. Before that, even if we deleted a row
    72  	// from a block, the index would not change. If then we insert a row with the same primary key as the
    73  	// previously deleted row, there will be an deduplication error (unexpected!).
    74  	// Here we use the rowmask to ingore any deduplication error on those deleted rows.
    75  	BatchDedup(col containers.Vector, invisibility *roaring.Bitmap) error
    76  
    77  	IsAppendableBlock() bool
    78  
    79  	GetSegment() Segment
    80  
    81  	GetTotalChanges() int
    82  }
    83  
    84  type BlockWriter interface {
    85  	io.Closer
    86  	Append(data *containers.Batch, offset uint32) (uint32, error)
    87  	Update(row uint32, col uint16, v any) error
    88  	RangeDelete(start, end uint32, dt DeleteType) error
    89  	UpdateMetaLoc(metaLoc string) error
    90  	UpdateDeltaLoc(deltaLoc string) error
    91  
    92  	PushDeleteOp(filter Filter) error
    93  	PushUpdateOp(filter Filter, attr string, val any) error
    94  }
    95  
    96  type Block interface {
    97  	BlockReader
    98  	BlockWriter
    99  }
   100  
   101  type DeleteType int8
   102  
   103  const (
   104  	DT_Normal DeleteType = iota
   105  	DT_MergeCompact
   106  )