pipedatasets

package
v0.162.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 18 Imported by: ? 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.

Documentation

Overview

Package pipedatasets keeps pipeline datasets: named snapshots of a stream that a pipeline materialised into DuckDB with the `builtin:datatug/dataset` sink, to be read back, joined and analysed with SQL.

The word "dataset" already names a recordset definition of a DataTug project (`datatug dataset`), so the DuckDB materialisations are always called pipeline datasets, in code, in the CLI and in the API.

A pipeline dataset is an explicit cache, never a transparent proxy: it holds what one run wrote and changes only when a run writes it again. Every dataset is one DuckDB file `<name>.duckdb` with the single table `data`, and a provenance sidecar `<name>.json` that says which pipeline, node and run wrote it, from which queries, when, and under which pipeline definition.

The files hold rows a policy admitted for one person, so they live outside every Git repository, below ~/.datatug/pipeline-datasets/<project-key>/: directories are 0700 and files 0600, a root inside a Git repository or behind a link is refused, a dataset is written beside its final name and renamed into place, and one writer at a time holds the dataset's lock while readers keep reading the file they opened.

DuckDB needs cgo. A build without it keeps every listing and provenance function and answers ErrRequiresCGO where rows would be written or read.

Index

Constants

View Source
const (
	// DefaultDir is the root of every project's pipeline datasets, below the
	// user's home directory.
	DefaultDir = ".datatug/pipeline-datasets"
	// DefaultMaxBytes bounds the staged rows of one dataset.
	DefaultMaxBytes = 2 << 30
	// MaxDatasets bounds the datasets of one project.
	MaxDatasets = 500
	// TableName is the table of a dataset file.
	TableName = "data"
	// ValueColumn is the column that holds an item that is not a JSON object.
	ValueColumn = "value"
)
View Source
const (
	StalePipelineChanged = "pipeline-changed"
	StalePipelineMissing = "pipeline-missing"
)

Stale reasons.

View Source
const ProvenanceVersion = 1

ProvenanceVersion is the format marker of a sidecar.

Variables

View Source
var (
	// ErrRequiresCGO is returned where DuckDB is needed in a build without cgo.
	ErrRequiresCGO = errors.New("pipeline datasets need DuckDB, which requires a cgo build of datatug (CGO_ENABLED=1)")
	// ErrNotFound is returned for a dataset that is not there.
	ErrNotFound = errors.New("pipeline dataset not found")
	// ErrBusy is returned when another run is writing the dataset.
	ErrBusy = errors.New("pipeline dataset is being written by another run")
	// ErrTooLarge is returned when a dataset would pass the store's size bound.
	ErrTooLarge = errors.New("pipeline dataset is larger than the store allows")
	// ErrInsideGit is returned for a root inside a Git repository.
	ErrInsideGit = errors.New("pipeline datasets must be stored outside Git repositories")
	// ErrUnsafeRoot is returned for a root that is a link, is not a directory,
	// or cannot be made private.
	ErrUnsafeRoot = errors.New("pipeline datasets root is not a private directory")
)

Errors a caller can test for.

Functions

func Available

func Available() bool

Available reports whether this build can write and read pipeline datasets.

func DefaultBase

func DefaultBase() (string, error)

DefaultBase is ~/.datatug/pipeline-datasets.

func ProjectKey

func ProjectKey(projectID, projectDir string) string

ProjectKey names the folder of a project's datasets: a readable form of the project id and a digest of the project's folder, so two checkouts of one project keep separate caches.

func TableIdentifier

func TableIdentifier(name string) string

TableIdentifier is the SQL name of a dataset in a query over datasets: the name with every `-` replaced by `_`.

func ValidName

func ValidName(name string) bool

ValidName reports whether name can name a pipeline dataset.

Types

type Column

type Column struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

Column is one column of a dataset, with the DuckDB type it was given.

type Freshness

type Freshness struct {
	AgeSeconds int64 `json:"ageSeconds"`
	// Stale is true when the pipeline that wrote the dataset no longer has
	// the definition it had then, or is gone.
	Stale  bool   `json:"stale"`
	Reason string `json:"reason,omitempty"`
}

Freshness says how old a dataset is and whether its pipeline changed since.

func FreshnessOf

func FreshnessOf(p Provenance, currentHash string) Freshness

FreshnessOf judges p against the current digest of its pipeline's definition; currentHash is "" when the pipeline is gone.

type Provenance

