lake

package module
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

LakeDB

LakeDB is a simple realtime analytics engine running on s3 using parquet.


Ingestion


[!TIP] It is absolutely permitted and often required to commit only a few ingested entries (e.g. in serverless scenarios or to make the data available quickly). To avoid "paruqet-file-churn" on the long run, use the compactor in the next section to compact the emitted files into large parquet chunks.

Compaction


[!NOTE] Compaction and ingestion operations are fully atomic usign optimistic locking. You will receive a lake.ErrOptimisticLock in case the lock is interrupted.

Limitations

[!WARNING] LakeDB is slow. It was written due to the lack of alternatives. With this being said, the speed will eventually improve in the future, however, for now engines like DuckDB will beat this by magnitudes in every single performance aspect.

  • LakeDB performs around 100x-1000x slower in most operations compared to DuckDB.
  • High cardinality grouping is not supported.

Documentation

Overview

Package lake is a simple realtime analytics engine running on s3 with parquet.

Index

Constants

This section is empty.

Variables

View Source
var ErrOptimisticLock = errors.New("optimistic lock failure")

Functions

func Avg

func Avg[T int64 | float64](rows iter.Seq[T], count int) (result T)

Avg returns the average column value.

func Count

func Count[T int64 | float64](_ iter.Seq[T], count int) (result T)

Count counts all column values.

func Max

func Max[T int64 | float64](rows iter.Seq[T], count int) (result T)

Max returns the highest column value.

func Min

func Min[T int64 | float64](rows iter.Seq[T], count int) (result T)

Min returns the lowest column value.

func Sum

func Sum[T int64 | float64](rows iter.Seq[T], _ int) (result T)

Sum calculates the sum of all column values.

func When added in v0.4.0

func When[T any](check bool, input T) (output T)

When is convenience helper that applies some input only if the check is true otherwise the default value is returned. Useful e.g. for filters, groups or aggregations if you want to only apply if an API value is not set to null.

Types

type Aggregator

type Aggregator[T int64 | float64] func(iter.Seq[T], int) T

type Bucket

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

func New

func New(ctx context.Context, url, bucket string, opts ...BucketOption) (*Bucket, error)

New constructs a lakedb bucket pointing to the provided s3 url / bucket. Credentials are loaded with aws sdk (e.g. from env AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY).

func NewFromClient

func NewFromClient(ctx context.Context, client *s3.Client, bucket string, opts ...BucketOption) (*Bucket, error)

NewFromClient initializes a dynamitedb bucket from an existing aws s3 sdk client.

type BucketOption

type BucketOption func(*Bucket, *s3.Options)

func WithCredentials

func WithCredentials(accessKey, secretKey string) BucketOption

WithCredentials specifies a static access and secret key. This disables the default AWS SDK credential process.

func WithMaxGroups

func WithMaxGroups(groups int) BucketOption

WithMaxGroups specifies the maximum number of dynamically aggregated groups before the engine cancels. This limit exists because lakedbs engine starts consuming excessive amounts of memory on high cardinality groups.

func WithRegion

func WithRegion(region string) BucketOption

WithRegion specifies a static bucket region. This disables the default AWS SDK region process.

type Compactor

type Compactor[T any] struct {
	// contains filtered or unexported fields
}

func NewCompactor

func NewCompactor[T any](bucket *Bucket, opts ...CompactorOption[T]) *Compactor[T]

func (*Compactor[T]) Compact

func (c *Compactor[T]) Compact(ctx context.Context) error

type CompactorOption

type CompactorOption[T any] func(c *Compactor[T])

func WithCompactionSize

func WithCompactionSize[T any](minimum int) CompactorOption[T]

WithCompactionSize defines the minimum size in bytes that compacted shards must be. Shards that are smaller than this are processed and compacted.

type DateRange

type DateRange int
const (
	DateSecond DateRange = iota
	DateMinute
	DateHour
	DateDay
	DateMonth
	DateYear
)

type Filter

type Filter[T ~float64 | ~int64 | ~string] struct {
	// contains filtered or unexported fields
}

func After

func After(operand time.Time) Filter[int64]

After only works for time.UnixNano (nanoseconds) data, it checks if the row value is AFTER the operand.

func Before

func Before(operand time.Time) Filter[int64]

Before only works for time.UnixNano (nanoseconds) data, it checks if the row value is BEFORE the operand.

func Eq

func Eq[T ~float64 | ~int64 | ~string](operand T) Filter[T]

Eq checks for an exact match on the property.

func Gt

func Gt[T ~float64 | ~int64 | ~string](operand T) Filter[T]

Gt checks if the row value is greater than the operand.

func Gte

func Gte[T ~float64 | ~int64 | ~string](operand T) Filter[T]

Gte checks if the row value is greater or equal than the operand.

func In

func In[T ~float64 | ~int64 | ~string](operands ...T) Filter[T]

In checks if one of the provided operands matches the row value.

func Lt

func Lt[T ~float64 | ~int64 | ~string](operand T) Filter[T]

