db

package
v0.0.0-...-92d0331 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package db implements an in‐memory embedded database for Apache Arrow records.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompressionConfig

type CompressionConfig struct {
	Enabled bool
	Codec   compress.Codec // e.g. arrow.CompressionLZ4Frame
	Level   int
}

CompressionConfig controls optional compression of Arrow records.

type DB

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

DB is an in-memory, embedded database for Arrow records with advanced query, ingestion, and recovery capabilities.

func NewDB

func NewDB(retention time.Duration, asyncQueueSize, batchSize int, batchTimeout time.Duration) *DB

NewDB initializes a new DB instance.

func (*DB) AsyncIngest

func (db *DB) AsyncIngest(record arrow.Record)

AsyncIngest enqueues a record for asynchronous ingestion.

func (*DB) Backup

func (db *DB) Backup(path string) error

Backup writes a backup to the specified path.

func (*DB) Close

func (db *DB) Close()

Close shuts down the DB, releases all records, and stops background workers.

func (*DB) Export

func (db *DB) Export(format string, writer io.Writer) error

Export writes the database state in the specified format.

func (*DB) GetRecords

func (db *DB) GetRecords() []arrow.Record

GetRecords returns all stored records.

func (*DB) GetRecordsSince

func (db *DB) GetRecordsSince(since time.Time) []arrow.Record

GetRecordsSince returns records with a timestamp after the specified time

func (*DB) GetSchema

func (db *DB) GetSchema() *arrow.Schema

GetSchema returns the database schema.

func (*DB) Import

func (db *DB) Import(format string, reader io.Reader) error

Import reads data from the given reader and loads it into the database.

func (*DB) PruneOldRecords

func (db *DB) PruneOldRecords()

PruneOldRecords removes records older than the retention period.

func (*DB) Query

func (db *DB) Query(plan *Query) ([]arrow.Record, error)

Query executes the plan and returns the results as []arrow.Record

func (*DB) QueryByUser

func (db *DB) QueryByUser(userID int64) []arrow.Record

QueryByUser returns all records for a given user.

func (*DB) Restore

func (db *DB) Restore(path string) error

Restore loads a backup from the specified path.

func (*DB) WaitForBatch

func (db *DB) WaitForBatch()

type DeadLetterQueue

type DeadLetterQueue interface {
	Write(arrow.Record) error
}

type Index

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

Index is a bitmap-based index for efficient value lookups

func NewIndex

func NewIndex() *Index

NewIndex creates a new bitmap index

func (*Index) Add

func (idx *Index) Add(value interface{}, position uint32)

Add indexes a value at the given record position

func (*Index) Cardinality

func (idx *Index) Cardinality() int

Cardinality returns the number of unique values in the index

func (*Index) Clear

func (idx *Index) Clear()

Clear removes all entries from the index

func (*Index) Get

func (idx *Index) Get(value interface{}) *roaring.Bitmap

Get returns the bitmap of record positions for a value

func (*Index) Remove

func (idx *Index) Remove(value interface{}, position uint32)

Remove deletes a value's position from the index

type JoinCondition

type JoinCondition struct {
	LeftColumn  string
	RightColumn string
}

JoinCondition represents a join between two columns.

type Migration

type Migration struct {
	Version int
	Apply   func(oldSchema *arrow.Schema) *arrow.Schema
}

Migration defines a function to evolve a schema.

type Partition

type Partition struct {
	Key      string
	Records  []arrow.Record
	Metadata map[string]interface{}
}

Partition holds a subset of records.

type PartitionStrategy

type PartitionStrategy interface {
	Partition(record arrow.Record) string
	Merge(partitions []*Partition) arrow.Record
}

PartitionStrategy defines how to partition and later merge records.

type Query

type Query struct {
	SelectColumns []string
	Aggregates    map[string]string // e.g. "purchase_amount" -> "SUM"
	GroupBy       []string
	Window        time.Duration

	// Additional query capabilities:
	Joins       []JoinCondition
	Subqueries  []*Query
	Unions      []*Query
	WindowFuncs []WindowFunction
}

Query represents a structured query against the database.

type QueryOptimizer

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

QueryOptimizer caches query results and collects statistics.

type RecoveryManager

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

RecoveryManager handles snapshots and write-ahead logging.

type SchemaManager

type SchemaManager struct {
	Versions       map[int]*arrow.Schema
	Migrations     []Migration
	CurrentVersion int
}

SchemaManager maintains multiple schema versions and migrations.

type Snapshot

type Snapshot struct {
	Timestamp time.Time
	Records   []arrow.Record
}

Snapshot represents a point-in-time backup.

type Statistics

type Statistics struct {
	Cardinality map[string]int64
	Min         map[string]interface{}
	Max         map[string]interface{}
}

Statistics holds cardinality, min, and max information for columns.

type Storage

type Storage interface {
	Export(format string, writer io.Writer) error
	Import(format string, reader io.Reader) error
	Backup(path string) error
	Restore(path string) error
}

Storage defines import/export and backup/restore methods.

type Task

type Task func()

Task defines work to be executed.

type WALJournal

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

WALJournal is a simple write-ahead log.

type WindowFunction

type WindowFunction struct {
	Function string
	Column   string
	Window   time.Duration
}

WindowFunction represents a windowed aggregation.

type Worker

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

Worker executes tasks from the WorkerPool.

type WorkerPool

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

WorkerPool manages a fixed set of workers.

func NewWorkerPool

func NewWorkerPool(numWorkers int) *WorkerPool

NewWorkerPool creates a new pool with the given number of workers.

func (*WorkerPool) Shutdown

func (wp *WorkerPool) Shutdown()

Shutdown stops the worker pool.

func (*WorkerPool) Submit

func (wp *WorkerPool) Submit(task Task)

Submit schedules a task for execution.

Jump to

Keyboard shortcuts

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