type Provenance struct {
	Version int    `json:"version"`
	Name    string `json:"name"`
	// PipelineID, Node and RunID say which node of which run wrote the dataset.
	PipelineID string `json:"pipelineId"`
	Node       string `json:"node"`
	RunID      string `json:"runId"`
	// PipelineHash is the digest of the pipeline definition the run executed;
	// the dataset is stale when the definition no longer has it.
	PipelineHash string    `json:"pipelineHash,omitempty"`
	StartedAt    time.Time `json:"startedAt"`
	FinishedAt   time.Time `json:"finishedAt"`
	Rows         int64     `json:"rows"`
	// Bytes is the size of the rows as NDJSON; FileBytes of the DuckDB file.
	Bytes     int64    `json:"bytes"`
	FileBytes int64    `json:"fileBytes"`
	Columns   []Column `json:"columns"`
	// Wrapped is true when the items were not JSON objects and each was stored
	// as {"value": item}.
	Wrapped bool     `json:"wrapped,omitempty"`
	Sources []Source `json:"sources"`
	// WrittenBy is absent in a sidecar written before sessions were recorded.
	WrittenBy *WrittenBy `json:"writtenBy,omitempty"`
}

Provenance is the sidecar of a dataset: who wrote it, from what, and when.

type ReadOptions

type ReadOptions struct {
	// Limit is the most rows to return; 0 is all of them.
	Limit int
	// Offset skips rows.
	Offset int
}

ReadOptions bound a read.

type Source

type Source struct {
	// Node is the pipeline node that ran the query.
	Node string `json:"node"`
	// Kind is `query` (a saved query), `sql` or `tugql` (inline text).
	Kind        string `json:"kind"`
	QueryID     string `json:"queryId,omitempty"`
	Environment string `json:"environment,omitempty"`
	// Connection is the id of the project database the query ran against.
	Connection string `json:"connection,omitempty"`
	// TextHash is the SHA-256 of an inline query text.
	TextHash string `json:"textHash,omitempty"`
}

Source is one query a dataset was read from. It names the query and the connection by their project ids and never holds a credential or a URL.

type Store

type Store struct {

	// MaxBytes bounds the staged rows of one dataset (DefaultMaxBytes when 0).
	MaxBytes int64
	// contains filtered or unexported fields
}

Store is the pipeline datasets of one project.

func Open

func Open(base, projectKey string) (*Store, error)

Open checks the folder base/projectKey without creating it: it must not lie inside a Git working tree or a bare repository, and must not be a link or anything but a directory (sessionstore.ResolvePrivateDirectory).

func OpenDefault

func OpenDefault(projectID, projectDir string) (*Store, error)

OpenDefault opens the store of a project below DefaultBase.

func (*Store) Delete

func (s *Store) Delete(name string) error

Delete removes a dataset. A dataset that is not there is ErrNotFound; one that is being written is ErrBusy.

func (*Store) Dir

func (s *Store) Dir() string

Dir is the folder of the store.

func (*Store) Get

func (s *Store) Get(name string) (Provenance, error)

Get returns the provenance of a dataset. A dataset exists when both its sidecar and its DuckDB file do.

func (*Store) List

func (s *Store) List() ([]Provenance, error)

List returns the provenance of every dataset, sorted by name. A sidecar that cannot be read is skipped: one bad file does not hide the others.

func (*Store) NewWriter

func (s *Store) NewWriter(name string) (*Writer, error)

NewWriter takes the dataset's lock and opens its stage. It fails with ErrRequiresCGO before anything is written in a build without DuckDB, and with ErrBusy while another run writes the same dataset.

func (*Store) Query

func (s *Store) Query(ctx context.Context, sqlText string, names []string, emit func(row []byte) error) error

Query runs one SELECT over the named datasets, each visible as a table named TableIdentifier(name), and calls emit with every result row as the bytes of one JSON object. The query runs in a DuckDB session that has the datasets attached read-only and no other access: no files, no network, no extensions, no configuration changes.

func (*Store) Read

func (s *Store) Read(ctx context.Context, name string, o ReadOptions, emit func(row []byte) error) error

Read calls emit with every row of a dataset as the bytes of one JSON object, in stored order. A dataset whose items were wrapped is returned unwrapped, as the items it was given.

type Writer

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

Writer stages the rows of one dataset. Exactly one of Commit and Abort ends it; until Commit the stored dataset, if any, is untouched.

func (*Writer) Abort

func (w *Writer) Abort()

Abort drops the stage and releases the lock. It is safe after Commit.

func (*Writer) Commit

func (w *Writer) Commit(ctx context.Context, p Provenance) (Provenance, error)

Commit builds the DuckDB file from the stage, writes the sidecar and puts both in place. p carries what the caller knows (pipeline, node, run, sources, pipeline hash); the store fills in the rest.

func (*Writer) Rows

func (w *Writer) Rows() int64

Rows is the number of items staged so far.

func (*Writer) Write

func (w *Writer) Write(item []byte) error

Write stages one item, the bytes of one JSON value. An item that is not a JSON object is stored as {"value": item}.

type WrittenBy

type WrittenBy struct {
	// Principal is the id of the principal, for people to read; empty when
	// the session had none.
	Principal string `json:"principal,omitempty"`
	// Context identifies the principal together with the exact policies that
	// decided what it could read. It holds no policy text and no path.
	Context string `json:"context"`
}

WrittenBy is the session a dataset was written under. A dataset holds the rows that session was allowed to read, so a host gives its rows back only to the same session (or to the local owner of the project).

Jump to

Keyboard shortcuts

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