Lt checks if the row value is less than the operand.

func Lte

func Lte[T ~float64 | ~int64 | ~string](operand T) Filter[T]

Lte checks if the row value is less or equal than the operand.

type Float

type Float struct {
	Data float64 `parquet:"data"`
	// contains filtered or unexported fields
}

func AggrFloat

func AggrFloat(aggregation Aggregator[float64]) Float

func FilterFloat

func FilterFloat(filters ...Filter[float64]) Float

func GroupFloat

func GroupFloat(grouper Grouper) Float

func NewFloat

func NewFloat[T ~float64](value T) Float

type Grouper

type Grouper func(parquet.Value) parquet.Value

func Date

func Date(r DateRange) Grouper

Date is only for lake.Int values that represent a time.Time in Unix (nanoseconds). It removes everything from the date after the range to group values to "day", "hour", etc. buckets.

func Exact

func Exact() Grouper

Exact performs an exact distinct grouping on the column. Every unique value creates a new column group.

func Floor

func Floor(bucketSize int64) Grouper

Floor is only for numerical values (lake.Int / lake.Float). It floors the value to the bucket size to retrieve the group value.

func Fold

func Fold() Grouper

Fold is only for string values (lake.String). It folds the value into lowercase to retrieve the group value.

func Prefix

func Prefix(length int) Grouper

Prefix is only for string values (lake.String). It trims everything before :length from the value and uses this as group value.

func Round

func Round(bucketSize int64) Grouper

Round is only for numerical values (lake.Int / lake.Float). It rounds the value to the bucket size to retrieve the group value.

func Suffix

func Suffix(length int) Grouper

Suffix is only for string values (lake.String). It trims everything after len(data)-length: from the value and uses this as group value.

type Ingestor

type Ingestor[T any] struct {
	// contains filtered or unexported fields
}

Ingestor provides a processor for one batch of input data.

func NewIngestor

func NewIngestor[T any](bucket *Bucket, opts ...IngestorOption[T]) *Ingestor[T]

func (*Ingestor[T]) Close

func (in *Ingestor[T]) Close(ctx context.Context) error

Close writes the ingested rows into the underlying storage.

func (*Ingestor[T]) Commit

func (in *Ingestor[T]) Commit(ctx context.Context) error

Commit writes the processed parquet rows to disk.

func (*Ingestor[T]) Insert

func (in *Ingestor[T]) Insert(ctx context.Context, rows ...T) error

Insert writes the provided parquet row to the processor. This does NOT write anything to disk.

type IngestorOption

type IngestorOption[T any] func(i *Ingestor[T])

func WithAutoCommit

func WithAutoCommit[T any](interval time.Duration) IngestorOption[T]

WithAutoCommit ensures that inserts automatically commit data after the specified interval.

func WithMaxBacklogSize added in v0.5.0

func WithMaxBacklogSize[T any](size int) IngestorOption[T]

WithMaxBacklogSize defines a custom maximum queue size of failing writes that are kept in backlog.

type Int

type Int struct {
	Data int64 `parquet:"data"`
	// contains filtered or unexported fields
}

func AggrInt

func AggrInt(aggregation Aggregator[int64]) Int

func FilterInt

func FilterInt(filters ...Filter[int64]) Int

func GroupInt

func GroupInt(grouper Grouper) Int

func NewInt

func NewInt[T ~int | ~int64](value T) Int

type QueryBuilder

type QueryBuilder[T any] struct {
	// contains filtered or unexported fields
}

QueryBuilder wraps the query structure with api exposed methods to construct it. Generics are not strictly required here but make the api more userfriendly for autocompletion.

func Query

func Query[T any]() *QueryBuilder[T]

func (*QueryBuilder[T]) Aggregate

func (b *QueryBuilder[T]) Aggregate(aggregates T) *QueryBuilder[T]

func (*QueryBuilder[T]) GroupBy

func (b *QueryBuilder[T]) GroupBy(grouping T) *QueryBuilder[T]

func (*QueryBuilder[T]) Limit

func (b *QueryBuilder[T]) Limit(limit int) *QueryBuilder[T]

func (*QueryBuilder[T]) Scan

func (b *QueryBuilder[T]) Scan(ctx context.Context, bucket *Bucket) ([]T, error)

func (*QueryBuilder[T]) Where

func (b *QueryBuilder[T]) Where(filter T) *QueryBuilder[T]

type String

type String struct {
	Data string `parquet:"data"`
	// contains filtered or unexported fields
}

func FilterString

func FilterString(filters ...Filter[string]) String

func GroupString

func GroupString(grouper Grouper) String

func NewString

func NewString[T ~string](value T) String

type Table

type Table struct{}

Table can be used as marker on any table to define metadata in the tag.

Directories

Path Synopsis
internal
catalog
Package catalog contains the structure of the lakedb index catalog format.
Package catalog contains the structure of the lakedb index catalog format.
group
Package group implements utils to manage groups.
Package group implements utils to manage groups.

Jump to

Keyboard shortcuts

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