rowcodec

package
v1.1.0-beta.0...-68ac9ec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NilFlag           byte = 0
	BytesFlag         byte = 1
	CompactBytesFlag  byte = 2
	IntFlag           byte = 3
	UintFlag          byte = 4
	FloatFlag         byte = 5
	DecimalFlag       byte = 6
	VarintFlag        byte = 8
	VaruintFlag       byte = 9
	JSONFlag          byte = 10
	VectorFloat32Flag byte = 20
)

First byte in the encoded value which specifies the encoding type.

View Source
const CodecVer = 128

CodecVer is the constant number that represent the new row format.

Variables

This section is empty.

Functions

func FieldTypeFromModelColumn

func FieldTypeFromModelColumn(col *model.ColumnInfo) *types.FieldType

FieldTypeFromModelColumn creates a types.FieldType from model.ColumnInfo. export for test case and CDC.

func IsNewFormat

func IsNewFormat(rowData []byte) bool

IsNewFormat checks whether row data is in new-format.

func IsRowKey

func IsRowKey(key []byte) bool

IsRowKey determine whether key is row key. this method will be used in unistore.

func NewDecoder

func NewDecoder(columns []ColInfo, handleColIDs []int64, loc *time.Location) *decoder

NewDecoder creates a decoder.

func RemoveKeyspacePrefix

func RemoveKeyspacePrefix(key []byte) []byte

RemoveKeyspacePrefix is used to remove keyspace prefix from the key.

Types

type BytesDecoder

type BytesDecoder struct {
	// contains filtered or unexported fields
}

BytesDecoder decodes the row to old datums bytes.

func NewByteDecoder

func NewByteDecoder(columns []ColInfo, handleColIDs []int64, defBytes func(i int) ([]byte, error), loc *time.Location) *BytesDecoder

NewByteDecoder creates a BytesDecoder. defBytes: provided default value bytes in old datum format(flag+colData).

func (*BytesDecoder) DecodeToBytes

func (decoder *BytesDecoder) DecodeToBytes(outputOffset map[int64]int, handle kv.Handle, value []byte, cacheBytes []byte) ([][]byte, error)

DecodeToBytes decodes raw byte slice to row data.

func (*BytesDecoder) DecodeToBytesNoHandle

func (decoder *BytesDecoder) DecodeToBytesNoHandle(outputOffset map[int64]int, value []byte) ([][]byte, error)

DecodeToBytesNoHandle decodes raw byte slice to row data without handle.

type Checksum

type Checksum interface {
	// contains filtered or unexported methods
}

Checksum is used to calculate and append checksum data into the raw bytes

type ChunkDecoder

type ChunkDecoder struct {
	// contains filtered or unexported fields
}

ChunkDecoder decodes the row to chunk.Chunk.

func NewChunkDecoder

func NewChunkDecoder(columns []ColInfo, handleColIDs []int64, defDatum func(i int, chk *chunk.Chunk) error, loc *time.Location) *ChunkDecoder

NewChunkDecoder creates a NewChunkDecoder.

func (*ChunkDecoder) DecodeToChunk

func (decoder *ChunkDecoder) DecodeToChunk(rowData []byte, handle kv.Handle, chk *chunk.Chunk) error

DecodeToChunk decodes a row to chunk.

type ColData

type ColData struct {
	*model.ColumnInfo
	Datum *data.Datum
}

ColData combines the column info as well as its datum. It's used to calculate checksum.

func (ColData) Encode

func (c ColData) Encode(loc *time.Location, buf []byte) ([]byte, error)

Encode encodes the column datum into bytes for checksum. If buf provided, append encoded data to it.

type ColInfo

type ColInfo struct {
	ID            int64
	IsPKHandle    bool
	VirtualGenCol bool
	Ft            *types.FieldType
}

ColInfo is used as column meta info for row decoder.

type DatumMapDecoder

type DatumMapDecoder struct {
	// contains filtered or unexported fields
}

DatumMapDecoder decodes the row to datum map.

func NewDatumMapDecoder

func NewDatumMapDecoder(columns []ColInfo, loc *time.Location) *DatumMapDecoder

NewDatumMapDecoder creates a DatumMapDecoder.

func (*DatumMapDecoder) DecodeToDatumMap

func (decoder *DatumMapDecoder) DecodeToDatumMap(rowData []byte, row map[int64]types.Datum) (map[int64]types.Datum, error)

DecodeToDatumMap decodes byte slices to datum map.

type Encoder

type Encoder struct {

	// Enable indicates whether this encoder should be use.
	Enable bool
	// contains filtered or unexported fields
}

Encoder is used to encode a row.

func (*Encoder) CalculateRawChecksum

func (r *Encoder) CalculateRawChecksum(
	loc *time.Location, colIDs []int64, values []*types.Datum, key kv.Key, handle kv.Handle, buf []byte,
) (uint32, error)

CalculateRawChecksum calculates the bytes-level checksum by using the given elements. this is mainly used by the TiCDC to implement E2E checksum functionality.

func (*Encoder) ChecksumVersion

func (r *Encoder) ChecksumVersion() int

ChecksumVersion returns the version of checksum. Note that it's valid only if checksum has been encoded in the row value (callers can check it by `GetChecksum`).

func (*Encoder) ColumnIsNull

func (r *Encoder) ColumnIsNull(rowData []byte, colID int64, defaultVal []byte) (bool, error)

ColumnIsNull returns if the column value is null. Mainly used for count column aggregation. this method will used in unistore.

func (*Encoder) Encode

func (encoder *Encoder) Encode(loc *time.Location, colIDs []int64, values []types.Datum, checksum Checksum, buf []byte) ([]byte, error)

Encode encodes a row from a datums slice. `buf` is not truncated before encoding. This function may return both a valid encoded bytes and an error (actually `"pingcap/errors".ErrorGroup`). If the caller expects to handle these errors according to `SQL_MODE` or other configuration, please refer to `pkg/errctx`. the caller needs to ensure the key is not nil if checksum is required.

func (*Encoder) GetChecksum

func (r *Encoder) GetChecksum() (uint32, bool)

GetChecksum returns the checksum of row data (not null columns).

func (*Encoder) GetExtraChecksum

func (r *Encoder) GetExtraChecksum() (uint32, bool)

GetExtraChecksum returns the extra checksum which shall be calculated in the last stable schema version (whose elements are all public).

type NoChecksum

type NoChecksum struct{}

NoChecksum indicates no checksum is encoded into the returned raw bytes.

type RawChecksum

type RawChecksum struct {
	Handle kv.Handle
}

RawChecksum indicates encode the raw bytes checksum and append it to the raw bytes.

type RowData

type RowData struct {
	// Cols is a list of ColData which is expected to be sorted by id before calling Encode/Checksum.
	Cols []ColData
	// Data stores the result of Encode. However, it mostly acts as a buffer for encoding columns on checksum
	// calculation.
	Data []byte
}

RowData is a list of ColData for row checksum calculation.

func (*RowData) Checksum

func (r *RowData) Checksum(loc *time.Location) (checksum uint32, err error)

Checksum calculates the checksum of columns. Callers should make sure columns are sorted by id.

func (*RowData) Encode

func (r *RowData) Encode(loc *time.Location) ([]byte, error)

Encode encodes all columns into bytes (for test purpose).

func (RowData) Len

func (r RowData) Len() int

Len implements sort.Interface for RowData.

func (RowData) Less

func (r RowData) Less(i int, j int) bool

Less implements sort.Interface for RowData.

func (RowData) Swap

func (r RowData) Swap(i int, j int)

Swap implements sort.Interface for RowData.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL