github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/col/coldata/datum_vec.go (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package coldata
    12  
    13  // Datum is abstract type for elements inside DatumVec, this type in reality
    14  // should be tree.Datum. However, in order to avoid pulling in 'tree' package
    15  // into the 'coldata' package, we use a runtime cast instead.
    16  type Datum interface{}
    17  
    18  // DatumVec is the interface for a specialized vector that operates on
    19  // tree.Datums in the vectorized engine. In order to avoid import of 'tree'
    20  // package the implementation of DatumVec lives in 'coldataext' package.
    21  type DatumVec interface {
    22  	// Get returns the datum at index i in the vector. The datum cannot be used
    23  	// anymore once the vector is modified.
    24  	Get(i int) Datum
    25  	// Set sets the datum at index i in the vector. It must check whether the
    26  	// provided datum is compatible with the type that the DatumVec stores.
    27  	Set(i int, v Datum)
    28  	// Window creates a "window" into the vector. It behaves similarly to
    29  	// Golang's slice.
    30  	Window(start, end int) DatumVec
    31  	// CopySlice copies srcStartIdx inclusive and srcEndIdx exclusive
    32  	// tree.Datum values from src into the vector starting at destIdx.
    33  	CopySlice(src DatumVec, destIdx, srcStartIdx, srcEndIdx int)
    34  	// AppendSlice appends srcStartIdx inclusive and srcEndIdx exclusive
    35  	// tree.Datum values from src into the vector starting at destIdx.
    36  	AppendSlice(src DatumVec, destIdx, srcStartIdx, srcEndIdx int)
    37  	// AppendVal appends the given tree.Datum value to the end of the vector.
    38  	AppendVal(v Datum)
    39  	// SetLength sets the length of the vector.
    40  	SetLength(l int)
    41  	// Len returns the length of the vector.
    42  	Len() int
    43  	// Cap returns the underlying capacity of the vector.
    44  	Cap() int
    45  	// MarshalAt returns the marshaled representation of datum at index i.
    46  	MarshalAt(appendTo []byte, i int) ([]byte, error)
    47  	// UnmarshalTo unmarshals the byte representation of a datum and sets it at
    48  	// index i.
    49  	UnmarshalTo(i int, b []byte) error
    50  	// Size returns the total memory footprint of the vector (including the
    51  	// internal memory used by tree.Datums) in bytes. It only accounts for the
    52  	// size of the datum objects starting from the given index. So, Size is
    53  	// relatively cheap when startIdx >= length, and expensive when
    54  	// startIdx < length (with a maximum at zero). A nonzero startIdx should only
    55  	// be used when elements before startIdx are guaranteed not to have been
    56  	// modified.
    57  	Size(startIdx int) int64
    58  	// SetEvalCtx updates the vector with the provided *eval.Context.
    59  	SetEvalCtx(evalCtx interface{})
    60  }