pack

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Copyright (c) 2018-2022 Blockwatch Data Inc. Author: alex@blockwatch.cc

Copyright (c) 2018-2020 Blockwatch Data Inc. Author: alex@blockwatch.cc

Index

Constants

View Source
const (
	COND_OR  = true
	COND_AND = false
)
View Source
const (
	NoPk  uint64 = 0
	MinPk uint64 = 1
	MaxPk uint64 = math.MaxUint64
)
View Source
const (
	TableEnginePack = "pack"
	TableEngineKV   = "kv"
)

Variables

View Source
var (
	ErrNoEngine         = errors.New("pack: engine does not exist")
	ErrNoTable          = errors.New("pack: table does not exist")
	ErrNoStore          = errors.New("pack: store does not exist")
	ErrNoIndex          = errors.New("pack: index does not exist")
	ErrNoColumn         = errors.New("pack: column does not exist")
	ErrTypeMismatch     = errors.New("pack: type mismatch")
	ErrNoPk             = errors.New("pack: primary key not defined")
	ErrNoField          = errors.New("pack: field does not exist")
	ErrInvalidType      = errors.New("pack: unsupported block type")
	ErrNilValue         = errors.New("pack: nil value passed")
	ErrReadOnlyDatabase = errors.New("pack: database is read-only")

	ErrIndexNotFound  = errors.New("pack: index not found")
	ErrBucketNotFound = errors.New("pack: bucket not found")
	ErrPackNotFound   = errors.New("pack: pack not found")
	ErrPackStripped   = errors.New("pack: pack is stripped")
	ErrIdNotFound     = errors.New("pack: id not found")
	ErrKeyNotFound    = errors.New("pack: key not found")

	ErrTableExists  = errors.New("pack: table already exists")
	ErrStoreExists  = errors.New("pack: store already exists")
	ErrIndexExists  = errors.New("pack: index already exists")
	ErrResultClosed = errors.New("pack: result already closed")

	EndStream = errors.New("end stream")
)
View Source
var (
	ZERO = []byte{}
	FF   = []byte{0xff}
)
View Source
var (
	DefaultOptions = Options{
		PackSizeLog2:    defaultPackSizeLog2,
		JournalSizeLog2: 17,
		CacheSize:       defaultCacheSize,
		FillLevel:       90,
	}
	NoOptions = Options{}
)
View Source
var QueryLogMinDuration time.Duration = 500 * time.Millisecond

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func SortBatch

func SortBatch(idx int, rval reflect.Value, pks []uint64)

func UseLogger

func UseLogger(logger logpkg.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type BatchSorter

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

func NewBatchSorter

func NewBatchSorter(val reflect.Value, pks []uint64) BatchSorter

func (BatchSorter) Len

func (s BatchSorter) Len() int

func (BatchSorter) Less

func (s BatchSorter) Less(i, j int) bool

func (BatchSorter) Sort

func (s BatchSorter) Sort() bool

func (BatchSorter) Swap

func (s BatchSorter) Swap(i, j int)

type BinaryCondition

type BinaryCondition struct {
	Left  *Field
	Right *Field
	Mode  FilterMode
}

func NewPredicate

func NewPredicate(left, right string, mode FilterMode) BinaryCondition

func (*BinaryCondition) Bind

func (b *BinaryCondition) Bind(l, r Table)

func (BinaryCondition) Check

func (b BinaryCondition) Check() error

func (BinaryCondition) ComparePacksAt

func (b BinaryCondition) ComparePacksAt(p1 *Package, n1 int, p2 *Package, n2 int) int

func (BinaryCondition) MatchPacksAt

func (b BinaryCondition) MatchPacksAt(p1 *Package, n1 int, p2 *Package, n2 int) bool

type BlockInfo

type BlockInfo struct {
	Type        block.BlockType
	Compression block.Compression
	Scale       int

	// statistics
	MinValue    interface{}   // vector min
	MaxValue    interface{}   // vector max
	Bloom       *bloom.Filter // optimized bloom filter
	Cardinality uint32        // unique items in vector
	// contains filtered or unexported fields
}

func NewBlockInfo

func NewBlockInfo(b *block.Block, field *Field) BlockInfo

func (*BlockInfo) Decode

func (h *BlockInfo) Decode(buf *bytes.Buffer, version byte) error

func (BlockInfo) Encode

func (h BlockInfo) Encode(buf *bytes.Buffer) error

func (BlockInfo) EncodedSize

func (h BlockInfo) EncodedSize() int

func (BlockInfo) IsDirty

func (h BlockInfo) IsDirty() bool

func (BlockInfo) IsValid

func (h BlockInfo) IsValid() bool

func (BlockInfo) SetDirty

func (h BlockInfo) SetDirty()

type BlockInfoList

type BlockInfoList []BlockInfo

func (*BlockInfoList) Decode

func (h *BlockInfoList) Decode(buf *bytes.Buffer) error

func (BlockInfoList) Encode

func (h BlockInfoList) Encode(buf *bytes.Buffer) error

type Buffer

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

func NewBuffer

func NewBuffer(b []byte) *Buffer

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

func (*Buffer) DecRef

func (b *Buffer) DecRef() int64

func (*Buffer) HeapSize

func (b *Buffer) HeapSize() int

func (*Buffer) IncRef

func (b *Buffer) IncRef() int64

type CSVHeader

type CSVHeader struct {
	Key   string `csv:"Pack Key"`
	Cols  int    `csv:"Columns"`
	Rows  int    `csv:"Rows"`
	MinPk uint64 `csv:"Min RowId"`
	MaxPk uint64 `csv:"Max RowId"`
	Size  int    `csv:"Pack Size"`
}

type Condition

type Condition struct {
	Field    *Field      // evaluated table field
	Mode     FilterMode  // eq|ne|gt|gte|lt|lte|in|nin|re
	Raw      string      // string value when parsed from a query string
	Value    interface{} // typed value
	From     interface{} // typed value for range queries
	To       interface{} // typed value for range queries
	IsSorted bool        // IN/NIN condition slice is already pre-sorted
	// contains filtered or unexported fields
}

func (*Condition) Compile

func (c *Condition) Compile() (err error)

func (Condition) MatchPack

func (c Condition) MatchPack(pkg *Package, mask *vec.Bitset) *vec.Bitset

MatchPack matches all elements in package pkg against the defined condition and returns a bitset of the same length as the package with bits set to true where the match is successful.

This implementation uses low level block vectors to efficiently execute vectorized checks with custom assembly-optimized routines.

func (Condition) MatchValue

func (c Condition) MatchValue(val *Value) bool

func (Condition) MaybeMatchPack

func (c Condition) MaybeMatchPack(info PackInfo) bool

match package min/max values against the condition Note: min/max are raw storage values (i.e. for decimals, they are scaled integers)

func (Condition) NValues

func (c Condition) NValues() int

returns the number of values to compare 1 (other), 2 (RANGE), many (IN)

func (Condition) PkRange

func (c Condition) PkRange() (uint64, uint64)

Notes: - 0 is an illegal PK, legal range is 1..uint64_max - compiled conditions guarantee:

  • value type is uint64
  • from/to and IN/NIN slices are sorted

func (Condition) String

func (c Condition) String() string

type ConditionTreeNode

type ConditionTreeNode struct {
	OrKind   bool                // AND|OR
	Children []ConditionTreeNode // sub conditions
	Cond     *Condition          // ptr to condition
	Bits     bitmap.Bitmap       // index query result
}

func (*ConditionTreeNode) AddAndCondition

func (n *ConditionTreeNode) AddAndCondition(c *Condition)

func (*ConditionTreeNode) AddNode

func (n *ConditionTreeNode) AddNode(node ConditionTreeNode)

Invariants - root is always an AND node - root is never a leaf node - root may be empty

func (*ConditionTreeNode) AddOrCondition

func (n *ConditionTreeNode) AddOrCondition(c *Condition)

func (*ConditionTreeNode) Compile

func (n *ConditionTreeNode) Compile() error

may otimize (merge/replace) conditions in the future

func (ConditionTreeNode) Conditions

func (n ConditionTreeNode) Conditions() []*Condition

func (ConditionTreeNode) Cost

func (n ConditionTreeNode) Cost(info PackInfo) int

returns the subtree execution cost based on the number of rows that may be visited in the given pack for a full scan times the number of comparisons

func (ConditionTreeNode) Depth

func (n ConditionTreeNode) Depth() int

Depth returns the max number of tree levels

func (ConditionTreeNode) Dump

func (n ConditionTreeNode) Dump() string

func (ConditionTreeNode) Empty

func (n ConditionTreeNode) Empty() bool

func (ConditionTreeNode) Fields

func (n ConditionTreeNode) Fields() FieldList

returns unique list of fields

func (ConditionTreeNode) IsNested

func (n ConditionTreeNode) IsNested() bool

func (ConditionTreeNode) IsProcessed

func (n ConditionTreeNode) IsProcessed() bool

func (ConditionTreeNode) Leaf

func (n ConditionTreeNode) Leaf() bool

func (ConditionTreeNode) MatchPack

func (n ConditionTreeNode) MatchPack(pkg *Package, info PackInfo) *vec.Bitset

func (ConditionTreeNode) MatchPackAnd

func (n ConditionTreeNode) MatchPackAnd(pkg *Package, info PackInfo) *vec.Bitset

Return a bit vector containing matching positions in the pack combining multiple AND conditions with efficient skipping and aggregation. TODO: consider concurrent matches for multiple conditions and cascading bitset merge

func (ConditionTreeNode) MatchPackOr

func (n ConditionTreeNode) MatchPackOr(pkg *Package, info PackInfo) *vec.Bitset

Return a bit vector containing matching positions in the pack combining multiple OR conditions with efficient skipping and aggregation.

func (ConditionTreeNode) MatchValue

func (n ConditionTreeNode) MatchValue(v *Value) bool

func (ConditionTreeNode) MaybeMatchPack

func (n ConditionTreeNode) MaybeMatchPack(info PackInfo) bool

func (ConditionTreeNode) NoMatch

func (n ConditionTreeNode) NoMatch() bool

func (ConditionTreeNode) PkRange

func (n ConditionTreeNode) PkRange() (uint64, uint64)

func (ConditionTreeNode) Size

func (n ConditionTreeNode) Size() int

Size returns the total number of condition leaf nodes

func (ConditionTreeNode) Weight

func (n ConditionTreeNode) Weight() int

returns the decision tree size (including sub-conditions)

type DB

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

func CreateDatabase

func CreateDatabase(engine, path, name, label string, opts any) (*DB, error)

func CreateDatabaseIfNotExists

func CreateDatabaseIfNotExists(engine, path, name, label string, opts any) (*DB, error)

func OpenDatabase

func OpenDatabase(engine, path, name, label string, opts any) (*DB, error)

func (*DB) Close

func (d *DB) Close() error

func (*DB) CloseStore

func (d *DB) CloseStore(s Store) error

func (*DB) CloseTable

func (d *DB) CloseTable(t Table) error

func (*DB) CreateStore

func (d *DB) CreateStore(name string, opts Options) (Store, error)

func (*DB) CreateStoreIfNotExists

func (d *DB) CreateStoreIfNotExists(name string, opts Options) (Store, error)

func (*DB) CreateTable

func (d *DB) CreateTable(engine TableEngine, name string, fields FieldList, opts Options) (Table, error)

func (*DB) CreateTableIfNotExists

func (d *DB) CreateTableIfNotExists(engine TableEngine, name string, fields FieldList, opts Options) (Table, error)

func (*DB) Dir

func (d *DB) Dir() string

func (*DB) DropStore

func (d *DB) DropStore(name string) error

func (*DB) DropTable

func (d *DB) DropTable(name string) error

func (*DB) Dump

func (d *DB) Dump(w io.Writer) error

func (*DB) Engine

func (d *DB) Engine() string

func (*DB) GC

func (d *DB) GC(ctx context.Context, ratio float64) error

func (*DB) IsClosed

func (d *DB) IsClosed() bool

func (*DB) IsReadOnly

func (d *DB) IsReadOnly() bool

func (*DB) IsUsed

func (d *DB) IsUsed() bool

func (*DB) ListIndexNames

func (d *DB) ListIndexNames(table string) ([]string, error)

func (*DB) ListStoreNames

func (d *DB) ListStoreNames() ([]string, error)

func (*DB) ListTableNames

func (d *DB) ListTableNames() ([]string, error)

func (*DB) Manifest

func (d *DB) Manifest() (store.Manifest, error)

func (*DB) NumOpenStores

func (d *DB) NumOpenStores() int

func (*DB) NumOpenTables

func (d *DB) NumOpenTables() int

func (*DB) OpenStore

func (d *DB) OpenStore(name string, opts Options) (Store, error)

func (*DB) OpenStores

func (d *DB) OpenStores() []Store

func (*DB) OpenTable

func (d *DB) OpenTable(engine TableEngine, name string, opts Options) (Table, error)

func (*DB) OpenTables

func (d *DB) OpenTables() []Table

func (*DB) Path

func (d *DB) Path() string

func (*DB) Tx

func (d *DB) Tx(writeable bool) (*Tx, error)

func (*DB) Update

func (d *DB) Update(fn func(*Tx) error) error

func (*DB) UpdateManifest

func (d *DB) UpdateManifest(name, label string) error

func (*DB) View

func (d *DB) View(fn func(*Tx) error) error

type DumpMode

type DumpMode int
const (
	DumpModeDec DumpMode = iota
	DumpModeHex
	DumpModeCSV
)

type Field

type Field struct {
	Index int        `json:"index"`
	Name  string     `json:"name"`
	Alias string     `json:"alias"`
	Type  FieldType  `json:"type"`
	Flags FieldFlags `json:"flags"` // primary, indexed, compression
	Scale int        `json:"scale"` // 0..127 fixed point scale, bloom error probability 1/x
	IKind IndexKind  `json:"ikind"` // index type: hash, integer
}

func (Field) DecodeValue

func (f Field) DecodeValue(buf *bytes.Buffer, dst reflect.Value, finfo *fieldInfo) (err error)

func (Field) Encode

func (f Field) Encode(val any) ([]byte, error)

func (Field) EncodeValue

func (f Field) EncodeValue(buf *bytes.Buffer, val reflect.Value, finfo *fieldInfo) (err error)

use BigEndian to be able to reuse encoded data as searchable key

func (Field) Equal

func (f Field) Equal(f2 Field) bool

func (Field) IsPk

func (f Field) IsPk() bool

func (Field) IsValid

func (f Field) IsValid() bool

func (Field) NewBlock

func (f Field) NewBlock(sz int) *block.Block

func (Field) SkipValue

func (f Field) SkipValue(buf *bytes.Buffer) (err error)

type FieldFlags

type FieldFlags int
const (
	FlagPrimary FieldFlags = 1 << iota
	FlagIndexed
	FlagCompressSnappy
	FlagCompressLZ4
	FlagBloom
)

func (FieldFlags) Compression

func (f FieldFlags) Compression() block.Compression

func (FieldFlags) Contains

func (f FieldFlags) Contains(i FieldFlags) bool

func (FieldFlags) String

func (f FieldFlags) String() string

type FieldList

type FieldList []*Field

func Fields

func Fields(proto interface{}) (FieldList, error)

func MakeSchema

func MakeSchema(proto any) (FieldList, error)

func (FieldList) Add

func (l FieldList) Add(field *Field) FieldList

func (FieldList) AddUnique

func (l FieldList) AddUnique(fields ...*Field) FieldList

func (FieldList) Aliases

func (l FieldList) Aliases() []string

func (FieldList) Clone

func (l FieldList) Clone() FieldList

func (FieldList) CompositePk

func (l FieldList) CompositePk() FieldList

func (FieldList) Contains

func (l FieldList) Contains(name string) bool

func (FieldList) CopyData

func (l FieldList) CopyData(pos []int, val []byte) []byte

TODO: refactor to use Value type assumes value contains all encoded data fields outputs byte and string with length prefixed

func (FieldList) Decode

func (l FieldList) Decode(buf []byte, val any) error

func (FieldList) DecodeWithInfo

func (l FieldList) DecodeWithInfo(buf []byte, val any, tinfo *typeInfo) error

func (FieldList) Encode

func (l FieldList) Encode(val any) ([]byte, error)

func (FieldList) EncodeValue

func (l FieldList) EncodeValue(buf *bytes.Buffer, val reflect.Value, tinfo *typeInfo) error

func (FieldList) Find

func (l FieldList) Find(name string) *Field

func (FieldList) HasCompositePk

func (l FieldList) HasCompositePk() bool

func (FieldList) HasPk

func (l FieldList) HasPk() bool

func (FieldList) Hash

func (l FieldList) Hash() uint64

func (FieldList) Indexed

func (l FieldList) Indexed() FieldList

func (FieldList) Mask

func (l FieldList) Mask(m FieldList) []byte

func (FieldList) MaskString

func (l FieldList) MaskString(m FieldList) string

func (FieldList) MergeUnique

func (l FieldList) MergeUnique(fields ...*Field) FieldList

func (FieldList) NameMap

func (l FieldList) NameMap() map[string]string

short -> long name map

func (FieldList) NameMapReverse

func (l FieldList) NameMapReverse() map[string]string

long -> short name map

func (FieldList) Names

func (l FieldList) Names() []string

func (FieldList) Pk

func (l FieldList) Pk() *Field

func (FieldList) PkIndex

func (l FieldList) PkIndex() int

func (FieldList) Select

func (l FieldList) Select(names ...string) FieldList

func (FieldList) SelectChecked

func (l FieldList) SelectChecked(names ...string) (FieldList, error)

func (FieldList) Sort

func (l FieldList) Sort() FieldList

func (FieldList) String

func (l FieldList) String() string

type FieldType

type FieldType byte
const (
	FieldTypeUndefined  FieldType = iota
	FieldTypeDatetime             // BlockTime
	FieldTypeInt64                // BlockInt64
	FieldTypeUint64               // BlockUint64
	FieldTypeFloat64              // BlockFloat64
	FieldTypeBoolean              // BlockBool
	FieldTypeString               // BlockString
	FieldTypeBytes                // BlockBytes
	FieldTypeInt32                // BlockInt32
	FieldTypeInt16                // BlockInt16
	FieldTypeInt8                 // BlockInt8
	FieldTypeUint32               // BlockUint32
	FieldTypeUint16               // BlockUint16
	FieldTypeUint8                // BlockUint8
	FieldTypeFloat32              // BlockFloat32
	FieldTypeInt256               // BlockInt256
	FieldTypeInt128               // BlockInt128
	FieldTypeDecimal256           // BlockDecimal256
	FieldTypeDecimal128           // BlockDecimal128
	FieldTypeDecimal64            // BlockDecimal64
	FieldTypeDecimal32            // BlockDecimal32

)

func ParseFieldType

func ParseFieldType(s string) FieldType

func (FieldType) Between

func (t FieldType) Between(val, from, to interface{}) bool

assumes from <= to

func (FieldType) BetweenBlock

func (t FieldType) BetweenBlock(b *block.Block, from, to interface{}, bits, mask *Bitset) *Bitset

assumes from <= to

func (FieldType) BlockType

func (t FieldType) BlockType() block.BlockType

func (FieldType) BuildBloomFilter

func (t FieldType) BuildBloomFilter(b *block.Block, cardinality uint32, factor int) *bloom.Filter

func (FieldType) CastSliceType

func (t FieldType) CastSliceType(val interface{}, f *Field) (interface{}, error)

func (FieldType) CastType

func (t FieldType) CastType(val interface{}, f *Field) (interface{}, error)

func (FieldType) CheckSliceType

func (t FieldType) CheckSliceType(val interface{}) error

func (FieldType) CheckType

func (t FieldType) CheckType(val interface{}) error

func (FieldType) Compare

func (t FieldType) Compare(xa, xb interface{}) int

Used by BinaryCondition during join.

func (FieldType) CopySliceType

func (t FieldType) CopySliceType(val interface{}) (interface{}, error)

func (FieldType) Equal

func (t FieldType) Equal(xa, xb interface{}) bool

Used in BinaryCondition MatchPacksAt() for loop joins Used in Condition.MatchValue for KV table matches

func (FieldType) EqualBlock

func (t FieldType) EqualBlock(b *block.Block, val interface{}, bits, mask *Bitset) *Bitset

func (FieldType) EqualPacksAt

func (t FieldType) EqualPacksAt(p1 *Package, i1, n1 int, p2 *Package, i2, n2 int) bool

Used by flushTx for checking whether a row update changes any indexed column and updates indexes when true.

func (FieldType) EstimateCardinality

func (t FieldType) EstimateCardinality(b *block.Block, precision uint) uint32

func (FieldType) Gt

func (t FieldType) Gt(xa, xb interface{}) bool

func (FieldType) GtBlock

func (t FieldType) GtBlock(b *block.Block, val interface{}, bits, mask *Bitset) *Bitset

func (FieldType) Gte

func (t FieldType) Gte(xa, xb interface{}) bool

func (FieldType) GteBlock

func (t FieldType) GteBlock(b *block.Block, val interface{}, bits, mask *Bitset) *Bitset

func (FieldType) Hash

func (t FieldType) Hash(val interface{}) [2]uint32

Hash produces a hash value compatible with bloom filters.

func (FieldType) In

func (t FieldType) In(v, in interface{}) bool

first arg is value to compare, second is slice of value types from condition

func (FieldType) InBetween

func (t FieldType) InBetween(slice, from, to interface{}) bool

using binary search to find if slice contains values in interval [from, to] Note: there's no *At func because this function works on slices already assumes from <= to

func (FieldType) IsValid

func (t FieldType) IsValid() bool

func (FieldType) Len

func (t FieldType) Len() int

func (FieldType) Lt

func (t FieldType) Lt(xa, xb interface{}) bool

func (FieldType) LtBlock

func (t FieldType) LtBlock(b *block.Block, val interface{}, bits, mask *Bitset) *Bitset

func (FieldType) Lte

func (t FieldType) Lte(xa, xb interface{}) bool

func (FieldType) LteBlock

func (t FieldType) LteBlock(b *block.Block, val interface{}, bits, mask *Bitset) *Bitset

func (FieldType) MarshalText

func (r FieldType) MarshalText() ([]byte, error)

func (FieldType) NotEqualBlock

func (t FieldType) NotEqualBlock(b *block.Block, val interface{}, bits, mask *Bitset) *Bitset

func (FieldType) ParseAs

func (t FieldType) ParseAs(s string, f *Field) (interface{}, error)

func (FieldType) ParseSliceAs

func (t FieldType) ParseSliceAs(s string, f *Field) (interface{}, error)

func (FieldType) Regexp

func (t FieldType) Regexp(v interface{}, re string) bool

func (FieldType) RegexpBlock

func (t FieldType) RegexpBlock(b *block.Block, re string, bits, mask *Bitset) *Bitset

func (FieldType) SliceToString

func (t FieldType) SliceToString(val interface{}, f *Field) string

func (FieldType) String

func (t FieldType) String() string

func (*FieldType) UnmarshalText

func (t *FieldType) UnmarshalText(data []byte) error

type FilterMode

type FilterMode int
const (
	FilterModeInvalid FilterMode = iota
	FilterModeEqual
	FilterModeNotEqual
	FilterModeGt
	FilterModeGte
	FilterModeLt
	FilterModeLte
	FilterModeIn
	FilterModeNotIn
	FilterModeRange
	FilterModeRegexp
)

func ParseFilterMode

func ParseFilterMode(s string) FilterMode

func (FilterMode) IsScalar

func (m FilterMode) IsScalar() bool

func (FilterMode) IsValid

func (m FilterMode) IsValid() bool

func (FilterMode) Op

func (m FilterMode) Op() string

func (FilterMode) String

func (m FilterMode) String() string

type ForwardIterator

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

func NewForwardIterator

func NewForwardIterator(q *Query) *ForwardIterator

func (*ForwardIterator) Close

func (it *ForwardIterator) Close()

func (*ForwardIterator) Next

func (it *ForwardIterator) Next(tx *Tx) (*Package, []uint32, error)

type GenericStore

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

func CreateGenericStore

func CreateGenericStore(d *DB, name string, opts Options) (*GenericStore, error)

func OpenGenericStore

func OpenGenericStore(d *DB, name string, opts Options) (*GenericStore, error)

func (*GenericStore) Close

func (s *GenericStore) Close() error

func (*GenericStore) DB

func (s *GenericStore) DB() *DB

func (*GenericStore) Del

func (s *GenericStore) Del(key []byte) error

func (*GenericStore) Del64

func (s *GenericStore) Del64(key uint64) error

func (*GenericStore) DelTx

func (s *GenericStore) DelTx(tx *Tx, key []byte) ([]byte, error)

func (*GenericStore) DeleteValue64

func (s *GenericStore) DeleteValue64(key uint64) error

compat interface for bitset storage

func (*GenericStore) Drop

func (s *GenericStore) Drop() error

func (*GenericStore) Engine

func (s *GenericStore) Engine() string

func (*GenericStore) Get

func (s *GenericStore) Get(key []byte) ([]byte, error)

low-level interface for direct KV storage access

func (*GenericStore) Get64

func (s *GenericStore) Get64(key uint64) ([]byte, error)

func (*GenericStore) GetTx

func (s *GenericStore) GetTx(tx *Tx, key []byte) []byte

func (*GenericStore) GetValue64

func (s *GenericStore) GetValue64(key uint64, val any) error

compat interface for bitset storage

func (*GenericStore) IsClosed

func (s *GenericStore) IsClosed() bool

func (*GenericStore) Name

func (s *GenericStore) Name() string

func (*GenericStore) Options

func (s *GenericStore) Options() Options

func (*GenericStore) PrefixRange

func (s *GenericStore) PrefixRange(prefix []byte, fn func(k, v []byte) error) error

poor man's query interface where user generates key range and decodes key + value

func (*GenericStore) PurgeCache

func (s *GenericStore) PurgeCache()

func (*GenericStore) Put

func (s *GenericStore) Put(key, val []byte) error

func (*GenericStore) Put64

func (s *GenericStore) Put64(key uint64, val []byte) error

func (*GenericStore) PutTx

func (s *GenericStore) PutTx(tx *Tx, key, val []byte) ([]byte, error)

func (*GenericStore) PutValue64

func (s *GenericStore) PutValue64(key uint64, val any) error

compat interface for bitset storage

func (*GenericStore) Range

func (s *GenericStore) Range(from, to []byte, fn func(k, v []byte) error) error

func (*GenericStore) Stats

func (s *GenericStore) Stats() []TableStats

type Index

type Index interface {
	Name() string
	Kind() IndexKind
	Drop() error
	PurgeCache()
	Fields() FieldList
	Stats() TableStats
	AddTx(tx *Tx, prev, val []byte) error
	DelTx(tx *Tx, prev []byte) error
	ScanTx(tx *Tx, prefix []byte) (bitmap.Bitmap, error)
	RangeTx(tx *Tx, from, to []byte) (bitmap.Bitmap, error)
	CloseTx(*Tx) error
}

type IndexData

type IndexData struct {
	Kind   IndexKind `json:"kind"`   // stored in table metadata
	Fields FieldList `json:"fields"` // stored in table metadata
}

type IndexKind

type IndexKind int
const (
	IndexKindNone      IndexKind = iota
	IndexKindHash                // any col (any type) -> uint64 FNV hash
	IndexKindInteger             // any col ((u)int64) -> pk (uint64)
	IndexKindComposite           // multiple cols binary key + binary pk (uint64, 8 byte)
)

func (IndexKind) MarshalText

func (t IndexKind) MarshalText() ([]byte, error)

func (IndexKind) MayHaveCollisions

func (t IndexKind) MayHaveCollisions() bool

func (IndexKind) String

func (t IndexKind) String() string

func (*IndexKind) UnmarshalText

func (t *IndexKind) UnmarshalText(d []byte) error

func (IndexKind) ValueAtFunc

func (t IndexKind) ValueAtFunc() IndexValueAtFunc

func (IndexKind) ValueFunc

func (t IndexKind) ValueFunc() IndexValueFunc

func (IndexKind) ZeroAtFunc

func (t IndexKind) ZeroAtFunc() IndexZeroAtFunc

type IndexList

type IndexList []Index

func (IndexList) Find

func (l IndexList) Find(name string) Index

type IndexValueAtFunc

type IndexValueAtFunc func(typ FieldType, pkg *Package, index, pos int) uint64

type IndexValueFunc

type IndexValueFunc func(typ FieldType, val interface{}) uint64

type IndexZeroAtFunc

type IndexZeroAtFunc func(pkg *Package, index, pos int) bool

type Join

type Join struct {
	Type      JoinType
	Predicate BinaryCondition
	Left      JoinTable
	Right     JoinTable
	// contains filtered or unexported fields
}

func (Join) AppendResult

func (j Join) AppendResult(out, left *Package, l int, right *Package, r int) error

func (Join) CheckConditions

func (j Join) CheckConditions() error

func (Join) CheckInputs

func (j Join) CheckInputs() error

func (*Join) Compile

func (j *Join) Compile() error

compile output field list and where conditions

func (Join) Dump

func (j Join) Dump() string

func (Join) Fields

func (j Join) Fields() FieldList

func (Join) IsEquiJoin

func (j Join) IsEquiJoin() bool

func (Join) Query

func (j Join) Query(ctx context.Context, q Query) (*Result, error)

func (Join) Stream

func (j Join) Stream(ctx context.Context, q Query, fn func(r Row) error) error

TODO

type JoinTable

type JoinTable struct {
	Table    Table
	Where    UnboundCondition // optional filters for table rows
	Fields   util.StringList  // list of output fields, in order
	FieldsAs util.StringList  // alias names of output fields, in order
	Limit    int              // individual table scan limit
	// contains filtered or unexported fields
}

type JoinType

type JoinType int
const (
	InnerJoin  JoinType = iota // INNER JOIN (maybe EQUI JOIN)
	LeftJoin                   // LEFT OUTER JOIN
	RightJoin                  // RIGHT OUTER JOIN
	FullJoin                   // FULL OUTER JOIN
	CrossJoin                  // CROSS JOIN
	SelfJoin                   // unused
	AsOfJoin                   // see https://code.kx.com/q4m3/9_Queries_q-sql/#998-as-of-joins
	WindowJoin                 // see https://code.kx.com/q4m3/9_Queries_q-sql/#999-window-join
)

func (JoinType) String

func (t JoinType) String() string

type Journal

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

Append-only journal and in-memory tombstone

- supports INSERT, UPSERT, UPDATE, DELETE - supports walking the journal by pk order (required for queries and flush) - journal pack data is only sorted by insert order, not necessarily pk order - primary key to position mapping is always sorted in pk order - tombstone is always sorted - re-inserting deleted entries is safe

To avoid sorting the journal after insert, but still process journal entries in pk sort order (in queries or flush and in both directions), we keep a mapping from pk to journal position in `keys` which is always sorted by pk.

How the journal is used

Lookup: (non-order-preserving) matches against pk values only. For best performance we pre-sort the pk's we want to look up.

Query, Stream, Count: runs a full pack match on the journal's data pack. Note the resulting bitset is in storage order, not pk order!. Then a query walks all table packs and cross-check with tomb + journal to decide if/which rows to return to the caller. Ticks off journal matches from the match bitset as they are visted along the way. Finally, walks all tail entries that only exist in the journal but were never flushed to a table pack. Since the bitset is in storage order we must translate it into pk order for this step to work. This is what SortedIndexes() and SortedIndexesReversed() are for.

TODO - write all incoming inserts/updates/deletes to a WAL - load and reconstructed journal + tomb from WAL

func NewJournal

func NewJournal(maxid uint64, size int, name string) *Journal

func (*Journal) Close

func (j *Journal) Close()

func (*Journal) DataPack

func (j *Journal) DataPack() *Package

func (*Journal) Delete

func (j *Journal) Delete(pk uint64) (int, error)

func (*Journal) DeleteBatch

func (j *Journal) DeleteBatch(pks []uint64) (int, error)

func (*Journal) HeapSize

func (j *Journal) HeapSize() int

func (*Journal) InitFields

func (j *Journal) InitFields(fields FieldList) error

func (*Journal) InitType

func (j *Journal) InitType(typ interface{}) error

func (*Journal) Insert

func (j *Journal) Insert(val any) error

func (*Journal) InsertBatch

func (j *Journal) InsertBatch(batch reflect.Value) (int, error)

Inserts multiple items, returns number of successfully processed items. Inserts with pk == 0 will generate a new pk > maxpk in sequential order. Inserts with an external pk (pk > 0) will insert or upsert and track the maximum pk seen.

func (*Journal) InsertPack

func (j *Journal) InsertPack(pkg *Package, pos, n int) (int, error)

Assumes no duplicates. pkg is not trusted to be sorted. It may come from a desc-ordered query result or from a result that has been sorted by a different field than the primary key. Primary key may exist (>0), but is generated when missing.

func (*Journal) IsDeleted

func (j *Journal) IsDeleted(pk uint64, last int) (bool, int)

Efficient check if a pk is in the tomb or not. Use `last` to skip already processed entries when walking through a sorted list of pks.

func (*Journal) IsSorted

func (j *Journal) IsSorted() bool

func (*Journal) LastId

func (j *Journal) LastId() uint64

func (*Journal) Len

func (j *Journal) Len() int

func (*Journal) LoadLegacy

func (j *Journal) LoadLegacy(tx *Tx, bucketName []byte) error

func (*Journal) MaxId

func (j *Journal) MaxId() uint64

func (*Journal) Open

func (j *Journal) Open(path string) error

func (*Journal) PkIndex

func (j *Journal) PkIndex(pk uint64, last int) (int, int)

Returns the journal index at which pk is stored or -1 when pk is not found and the last index that matched. Using the last argument allows to skip searching a part of the journal for better efficiency in loops. This works only if subsequent calls can guarantee that queried primary keys are sorted, i.e. the next pk is larger than the previous pk.

var last, index int

for last < journal.Len() {
   index, last = journal.PkIndex(pk, last)
}

Invariant: keys list is always sorted

func (*Journal) Reset

func (j *Journal) Reset()

func (*Journal) ShouldFlush

func (j *Journal) ShouldFlush() bool

func (*Journal) SortedIndexes

func (j *Journal) SortedIndexes(b *vec.Bitset) ([]int, []uint64)

On lookup/query we run matching algos on the journal pack which produce a bitset of all matches. The algo below takes this bitset and translates it into a pk sorted index list.

1. Cond.MatchPack() -> Bitset (1s at unsorted journal matches) 2. Bitset.Indexes() -> []int (positions in unsorted journal) 3. data.Column(pkid) -> []uint64 (lookup pks at indexes) 4. Joined sort index/pks by pk 5. Return pk-sorted index list

func (*Journal) SortedIndexesReversed

func (j *Journal) SortedIndexesReversed(b *vec.Bitset) ([]int, []uint64)

func (*Journal) StoreLegacy

func (j *Journal) StoreLegacy(tx *Tx, bucketName []byte) (int, int, error)

func (*Journal) TombLen

func (j *Journal) TombLen() int

func (*Journal) Update

func (j *Journal) Update(val any) error

func (*Journal) UpdateBatch

func (j *Journal) UpdateBatch(batch reflect.Value) (int, error)

Updates multiple items by inserting or overwriting them in the journal, returns the number of successsfully processed items. Batch is expected to be sorted.

type KeyValueIndex

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

func CreateKeyValueIndex

func CreateKeyValueIndex(t Table, kind IndexKind, fields FieldList, _ Options) (*KeyValueIndex, error)

func OpenKeyValueIndex

func OpenKeyValueIndex(t Table, kind IndexKind, fields FieldList, _ Options) (*KeyValueIndex, error)

func (*KeyValueIndex) AddTx

func (idx *KeyValueIndex) AddTx(tx *Tx, prev, val []byte) error

func (*KeyValueIndex) DelTx

func (idx *KeyValueIndex) DelTx(tx *Tx, prev []byte) error

func (*KeyValueIndex) Drop

func (idx *KeyValueIndex) Drop() error

func (*KeyValueIndex) Fields

func (idx *KeyValueIndex) Fields() FieldList

func (*KeyValueIndex) Key

func (idx *KeyValueIndex) Key() []byte

func (KeyValueIndex) Kind

func (idx KeyValueIndex) Kind() IndexKind

func (KeyValueIndex) MarshalJSON

func (idx KeyValueIndex) MarshalJSON() ([]byte, error)

func (KeyValueIndex) Name

func (idx KeyValueIndex) Name() string

func (*KeyValueIndex) RangeTx

func (idx *KeyValueIndex) RangeTx(tx *Tx, from, to []byte) (bitmap.Bitmap, error)

func (*KeyValueIndex) Scan

func (idx *KeyValueIndex) Scan(prefix []byte) (bitmap.Bitmap, error)

func (*KeyValueIndex) ScanTx

func (idx *KeyValueIndex) ScanTx(tx *Tx, prefix []byte) (bitmap.Bitmap, error)

func (*KeyValueIndex) UnmarshalJSON

func (idx *KeyValueIndex) UnmarshalJSON(buf []byte) error

type KeyValueMarshaler

type KeyValueMarshaler interface {
	MarshalKey() ([]byte, error)
	MarshalValue() ([]byte, error)
}

Marshaler interface, a more performant alternative to type based {Get|Put|Delete}Value methods, but incompatible with secondary indexes.

type KeyValueTable

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

func CreateKeyValueTable

func CreateKeyValueTable(d *DB, name string, fields FieldList, opts Options) (*KeyValueTable, error)

func OpenKeyValueTable

func OpenKeyValueTable(d *DB, name string, opts Options) (*KeyValueTable, error)

func (*KeyValueTable) Close

func (t *KeyValueTable) Close() error

func (*KeyValueTable) Compact

func (t *KeyValueTable) Compact(_ context.Context) error

func (*KeyValueTable) Count

func (t *KeyValueTable) Count(ctx context.Context, q Query) (int64, error)

func (*KeyValueTable) CreateIndex

func (t *KeyValueTable) CreateIndex(kind IndexKind, fields FieldList, opts Options) error

func (*KeyValueTable) CreateIndexIfNotExists

func (t *KeyValueTable) CreateIndexIfNotExists(kind IndexKind, fields FieldList, opts Options) error

func (*KeyValueTable) DB

func (t *KeyValueTable) DB() *DB

func (*KeyValueTable) Del

func (t *KeyValueTable) Del(key []byte) error

func (*KeyValueTable) Del64

func (t *KeyValueTable) Del64(key uint64) error

func (*KeyValueTable) DelTx

func (t *KeyValueTable) DelTx(tx *Tx, key []byte) ([]byte, error)

func (*KeyValueTable) Delete

func (t *KeyValueTable) Delete(ctx context.Context, q Query) (int64, error)

func (*KeyValueTable) DeletePks

func (t *KeyValueTable) DeletePks(ctx context.Context, pks []uint64) (int64, error)

func (*KeyValueTable) DeleteValue

func (t *KeyValueTable) DeleteValue(val any) error

func (*KeyValueTable) Drop

func (t *KeyValueTable) Drop() error

func (*KeyValueTable) DropIndex

func (t *KeyValueTable) DropIndex(fields FieldList) error

func (*KeyValueTable) Engine

func (_ *KeyValueTable) Engine() TableEngine

func (*KeyValueTable) Fields

func (t *KeyValueTable) Fields() FieldList

func (*KeyValueTable) Get

func (t *KeyValueTable) Get(key []byte) ([]byte, error)

low-level interface for direct KV storage access

func (*KeyValueTable) Get64

func (t *KeyValueTable) Get64(key uint64) ([]byte, error)

func (*KeyValueTable) GetTx

func (t *KeyValueTable) GetTx(tx *Tx, key []byte) []byte

func (*KeyValueTable) Insert

func (t *KeyValueTable) Insert(_ context.Context, val any) error

Table Compat interface

func (*KeyValueTable) IsClosed

func (t *KeyValueTable) IsClosed() bool

func (*KeyValueTable) LookupPks

func (t *KeyValueTable) LookupPks(ctx context.Context, pks []uint64) (*Result, error)

func (*KeyValueTable) Name

func (t *KeyValueTable) Name() string

func (*KeyValueTable) NextSequence

func (t *KeyValueTable) NextSequence() uint64

func (*KeyValueTable) Options

func (t *KeyValueTable) Options() Options

func (*KeyValueTable) PurgeCache

func (_ *KeyValueTable) PurgeCache()

func (*KeyValueTable) Put

func (t *KeyValueTable) Put(key, val []byte) error

func (*KeyValueTable) Put64

func (t *KeyValueTable) Put64(key uint64, val []byte) error

func (*KeyValueTable) PutTx

func (t *KeyValueTable) PutTx(tx *Tx, key, val []byte) ([]byte, error)

func (*KeyValueTable) PutValue

func (t *KeyValueTable) PutValue(val any) error

func (*KeyValueTable) Query

func (t *KeyValueTable) Query(ctx context.Context, q Query) (*Result, error)

func (*KeyValueTable) QueryIndexesTx

func (t *KeyValueTable) QueryIndexesTx(ctx context.Context, tx *Tx, node *ConditionTreeNode) (int, error)

func (*KeyValueTable) RebuildIndex

func (t *KeyValueTable) RebuildIndex(idx *KeyValueIndex) error

FIXME: this accesses private index fields, better to hide rebuild behind interface and stream table data

func (*KeyValueTable) Stats

func (t *KeyValueTable) Stats() []TableStats

func (*KeyValueTable) Stream

func (t *KeyValueTable) Stream(ctx context.Context, q Query, fn func(Row) error) error

func (*KeyValueTable) StreamPks

func (t *KeyValueTable) StreamPks(ctx context.Context, pks []uint64, fn func(r Row) error) error

func (*KeyValueTable) Sync

func (t *KeyValueTable) Sync(_ context.Context) error

func (*KeyValueTable) Update

func (t *KeyValueTable) Update(ctx context.Context, val any) error

type KeyValueUnmarshaler

type KeyValueUnmarshaler interface {
	UnmarshalKey([]byte) error
	UnmarshalValue([]byte) error
}

type LookupIterator

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

func NewLookupIterator

func NewLookupIterator(q *Query, pks []uint64) *LookupIterator

func (*LookupIterator) Close

func (it *LookupIterator) Close()

func (*LookupIterator) Next

func (it *LookupIterator) Next(tx *Tx) (*Package, uint64, error)

type Options

type Options struct {
	PackSizeLog2    int `json:"pack_size_log2,omitempty"`
	JournalSizeLog2 int `json:"journal_size_log2,omitempty"`
	CacheSize       int `json:"cache_size,omitempty"`
	FillLevel       int `json:"fill_level,omitempty"`
}

func (Options) CacheSizeMBytes

func (o Options) CacheSizeMBytes() int

func (Options) Check

func (o Options) Check() error

func (Options) IsValid

func (o Options) IsValid() bool

func (Options) JournalSize

func (o Options) JournalSize() int

func (Options) Merge

func (o Options) Merge(o2 Options) Options

Notes: allow cache size to be zero

func (Options) PackSize

func (o Options) PackSize() int

type OrderType

type OrderType int
const (
	OrderAsc OrderType = iota
	OrderDesc
)

func ParseOrderType

func ParseOrderType(s string) (OrderType, error)

func (OrderType) MarshalText

func (o OrderType) MarshalText() ([]byte, error)

func (OrderType) String

func (o OrderType) String() string

func (*OrderType) UnmarshalText

func (o *OrderType) UnmarshalText(data []byte) error

type PackHeader

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

PackHeader implements efficient and scalable pack info/stats management as well as primary key placement (i.e. best pack selection) for tables and indexes.

Packs are stored and referenced in key order ([4]byte = big endian uint32), and primary keys have a global order across packs. This means pk min-max ranges are unordered, but never overlap.

PackHeader takes care of searching a pack that may contain a given pk and can select the best pack to store a new pk into. New or updated packs (i.e. from calls to split or storePack) are registered using their pack info. When empty packs are deleted (Table only) they must be deregistered.

PackHeader keeps a list of all current pack info/stats and a list of all removed keys in memory. Use storePackHeader to persist the pack index to storage.

func NewPackHeader

func NewPackHeader(packs PackInfoList, pkidx, maxsize int) *PackHeader

may be used in {Index|Table}.loadPackHeaders

func (*PackHeader) AddOrUpdate

func (l *PackHeader) AddOrUpdate(head PackInfo)

called by storePack

func (*PackHeader) Best

func (l *PackHeader) Best(val uint64) (pos int, packmin uint64, packmax uint64, nextmin uint64, isFull bool)

Returns placement hint and pack info for the specified primary key.

Assumes pos list is sorted by min value and pack min/max ranges don't overlap this is the case for all index and table packs because placement and split algorithms ensure overlaps never exist.

func (*PackHeader) Clear

func (l *PackHeader) Clear()

func (*PackHeader) Count

func (l *PackHeader) Count() int

func (*PackHeader) Get

func (l *PackHeader) Get(i int) PackInfo

func (*PackHeader) GetByKey

func (l *PackHeader) GetByKey(key uint32) PackInfo

func (*PackHeader) GetSorted

func (l *PackHeader) GetSorted(i int) PackInfo

func (*PackHeader) GlobalMinMax

func (l *PackHeader) GlobalMinMax() (uint64, uint64)

func (*PackHeader) HeapSize

func (l *PackHeader) HeapSize() int

func (*PackHeader) IsFull

func (l *PackHeader) IsFull(i int) bool

func (*PackHeader) Len

func (l *PackHeader) Len() int

func (*PackHeader) MinMax

func (l *PackHeader) MinMax(n int) (uint64, uint64)

func (*PackHeader) MinMaxSlices

func (l *PackHeader) MinMaxSlices() ([]uint64, []uint64)

func (*PackHeader) Next

func (l *PackHeader) Next(last int) (pos int, packmin uint64, packmax uint64, nextmin uint64, isFull bool)

Returns pack info for the logical follower pack (in min/max sort order).

func (PackHeader) NextKey

func (l PackHeader) NextKey() uint32

func (*PackHeader) Remove

func (l *PackHeader) Remove(key uint32)

called by storePack when packs are empty (Table only, index packs are never removed)

func (*PackHeader) Sort

func (l *PackHeader) Sort()

func (*PackHeader) TableSize

func (l *PackHeader) TableSize() int

func (PackHeader) Validate

func (l PackHeader) Validate() []error

type PackIndex

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

func CreatePackIndex

func CreatePackIndex(t Table, kind IndexKind, fields FieldList, opts Options) (*PackIndex, error)

func OpenPackIndex

func OpenPackIndex(t Table, kind IndexKind, fields FieldList, opts Options) (*PackIndex, error)

func (*PackIndex) AddTx

func (idx *PackIndex) AddTx(tx *Tx, pkg *Package, srcPos, srcLen int) error

func (*PackIndex) CanMatch

func (idx *PackIndex) CanMatch(cond Condition) bool

This index only supports the following condition types on lookup. - FilterModeEqual - FilterModeIn - FilterModeNotIn

func (*PackIndex) CloseTx

func (idx *PackIndex) CloseTx(tx *Tx) error

saves journal & tombstone on close

func (*PackIndex) Drop

func (idx *PackIndex) Drop() error

func (*PackIndex) Field

func (idx *PackIndex) Field() *Field

func (*PackIndex) FlushTx

func (idx *PackIndex) FlushTx(ctx context.Context, tx *Tx) error

merge journal entries into data partitions, repack, store, and update indexes TODO: replace append+quicksort with reverse mergesort

func (*PackIndex) Kind

func (idx *PackIndex) Kind() IndexKind

func (*PackIndex) LookupTx

func (idx *PackIndex) LookupTx(ctx context.Context, tx *Tx, cond Condition) ([]uint64, error)

[]in -> []oid

func (*PackIndex) Name

func (idx *PackIndex) Name() string

func (*PackIndex) Options

func (idx *PackIndex) Options() Options

func (*PackIndex) PurgeCache

func (idx *PackIndex) PurgeCache()

func (*PackIndex) Reindex

func (idx *PackIndex) Reindex(ctx context.Context, flushEvery int, ch chan<- float64) error

func (*PackIndex) ReindexTx

func (idx *PackIndex) ReindexTx(ctx context.Context, tx *Tx, flushEvery int, ch chan<- float64) error

func (*PackIndex) RemoveTx

func (idx *PackIndex) RemoveTx(tx *Tx, pkg *Package, srcPos, srcLen int) error

func (*PackIndex) Stats

func (idx *PackIndex) Stats() TableStats

type PackIndexEntry

type PackIndexEntry struct {
	Key uint64 `knox:"K,pk"` // hash key, i.e. FNV(value)
	Id  uint64 `knox:"I"`    // OID of table entry
}

type PackIndexList

type PackIndexList []*PackIndex

func (PackIndexList) Find

func (l PackIndexList) Find(name string) *PackIndex

type PackInfo

type PackInfo struct {
	Key      uint32
	NValues  int
	Blocks   BlockInfoList
	Packsize int
	// contains filtered or unexported fields
}

func (*PackInfo) Decode

func (h *PackInfo) Decode(buf *bytes.Buffer) error

func (PackInfo) Dump

func (h PackInfo) Dump(w io.Writer, mode DumpMode, nfields int) error

func (PackInfo) DumpDetail

func (i PackInfo) DumpDetail(w io.Writer) error

func (PackInfo) Encode

func (h PackInfo) Encode(buf *bytes.Buffer) error

func (PackInfo) HeapSize

func (h PackInfo) HeapSize() int

func (PackInfo) IsValid

func (p PackInfo) IsValid() bool

func (PackInfo) KeyBytes

func (p PackInfo) KeyBytes() []byte

func (PackInfo) MarshalBinary

func (h PackInfo) MarshalBinary() ([]byte, error)

func (*PackInfo) UnmarshalBinary

func (h *PackInfo) UnmarshalBinary(data []byte) error

func (*PackInfo) UpdateStats

func (h *PackInfo) UpdateStats(pkg *Package) error

type PackInfoList

type PackInfoList []PackInfo

func (*PackInfoList) Add

func (l *PackInfoList) Add(info PackInfo) (PackInfo, int, bool)

func (PackInfoList) Len

func (l PackInfoList) Len() int

func (PackInfoList) Less

func (l PackInfoList) Less(i, j int) bool

func (PackInfoList) MarshalBinary

func (h PackInfoList) MarshalBinary() ([]byte, error)

func (*PackInfoList) Remove

func (l *PackInfoList) Remove(head PackInfo) (PackInfo, int)

func (*PackInfoList) RemoveKey

func (l *PackInfoList) RemoveKey(key uint32) (PackInfo, int)

func (PackInfoList) Swap

func (l PackInfoList) Swap(i, j int)

func (*PackInfoList) UnmarshalBinary

func (h *PackInfoList) UnmarshalBinary(data []byte) error

type PackTable

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

func CreatePackTable

func CreatePackTable(d *DB, name string, fields FieldList, opts Options) (*PackTable, error)

func OpenPackTable

func OpenPackTable(d *DB, name string, opts ...Options) (*PackTable, error)

func (*PackTable) Close

func (t *PackTable) Close() error

func (*PackTable) Compact

func (t *PackTable) Compact(ctx context.Context) error

merges non-full packs to minimize total pack count, also re-establishes a sequential/gapless pack key order when packs have been deleted

func (*PackTable) Count

func (t *PackTable) Count(ctx context.Context, q Query) (int64, error)

func (*PackTable) CountTx

func (t *PackTable) CountTx(ctx context.Context, tx *Tx, q Query) (int64, error)

func (*PackTable) CreateIndex

func (t *PackTable) CreateIndex(kind IndexKind, fields FieldList, opts Options) error

func (*PackTable) CreateIndexIfNotExists

func (t *PackTable) CreateIndexIfNotExists(kind IndexKind, fields FieldList, opts Options) error

func (*PackTable) DB

func (t *PackTable) DB() *DB

func (*PackTable) Delete

func (t *PackTable) Delete(ctx context.Context, q Query) (int64, error)

func (*PackTable) DeletePks

func (t *PackTable) DeletePks(ctx context.Context, val []uint64) (int64, error)

func (*PackTable) DeletePksTx

func (t *PackTable) DeletePksTx(ctx context.Context, tx *Tx, val []uint64) (int64, error)

func (*PackTable) Drop

func (t *PackTable) Drop() error

func (*PackTable) DropIndex

func (t *PackTable) DropIndex(fields FieldList) error

func (*PackTable) DumpIndexPack

func (t *PackTable) DumpIndexPack(w io.Writer, i, p int, mode DumpMode) error

func (*PackTable) DumpIndexPackInfo

func (t *PackTable) DumpIndexPackInfo(w io.Writer, idx int, mode DumpMode, sorted bool) error

func (*PackTable) DumpJournal

func (t *PackTable) DumpJournal(w io.Writer, mode DumpMode) error

func (*PackTable) DumpPack

func (t *PackTable) DumpPack(w io.Writer, i int, mode DumpMode) error

func (*PackTable) DumpPackBlocks

func (t *PackTable) DumpPackBlocks(w io.Writer, mode DumpMode) error

func (*PackTable) DumpPackInfo

func (t *PackTable) DumpPackInfo(w io.Writer, mode DumpMode, sorted bool) error

func (*PackTable) DumpPackInfoDetail

func (t *PackTable) DumpPackInfoDetail(w io.Writer, mode DumpMode, sorted bool) error

func (*PackTable) DumpType

func (t *PackTable) DumpType(w io.Writer) error

func (*PackTable) Engine

func (t *PackTable) Engine() TableEngine

func (*PackTable) Fields

func (t *PackTable) Fields() FieldList

func (*PackTable) Flush

func (t *PackTable) Flush(ctx context.Context) error

func (*PackTable) FlushJournal

func (t *PackTable) FlushJournal(ctx context.Context) error

func (*PackTable) Indexes

func (t *PackTable) Indexes() PackIndexList

func (*PackTable) Insert

func (t *PackTable) Insert(ctx context.Context, val any) error

func (*PackTable) InsertResult

func (t *PackTable) InsertResult(ctx context.Context, res *Result) error

func (*PackTable) InsertRow

func (t *PackTable) InsertRow(ctx context.Context, row Row) error

func (*PackTable) InsertTx

func (t *PackTable) InsertTx(ctx context.Context, tx *Tx, val any) error

unsafe when used concurrently, need to obtain lock _before_ starting bolt tx

func (*PackTable) IsClosed

func (t *PackTable) IsClosed() bool

func (*PackTable) Lock

func (t *PackTable) Lock()

func (*PackTable) LookupPks

func (t *PackTable) LookupPks(ctx context.Context, ids []uint64) (*Result, error)

func (*PackTable) LookupPksTx

func (t *PackTable) LookupPksTx(ctx context.Context, tx *Tx, ids []uint64) (*Result, error)

unsafe when called concurrently! lock table _before_ starting bolt tx!

func (*PackTable) Name

func (t *PackTable) Name() string

func (*PackTable) NextSequence

func (t *PackTable) NextSequence() uint64

func (*PackTable) Options

func (t *PackTable) Options() Options

func (*PackTable) PurgeCache

func (t *PackTable) PurgeCache()

func (*PackTable) Query

func (t *PackTable) Query(ctx context.Context, q Query) (*Result, error)

func (*PackTable) QueryIndexesTx

func (t *PackTable) QueryIndexesTx(ctx context.Context, tx *Tx, node *ConditionTreeNode) (int, error)

func (*PackTable) QueryTx

func (t *PackTable) QueryTx(ctx context.Context, tx *Tx, q Query) (*Result, error)

NOTE: not concurrency safe lock table _before_ starting bolt tx!

func (*PackTable) QueryTxDesc

func (t *PackTable) QueryTxDesc(ctx context.Context, tx *Tx, q Query) (*Result, error)

DESCENDING pk order algorithm

func (*PackTable) Stats

func (t *PackTable) Stats() []TableStats

func (*PackTable) Stream

func (t *PackTable) Stream(ctx context.Context, q Query, fn func(r Row) error) error

func (*PackTable) StreamPks

func (t *PackTable) StreamPks(ctx context.Context, ids []uint64, fn func(r Row) error) error

func (*PackTable) StreamPksTx

func (t *PackTable) StreamPksTx(ctx context.Context, tx *Tx, ids []uint64, fn func(r Row) error) error

func (*PackTable) StreamTx

func (t *PackTable) StreamTx(ctx context.Context, tx *Tx, q Query, fn func(r Row) error) error

Similar to QueryTx but returns each match via callback function to allow stream processing at low memory overheads.

func (*PackTable) StreamTxDesc

func (t *PackTable) StreamTxDesc(ctx context.Context, tx *Tx, q Query, fn func(r Row) error) error

DESCENDING order stream

func (*PackTable) Sync

func (t *PackTable) Sync(ctx context.Context) error

func (*PackTable) Unlock

func (t *PackTable) Unlock()

func (*PackTable) Update

func (t *PackTable) Update(ctx context.Context, val any) error

func (*PackTable) UpdateTx

func (t *PackTable) UpdateTx(ctx context.Context, tx *Tx, val any) error

func (*PackTable) ValidateIndexPackHeader

func (t *PackTable) ValidateIndexPackHeader(w io.Writer) error

func (*PackTable) ValidatePackHeader

func (t *PackTable) ValidatePackHeader(w io.Writer) error

func (*PackTable) WalkPacks

func (t *PackTable) WalkPacks(fn func(*Package) error) error

func (*PackTable) WalkPacksRange

func (t *PackTable) WalkPacksRange(start, end int, fn func(*Package) error) error

type Package

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

func NewPackage

func NewPackage(sz int, pool *sync.Pool) *Package

func (*Package) AppendFrom

func (p *Package) AppendFrom(srcPack *Package, srcPos, srcLen int) error

func (*Package) Block

func (p *Package) Block(index int) (*block.Block, error)

Block allows raw access to the underlying block for a field. Use this for implementing efficient matching algorithms that can work with optimized data vectors used at the block layer.

func (*Package) Blocks

func (p *Package) Blocks() []*block.Block

func (*Package) BoolAt

func (p *Package) BoolAt(index, pos int) (bool, error)

func (*Package) BytesAt

func (p *Package) BytesAt(index, pos int) ([]byte, error)

func (*Package) CanGrow

func (p *Package) CanGrow(n int) bool

func (*Package) Cap

func (p *Package) Cap() int

func (*Package) Clear

func (p *Package) Clear()

func (*Package) Clone

func (p *Package) Clone(capacity int) (*Package, error)

func (*Package) Cols

func (p *Package) Cols() int

func (*Package) Column

func (p *Package) Column(index int) (interface{}, error)

Column returns a typed slice containing materialized values for the requested field index. This function has higher cost than direct block access because optimized representation of data vectors like timestamps, bitsets and decimals are unpacked into a temporary slice and type-cast.

func (*Package) Contains

func (p *Package) Contains(fields FieldList) bool

func (*Package) DecRef

func (p *Package) DecRef() int64

func (*Package) Decimal128At

func (p *Package) Decimal128At(index, pos int) (Decimal128, error)

func (*Package) Decimal256At

func (p *Package) Decimal256At(index, pos int) (Decimal256, error)

func (*Package) Decimal32At

func (p *Package) Decimal32At(index, pos int) (Decimal32, error)

func (*Package) Decimal64At

func (p *Package) Decimal64At(index, pos int) (Decimal64, error)

func (*Package) Delete

func (p *Package) Delete(pos, n int) error

func (*Package) DumpBlocks

func (p *Package) DumpBlocks(w io.Writer, mode DumpMode, lineNo int) (int, error)

func (*Package) DumpData

func (p *Package) DumpData(w io.Writer, mode DumpMode, aliases []string) error

func (*Package) DumpType

func (p *Package) DumpType(w io.Writer) error

func (*Package) FieldAt

func (p *Package) FieldAt(index, pos int) (interface{}, error)

func (*Package) FieldById

func (p *Package) FieldById(idx int) *Field

func (*Package) FieldByName

func (p *Package) FieldByName(name string) *Field

func (*Package) FieldIndex

func (p *Package) FieldIndex(name string) int

func (*Package) Fields

func (p *Package) Fields() FieldList

func (*Package) Float32At

func (p *Package) Float32At(index, pos int) (float32, error)

func (*Package) Float64At

func (p *Package) Float64At(index, pos int) (float64, error)

func (*Package) Grow

func (p *Package) Grow(n int) error

append n empty rows with default/zero values

func (*Package) HeapSize

func (p *Package) HeapSize() int

func (*Package) IncRef

func (p *Package) IncRef() int64

func (*Package) Info

func (p *Package) Info() PackInfo

func (*Package) InitFields

func (p *Package) InitFields(fields FieldList, tinfo *typeInfo) error

Init from field list when Go type is unavailable

func (*Package) InitFieldsEmpty

func (p *Package) InitFieldsEmpty(fields FieldList, tinfo *typeInfo) error

Init from field list when Go type is unavailable

func (*Package) InitFieldsFrom

func (p *Package) InitFieldsFrom(src *Package) error

func (*Package) InitFieldsFromEmpty

func (p *Package) InitFieldsFromEmpty(src *Package) error

func (*Package) InitResultFields

func (p *Package) InitResultFields(fields FieldList, tinfo *typeInfo) error

may be called from Join, no pk required

func (*Package) InitType

func (p *Package) InitType(proto interface{}) error

Go type is required to write using reflect inside Push(),

func (*Package) InsertFrom

func (p *Package) InsertFrom(srcPack *Package, dstPos, srcPos, srcLen int) error

func (*Package) Int128At

func (p *Package) Int128At(index, pos int) (vec.Int128, error)

func (*Package) Int16At

func (p *Package) Int16At(index, pos int) (int16, error)

func (*Package) Int256At

func (p *Package) Int256At(index, pos int) (vec.Int256, error)

func (*Package) Int32At

func (p *Package) Int32At(index, pos int) (int32, error)

func (*Package) Int64At

func (p *Package) Int64At(index, pos int) (int64, error)

func (*Package) Int8At

func (p *Package) Int8At(index, pos int) (int8, error)

func (*Package) IsDirty

func (p *Package) IsDirty() bool

func (*Package) IsFull

func (p *Package) IsFull() bool

func (Package) IsJournal

func (p Package) IsJournal() bool

func (Package) IsResult

func (p Package) IsResult() bool

func (Package) IsTomb

func (p Package) IsTomb() bool

func (*Package) IsZeroAt

func (p *Package) IsZeroAt(index, pos int, zeroIsNull bool) bool

func (*Package) Key

func (p *Package) Key() []byte

func (*Package) Len

func (p *Package) Len() int

func (*Package) MarshalBinary

func (p *Package) MarshalBinary() ([]byte, error)

func (*Package) Materialize

func (p *Package) Materialize()

func (*Package) MergeCols

func (dst *Package) MergeCols(src *Package) error

func (*Package) Optimize

func (p *Package) Optimize()

func (*Package) PkColumn

func (p *Package) PkColumn() []uint64

func (*Package) PkField

func (p *Package) PkField() *Field

func (*Package) PkIndex

func (p *Package) PkIndex(id uint64, last int) (int, int)

Searches id in primary key column and return index or -1 when not found This function is only safe to use when packs are sorted!

func (*Package) PkIndexUnsorted

func (p *Package) PkIndexUnsorted(id uint64, last int) int

Searches id in primary key column and return index or -1 when not found, use this function when pack is unsorted as when updates/inserts are out of order.

func (*Package) PkSort

func (p *Package) PkSort() error

func (*Package) PopulateFields

func (p *Package) PopulateFields(fields FieldList) *Package

func (*Package) Push

func (p *Package) Push(v interface{}) error

Push appends a new row to all columns. Requires a type that strictly defines all columns in this pack! Column mapping uses the default struct tag `knox`.

func (*Package) RangeAt

func (p *Package) RangeAt(index, start, end int) (interface{}, error)

func (*Package) ReadAtWithInfo

func (p *Package) ReadAtWithInfo(pos int, v interface{}, tinfo *typeInfo) error

ReadAtWithInfo reads a row at offset pos and unmarshals values into an arbitrary type described by tinfo. This method has better performance than ReadAt when calls are very frequent, e.g. walking all rows in a pack. Will set struct fields based on name and alias as defined by struct tags `pack` and `json`.

func (*Package) Release

func (p *Package) Release()

func (*Package) ReplaceAt

func (p *Package) ReplaceAt(pos int, v interface{}) error

ReplaceAt replaces a row at offset pos across all columns. Requires a type that strictly defines all columns in this pack! Column mapping uses the default struct tag `pack`, hence the fields name only (not the fields alias).

func (*Package) ReplaceFrom

func (p *Package) ReplaceFrom(srcPack *Package, dstPos, srcPos, srcLen int) error

ReplaceFrom replaces at most srcLen rows from the current package starting at offset dstPos with rows from package src starting at pos srcPos. Both packages must have same block order.

func (*Package) ResetType

func (p *Package) ResetType()

func (*Package) RowAt

func (p *Package) RowAt(pos int) ([]interface{}, error)

func (*Package) SetFieldAt

func (p *Package) SetFieldAt(index, pos int, v interface{}) error

func (*Package) SetKey

func (p *Package) SetKey(key []byte)

func (*Package) StringAt

func (p *Package) StringAt(index, pos int) (string, error)

func (*Package) TimeAt

func (p *Package) TimeAt(index, pos int) (time.Time, error)

func (*Package) Uint16At

func (p *Package) Uint16At(index, pos int) (uint16, error)

func (*Package) Uint32At

func (p *Package) Uint32At(index, pos int) (uint32, error)

func (*Package) Uint64At

func (p *Package) Uint64At(index, pos int) (uint64, error)

func (*Package) Uint8At

func (p *Package) Uint8At(index, pos int) (uint8, error)

func (*Package) UnmarshalBinary

func (p *Package) UnmarshalBinary(data []byte) error

func (*Package) UpdateAliasesFrom

func (p *Package) UpdateAliasesFrom(fields FieldList) *Package

clones field list and sets new aliase names

func (*Package) Validate

func (p *Package) Validate() error

func (*Package) WithCap

func (p *Package) WithCap(c int) *Package

func (*Package) WithKey

func (p *Package) WithKey(k uint32) *Package

type PackageSorter

type PackageSorter struct {
	*Package
	// contains filtered or unexported fields
}

func NewPackageSorter

func NewPackageSorter(p *Package, col int) (*PackageSorter, error)

func (*PackageSorter) Len

func (s *PackageSorter) Len() int

func (*PackageSorter) Less

func (s *PackageSorter) Less(i, j int) bool

func (*PackageSorter) Sort

func (s *PackageSorter) Sort() bool

Sorts the package by defined column and returns if the package was changed, i.e. returns false if the package was sorted before

func (*PackageSorter) Swap

func (s *PackageSorter) Swap(i, j int)

type Query

type Query struct {
	Name       string           // optional, used for query stats
	Fields     []string         // SELECT ...
	Conditions UnboundCondition // WHERE ... AND / OR tree
	Order      OrderType        // ASC|DESC
	Limit      int              // LIMIT ...
	Offset     int              // OFFSET ...
	NoCache    bool             // explicitly disable pack caching for this query
	NoIndex    bool             // explicitly disable index query (use for many known duplicates)
	Debugf     logpkg.LogfFn
	// contains filtered or unexported fields
}

func NewQuery

func NewQuery(name string) Query

func (Query) And

func (q Query) And(field string, mode FilterMode, value any) Query

func (Query) AndCondition

func (q Query) AndCondition(conds ...UnboundCondition) Query

func (Query) AndEqual

func (q Query) AndEqual(field string, value any) Query

func (Query) AndGt

func (q Query) AndGt(field string, value any) Query

func (Query) AndGte

func (q Query) AndGte(field string, value any) Query

func (Query) AndIn

func (q Query) AndIn(field string, value any) Query

func (Query) AndLt

func (q Query) AndLt(field string, value any) Query

func (Query) AndLte

func (q Query) AndLte(field string, value any) Query

func (Query) AndNotEqual

func (q Query) AndNotEqual(field string, value any) Query

func (Query) AndNotIn

func (q Query) AndNotIn(field string, value any) Query

func (Query) AndRange

func (q Query) AndRange(field string, from, to any) Query

func (Query) AndRegexp

func (q Query) AndRegexp(field string, value any) Query

func (*Query) Close

func (q *Query) Close()

func (*Query) Compile

func (q *Query) Compile() error

func (Query) Count

func (q Query) Count(ctx context.Context) (int64, error)

func (Query) Delete

func (q Query) Delete(ctx context.Context) (int64, error)

func (Query) Dump

func (q Query) Dump() string

func (Query) Execute

func (q Query) Execute(ctx context.Context, val any) error

func (Query) IsBound

func (q Query) IsBound() bool

func (Query) IsEmptyMatch

func (q Query) IsEmptyMatch() bool

func (Query) Or

func (q Query) Or(field string, mode FilterMode, value any) Query

func (Query) OrCondition

func (q Query) OrCondition(conds ...UnboundCondition) Query

func (Query) PrintTiming

func (q Query) PrintTiming() string

func (*Query) QueryIndexes

func (q *Query) QueryIndexes(ctx context.Context, tx *Tx) error

INDEX QUERY: use index lookup for indexed fields - fetch pk lists for every indexed field - when resolved, replace source condition with new FilterModeIn condition

func (Query) Run

func (q Query) Run(ctx context.Context) (*Result, error)

func (Query) Runtime

func (q Query) Runtime() time.Duration

func (Query) Stream

func (q Query) Stream(ctx context.Context, fn func(r Row) error) error

func (Query) Table

func (q Query) Table() Table

func (*Query) Tick

func (q *Query) Tick() time.Duration

func (*Query) TickNow

func (q *Query) TickNow() (time.Duration, time.Time)

func (Query) WithAsc

func (q Query) WithAsc() Query

func (Query) WithCache

func (q Query) WithCache(enable bool) Query

func (Query) WithColumns

func (q Query) WithColumns(names ...string) Query

func (Query) WithDebug

func (q Query) WithDebug() Query

func (Query) WithDesc

func (q Query) WithDesc() Query

func (Query) WithFields

func (q Query) WithFields(names ...string) Query

func (Query) WithIndex

func (q Query) WithIndex(enable bool) Query

func (Query) WithLimit

func (q Query) WithLimit(l int) Query

func (Query) WithOffset

func (q Query) WithOffset(o int) Query

func (Query) WithOrder

func (q Query) WithOrder(o OrderType) Query

func (Query) WithStats

func (q Query) WithStats() Query

func (Query) WithStatsAfter

func (q Query) WithStatsAfter(d time.Duration) Query

func (Query) WithTable

func (q Query) WithTable(table Table) Query

func (Query) WithoutCache

func (q Query) WithoutCache() Query

func (Query) WithoutIndex

func (q Query) WithoutIndex() Query

func (Query) WithoutStats

func (q Query) WithoutStats() Query

type QueryStats

type QueryStats struct {
	CompileTime    time.Duration `json:"compile_time"`
	AnalyzeTime    time.Duration `json:"analyze_time"`
	JournalTime    time.Duration `json:"journal_time"`
	IndexTime      time.Duration `json:"index_time"`
	ScanTime       time.Duration `json:"scan_time"`
	TotalTime      time.Duration `json:"total_time"`
	PacksScheduled int           `json:"packs_scheduled"`
	PacksScanned   int           `json:"packs_scanned"`
	RowsScanned    int           `json:"rows_scanned"`
	RowsMatched    int           `json:"rows_matched"`
	IndexLookups   int           `json:"index_lookups"`
}

type Result

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

TODO: migrate to interface and implement PackResult + KeyValueResult

func (*Result) Close

func (r *Result) Close()

func (*Result) Cols

func (r *Result) Cols() int

func (*Result) Column

func (r *Result) Column(colname string) (interface{}, error)

TODO: extend to value type results

func (*Result) Decode

func (r *Result) Decode(val interface{}) error

func (*Result) DecodeAt

func (r *Result) DecodeAt(n int, val interface{}) error

func (*Result) DecodeRange

func (r *Result) DecodeRange(start, end int, proto interface{}) (interface{}, error)

func (Result) Dump

func (r Result) Dump() string

func (*Result) Fields

func (r *Result) Fields() FieldList

func (*Result) ForEach

func (r *Result) ForEach(proto interface{}, fn func(i int, val interface{}) error) error

func (*Result) IsValid

func (r *Result) IsValid() bool

func (*Result) PkColumn

func (r *Result) PkColumn() []uint64

TODO: extend to value type results

func (*Result) Record

func (r *Result) Record(n int) []byte

func (*Result) Row

func (r *Result) Row(n int) Row

func (*Result) Rows

func (r *Result) Rows() int

func (*Result) SortByField

func (r *Result) SortByField(name string) error

TODO: extend to value type results

func (*Result) Walk

func (r *Result) Walk(fn func(r Row) error) error

type ReverseIterator

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

func NewReverseIterator

func NewReverseIterator(q *Query) *ReverseIterator

func (*ReverseIterator) Close

func (it *ReverseIterator) Close()

func (*ReverseIterator) Next

func (it *ReverseIterator) Next(tx *Tx) (*Package, []uint32, error)

type Row

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

func (Row) Bool

func (r Row) Bool(index int) (bool, error)

func (Row) Bytes

func (r Row) Bytes(index int) ([]byte, error)

func (Row) Decimal128

func (r Row) Decimal128(index int) (decimal.Decimal128, error)

func (Row) Decimal256

func (r Row) Decimal256(index int) (decimal.Decimal256, error)

func (Row) Decimal32

func (r Row) Decimal32(index int) (decimal.Decimal32, error)

func (Row) Decimal64

func (r Row) Decimal64(index int) (decimal.Decimal64, error)

func (Row) Decode

func (r Row) Decode(val interface{}) error

func (Row) Field

func (r Row) Field(name string) (interface{}, error)

func (Row) Float32

func (r Row) Float32(index int) (float32, error)

func (Row) Float64

func (r Row) Float64(index int) (float64, error)

func (Row) Index

func (r Row) Index(i int) (interface{}, error)

TODO: extend to value type results

func (Row) Int128

func (r Row) Int128(index int) (vec.Int128, error)

func (Row) Int16

func (r Row) Int16(index int) (int16, error)

func (Row) Int256

func (r Row) Int256(index int) (vec.Int256, error)

func (Row) Int32

func (r Row) Int32(index int) (int32, error)

func (Row) Int64

func (r Row) Int64(index int) (int64, error)

func (Row) Int8

func (r Row) Int8(index int) (int8, error)

func (Row) N

func (r Row) N() int

func (Row) Result

func (r Row) Result() *Result

func (Row) String

func (r Row) String(index int) (string, error)

func (Row) Time

func (r Row) Time(index int) (time.Time, error)

func (Row) Uint16

func (r Row) Uint16(index int) (uint16, error)

func (Row) Uint32

func (r Row) Uint32(index int) (uint32, error)

func (Row) Uint64

func (r Row) Uint64(index int) (uint64, error)

func (Row) Uint8

func (r Row) Uint8(index int) (uint8, error)

type Store

type Store interface {
	Name() string
	Engine() string
	DB() *DB
	Options() Options
	IsClosed() bool
	Stats() []TableStats
	PurgeCache()
	Close() error
	Drop() error

	Get(key []byte) ([]byte, error)
	GetTx(tx *Tx, key []byte) []byte
	Get64(key uint64) ([]byte, error)
	GetValue64(key uint64, val any) error
	Put(key, val []byte) error
	PutTx(tx *Tx, key, val []byte) ([]byte, error)
	Put64(key uint64, val []byte) error
	PutValue64(key uint64, val any) error
	Del(key []byte) error
	DelTx(tx *Tx, key []byte) ([]byte, error)
	Del64(key uint64) error
	DeleteValue64(key uint64) error
	PrefixRange(prefix []byte, fn func(k, v []byte) error) error
	Range(from, to []byte, fn func(k, v []byte) error) error
}

type Table

type Table interface {
	Name() string
	Engine() TableEngine
	DB() *DB
	Options() Options
	IsClosed() bool
	Fields() FieldList
	Stats() []TableStats
	PurgeCache()
	Close() error
	Drop() error
	Sync(context.Context) error
	Compact(context.Context) error

	Insert(context.Context, any) error
	Update(context.Context, any) error
	Query(context.Context, Query) (*Result, error)
	Stream(context.Context, Query, func(Row) error) error
	Count(context.Context, Query) (int64, error)
	Delete(context.Context, Query) (int64, error)
	LookupPks(context.Context, []uint64) (*Result, error)
	StreamPks(context.Context, []uint64, func(Row) error) error
	DeletePks(context.Context, []uint64) (int64, error)

	CreateIndex(IndexKind, FieldList, Options) error
	CreateIndexIfNotExists(IndexKind, FieldList, Options) error
	DropIndex(FieldList) error
	QueryIndexesTx(context.Context, *Tx, *ConditionTreeNode) (int, error)
}

type TableEngine

type TableEngine string

type TableMeta

type TableMeta struct {
	Sequence uint64 `json:"sequence"`
	Rows     int64  `json:"rows"`
	// contains filtered or unexported fields
}

type TableStats

type TableStats struct {
	// global statistics
	TableName         string `json:"table_name,omitempty"`
	IndexName         string `json:"index_name,omitempty"`
	LastFlushTime     int64  `json:"last_flush_time"`
	LastFlushDuration int64  `json:"last_flush_duration"`

	// tuple statistics
	TupleCount     int64 `json:"tuples_count"`
	InsertedTuples int64 `json:"tuples_inserted"`
	UpdatedTuples  int64 `json:"tuples_updated"`
	DeletedTuples  int64 `json:"tuples_deleted"`
	FlushedTuples  int64 `json:"tuples_flushed"`
	QueriedTuples  int64 `json:"tuples_queried"`
	StreamedTuples int64 `json:"tuples_streamed"`

	// call statistics
	InsertCalls int64 `json:"calls_insert"`
	UpdateCalls int64 `json:"calls_update"`
	DeleteCalls int64 `json:"calls_delete"`
	FlushCalls  int64 `json:"calls_flush"`
	QueryCalls  int64 `json:"calls_query"`
	StreamCalls int64 `json:"calls_stream"`

	// metadata statistics
	MetaBytesRead    int64 `json:"meta_bytes_read"`
	MetaBytesWritten int64 `json:"meta_bytes_written"`
	MetaSize         int64 `json:"meta_size"`

	// journal statistics
	JournalSize            int64 `json:"journal_size"`
	JournalDiskSize        int64 `json:"journal_disk_size"`
	JournalTuplesCount     int64 `json:"journal_tuples_count"`
	JournalTuplesThreshold int64 `json:"journal_tuples_threshold"`
	JournalTuplesCapacity  int64 `json:"journal_tuples_capacity"`
	JournalPacksStored     int64 `json:"journal_packs_stored"`
	JournalTuplesFlushed   int64 `json:"journal_tuples_flushed"`
	JournalBytesWritten    int64 `json:"journal_bytes_written"`

	// tombstone statistics
	TombstoneSize            int64 `json:"tombstone_size"`
	TombstoneDiskSize        int64 `json:"tombstone_disk_size"`
	TombstoneTuplesCount     int64 `json:"tomb_tuples_count"`
	TombstoneTuplesThreshold int64 `json:"tomb_tuples_threshold"`
	TombstoneTuplesCapacity  int64 `json:"tomb_tuples_capacity"`
	TombstonePacksStored     int64 `json:"tomb_packs_stored"`
	TombstoneTuplesFlushed   int64 `json:"tomb_tuples_flushed"`
	TombstoneBytesWritten    int64 `json:"tomb_bytes_written"`

	// pack statistics
	PacksCount    int64 `json:"packs_count"`
	PacksAlloc    int64 `json:"packs_alloc"`
	PacksRecycled int64 `json:"packs_recycled"`
	PacksLoaded   int64 `json:"packs_loaded"`
	PacksStored   int64 `json:"packs_stored"`

	// I/O statistics
	BytesRead    int64 `json:"bytes_read"`
	BytesWritten int64 `json:"bytes_written"`
	TotalSize    int64 `json:"total_size"`

	// pack cache statistics
	CacheSize      int64 `json:"cache_size"`
	CacheCount     int64 `json:"cache_count"`
	CacheCapacity  int64 `json:"cache_capacity"`
	CacheHits      int64 `json:"cache_hits"`
	CacheMisses    int64 `json:"cache_misses"`
	CacheInserts   int64 `json:"cache_inserts"`
	CacheEvictions int64 `json:"cache_evictions"`
}

func (*TableStats) Clone

func (s *TableStats) Clone() (c TableStats)

type Tombstone

type Tombstone struct {
	Id uint64 `knox:"I,pk,snappy"`
}

type Tx

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

func (*Tx) Bucket

func (t *Tx) Bucket(key []byte) store.Bucket

func (*Tx) Commit

func (t *Tx) Commit() error

func (*Tx) CommitAndContinue

func (t *Tx) CommitAndContinue() error

func (*Tx) Pending

func (t *Tx) Pending() int

func (*Tx) Rollback

func (t *Tx) Rollback() error

func (*Tx) Root

func (t *Tx) Root() store.Bucket

type UnboundCondition

type UnboundCondition struct {
	Name     string
	Mode     FilterMode  // eq|ne|gt|gte|lt|lte|in|nin|re
	Raw      string      // string value when parsed from a query string
	Value    interface{} // typed value
	From     interface{} // typed value for range queries
	To       interface{} // typed value for range queries
	OrKind   bool
	Children []UnboundCondition
}

condition that is not bound to a table field yet

func And

func And(conds ...UnboundCondition) UnboundCondition

func Equal

func Equal(col string, val interface{}) UnboundCondition

func Gt

func Gt(col string, value interface{}) UnboundCondition

func Gte

func Gte(col string, value interface{}) UnboundCondition

func In

func In(col string, value interface{}) UnboundCondition

func Lt

func Lt(col string, value interface{}) UnboundCondition

func Lte

func Lte(col string, value interface{}) UnboundCondition

func NotEqual

func NotEqual(col string, val interface{}) UnboundCondition

func NotIn

func NotIn(col string, value interface{}) UnboundCondition

func Or

func ParseCondition

func ParseCondition(key, val string, fields FieldList) (UnboundCondition, error)

parse conditions from query string col_name.{gt|gte|lt|lte|ne|in|nin|rg|re}=value

func Range

func Range(col string, from, to interface{}) UnboundCondition

func Regexp

func Regexp(col string, value interface{}) UnboundCondition

func (*UnboundCondition) Add

func (*UnboundCondition) And

func (u *UnboundCondition) And(col string, mode FilterMode, value interface{})

func (*UnboundCondition) AndRange

func (u *UnboundCondition) AndRange(col string, from, to interface{})

func (UnboundCondition) Bind

func (*UnboundCondition) Clear

func (u *UnboundCondition) Clear()

func (UnboundCondition) Dump

func (n UnboundCondition) Dump() string

func (UnboundCondition) Empty

func (u UnboundCondition) Empty() bool

func (UnboundCondition) Leaf

func (u UnboundCondition) Leaf() bool

func (*UnboundCondition) Or

func (u *UnboundCondition) Or(col string, mode FilterMode, value interface{})

func (*UnboundCondition) OrRange

func (u *UnboundCondition) OrRange(col string, from, to interface{})

func (UnboundCondition) Rename

func (u UnboundCondition) Rename(name string) UnboundCondition

func (UnboundCondition) String

func (u UnboundCondition) String() string

type Value

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

func NewValue

func NewValue(fields FieldList) *Value

func (Value) Get

func (v Value) Get(i int) (val any, ok bool)

func (Value) IsFixed

func (v Value) IsFixed() bool

func (Value) IsValid

func (v Value) IsValid() bool

func (*Value) Reset

func (v *Value) Reset(buf []byte) *Value

type Wal

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

func OpenWal

func OpenWal(path, name string) (*Wal, error)

func (*Wal) Close

func (w *Wal) Close()

func (*Wal) IsOpen

func (w *Wal) IsOpen() bool

func (*Wal) Reset

func (w *Wal) Reset() error

func (*Wal) Sync

func (w *Wal) Sync() error

func (*Wal) Write

func (w *Wal) Write(rec WalRecordType, pk uint64, val any) error

func (*Wal) WriteMulti

func (w *Wal) WriteMulti(rec WalRecordType, pks []uint64, vals any) error

func (*Wal) WritePack

func (w *Wal) WritePack(rec WalRecordType, pkg *Package, pos, n int) error

type WalRecordType

type WalRecordType string
var (
	WalRecordTypeInsert WalRecordType = "I "
	WalRecordTypeUpdate WalRecordType = "U "
	WalRecordTypeDelete WalRecordType = "D "
)

Jump to

Keyboard shortcuts

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