{"modulePath":"github.com/labstack/pitot","version":"v0.0.0-20261123231833-0301fe8e3bdc","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package engine\n\n## Constants\n\n```go\nconst MaxPatternBytes = 256\n```\nMaxPatternBytes bounds a pattern's length.\n\n## Variables\n\n```go\nvar ErrStalled = errors.New(\"query engine stalled\")\n```\nErrStalled reports a stall in work Pitot owns: a Parquet publication running far past its budget, or an idle engine that does not answer a ping. Only a restart frees it.\n\n## Functions\n\n```go\nfunc CreateCacheTables(db *sql.DB) error\n```\nCreateCacheTables creates DuckDB's tables: the rebuildable read caches and the anomaly history. The telemetry rows themselves live in immutable Parquet batches.\n\n```go\nfunc CreateParquetViews(db *sql.DB, parquetDir string) error\n```\nCreateParquetViews exposes the fixed format-6 schema. Binding one file rather than unioning every footer bounds binder memory. Supplying a schema MAP suppresses DuckDB 2's VARIANT extraction pushdown, so read the physical schema directly; startup rejects mismatched batch schemas before this point. The bound file is the schema batch, listed first: a retired batch may be deleted between DuckDB's glob expansion and its bind. Reads of these views are bound to the captured catalog whenever it is not empty.\n\n```go\nfunc CreateViews(db *sql.DB) error\n```\nCreateViews creates stable clean-name views plus the attr() macro.\n\n```go\nfunc NormalizeJSON(text string) string\n```\nNormalizeJSON makes the JSON text of a serialized column parseable. DuckDB writes nonfinite doubles as bare NaN, Infinity and -Infinity, which JSON cannot encode; they become the ProtoJSON strings of the same names. Storage remains typed.\n\n```go\nfunc NormalizeLogQualifiers(node map[string]any)\n```\nNormalizeLogQualifiers binds approved schema-qualified log columns before the panel replaces logs with its redacted projection. Snapshot compilation uses the same lexical resolver for every relation it replaces.\n\n```go\nfunc PatternParams(value any) map[string]bool\n```\nPatternParams names the parameters a statement uses as patterns, so a caller can bound their values when it binds them.\n\n## Types\n\n```go\ntype Duck struct {\n\n\t// DB is the read pool. Reads scan immutable Parquet concurrently, so it is\n\t// sized from the machine.\n\tDB *sql.DB\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewDuck(ctx context.Context, cfg config.Config, repository *telemetrystore.Repository) (*Duck, error)\n```\n\n```go\nfunc (d *Duck) CheckpointHealth() (lastOK, lastAt time.Time, consecutiveFailures int, lastErr error)\n```\nCheckpointHealth reports the rollup-cache checkpoint's own health, mirroring MaintenanceHealth: when a fold last succeeded, when one was last attempted, how many have failed in a row, and the most recent error (nil after a clean fold). It is surfaced via /readyz separately from maintenance so a transient refusal — retried on the 10s compaction cycle — does not degrade readiness, while a fold that keeps failing well past that cadence still does. A zero lastAt means no checkpoint has been attempted since the process started.\n\n```go\nfunc (d *Duck) Close() error\n```\n\n```go\nfunc (d *Duck) CompletedServiceRollupMinute(ctx context.Context) (time.Time, error)\n```\nCompletedServiceRollupMinute is the exclusive end of detector input. The minute containing the ingest watermark may still be incomplete.\n\n```go\nfunc (d *Duck) DefaultNamespace() string\n```\nDefaultNamespace returns empty string so queries search all namespaces.\n\n```go\nfunc (d *Duck) DrainVersionRollup(ctx context.Context) (int64, bool, error)\n```\nDrainVersionRollup repeats passes while a pass's budget left batches behind, and reports whether a backlog still remains when the phase budget ends.\n\n```go\nfunc (d *Duck) Fatal() \u003c-chan error\n```\nFatal delivers the first fatal engine error a background pass saw. DuckDB has invalidated the database by then and fails every later statement, so the process must restart; nothing in it can recover the instance.\n\n```go\nfunc (d *Duck) Live(ctx context.Context) error\n```\nLive reports whether the engine can still serve. A stall fails it. A pool where statements returned recently is alive. Otherwise a ping confirms it, and a ping that fails while reads hold the pool may only have waited for them, not found the engine hung, so that is alive too.\n\n```go\nfunc (d *Duck) MaintenanceHealth() (lastOK, lastAt time.Time, consecutiveFailures int, lastErr error)\n```\nMaintenanceHealth reports the maintenance loop's own health: when it last completed cleanly, when a pass last executed at all (throttled calls don't count), and the error from the most recent executed pass (nil after a clean one). Surfaced via /readyz so an instance whose retention/compaction is failing — and therefore re-entering the storage growth spiral — tells its operator instead of only logging. lastAt distinguishes \"failing right now\" from a stale error awaiting the hourly retry; a zero lastAt means no pass has executed since the process started.\n\n```go\nfunc (d *Duck) Overruns() int\n```\nOverruns counts the reads still running more than overrunGrace past their deadlines. They make readiness degraded, never liveness: a costly query holds its own connection while the engine serves the rest.\n\n```go\nfunc (d *Duck) ParseSQL(ctx context.Context, query string) (map[string]any, error)\n```\nParseSQL parses one statement with DuckDB's parser and returns its serialized node. It reads no telemetry and takes no snapshot.\n\n```go\nfunc (d *Duck) Ping(ctx context.Context) error\n```\nPing runs a trivial statement on the read pool, recording progress when it answers. It is not tracked as a statement in flight; the connection it holds is counted in pings.\n\n```go\nfunc (d *Duck) PrepareTelemetrySQL(ctx context.Context, query, describe string, maxRows int) (string, []bool, error)\n```\nPrepareTelemetrySQL checks one untrusted SELECT (both query and describe, since binding describe can invoke table functions) against the telemetry SQL rules and wraps it in the projection that keeps nested values away from the Go driver. describe is the same statement with every placeholder replaced by NULL, which DESCRIBE can bind; the returned statement keeps query's placeholders and is run with QueryContext under the panel's read window.\n\n```go\nfunc (d *Duck) PublishParquet(ctx context.Context, publish func(context.Context) error) error\n```\nPublishParquet runs one catalog swap. Readers are never excluded or waited for: the swap is atomic under the catalog lock, and what it replaces stays on disk until no pinned reader can open it. The budget only bounds the swap's own publish gate, rename and fsync.\n\n```go\nfunc (d *Duck) PublishParquetReplacement(ctx context.Context, output telemetry.BatchMetadata, inputs []string, publish func(context.Context) error) error\n```\nPublishParquetReplacement reuses complete input caches when the SQL leases are idle. Busy leases defer the transfer to the refresh worker, without delaying the catalog swap or decoding the output again.\n\n```go\nfunc (d *Duck) QueryContext(ctx context.Context, query string, args ...any) (queryrows.Rows, error)\n```\nQueryContext executes a read against immutable Parquet files and DuckDB's local rollup cache.\n\n```go\nfunc (d *Duck) QueryRowScan(ctx context.Context, dest []any, query string, args ...any) error\n```\nQueryRowScan executes a single-row query against immutable Parquet files and DuckDB's local rollup cache.\n\n```go\nfunc (d *Duck) ReadConnections() int\n```\nReadConnections is the size of the read pool, so a caller can admit no more concurrent readers than there are connections.\n\n```go\nfunc (d *Duck) RecordAnomalies(ctx context.Context, findings []annotations.Anomaly, now time.Time) error\n```\n\n```go\nfunc (d *Duck) RefreshDashboardRollups(ctx context.Context) (int64, error)\n```\nRefreshDashboardRollups advances the analytical dashboard summaries. Each pass commits a complete set of affected service-minutes and its ingest horizon.\n\n```go\nfunc (d *Duck) RefreshReadCaches(ctx context.Context) (int64, error)\n```\nRefreshReadCaches acknowledges complete immutable files, not an ingest-time watermark. A pass only aggregates its selected batches: it never rebuilds a retained-history index. Contributions and acknowledgements commit together.\n\n```go\nfunc (d *Duck) RefreshVersionRollup(ctx context.Context) (int64, error)\n```\n\n```go\nfunc (d *Duck) RenderSQL(ctx context.Context, node map[string]any) (string, error)\n```\nRenderSQL renders a statement node (as returned by ParseSQL) back to SQL text with DuckDB's own serializer. The text is canonical: comments, dollar quotes and other lexical forms the author used cannot survive it, so a caller that checked the node can bind and run the rendering instead of the author's text.\n\n```go\nfunc (d *Duck) RollupWatermark(ctx context.Context) (time.Time, error)\n```\nRollupWatermark is the committed ingest horizon shared by service\\_rollup and span\\_rollup. This standalone preflight precedes the panel's data snapshot; snapshot-bound coverage checks read persisted state in their own transaction.\n\n```go\nfunc (d *Duck) RunRollups(ctx context.Context)\n```\n\n```go\nfunc (d *Duck) SetReadPressure(pressure func() bool)\n```\nSetReadPressure connects foreground admission to bounded background yielding.\n\n```go\nfunc (d *Duck) SnapshotCacheStats() (hits, misses int64)\n```\nSnapshotCacheStats reports the cumulative snapshot-compile cache hits and misses since start. A miss is a statement whose compiled relation aliases had to be built; a hit reused them. It lets a benchmark or test measure the cache hit rate, which window-stable statement text is meant to raise.\n\n```go\nfunc (d *Duck) Stalled() bool\n```\nStalled reports whether a Parquet publication has run for publishStall: storage has stopped serving its rename or fsync.\n\n```go\nfunc (d *Duck) Trace(ctx context.Context, query telemetry.TraceQuery) ([]telemetry.IndexedSpan, telemetry.TraceTotals, error)\n```\nTrace pins the immutable Parquet snapshot for the full indexed-file read.\n\n```go\nfunc (d *Duck) TraceDetail(ctx context.Context, query telemetry.TraceQuery) (telemetry.TraceDetail, error)\n```\nTraceDetail pins one snapshot for a trace's spans and logs together.\n\n```go\nfunc (d *Duck) TraceSummaries(ctx context.Context, ids []telemetry.TraceIdentity, start, end int64) ([]telemetry.TraceTotals, error)\n```\nTraceSummaries pins one snapshot for the bounded multi-trace root pass.\n\n```go\nfunc (d *Duck) Watch(ctx context.Context)\n```\nWatch reports read overruns, and delivers ErrStalled on Fatal once a stall in Pitot's own work has lasted stallExit, so the process exits and its supervisor restarts it. Overload and costly queries are no stall. It stops with ctx, so shutdown cannot fire it.\n\n```go\nfunc (d *Duck) WithReadTransaction(ctx context.Context, read func(queryrows.Queryer) error) error\n```\nWithReadTransaction keeps derived annotation rows and completeness flags in one read snapshot. Its callback only receives the query surface.\n\n```go\nfunc (d *Duck) WriteGate() *writegate.Gate\n```\nWriteGate returns the gate that serializes writes to DuckDB's rebuildable rollup cache.\n\n","path":"github.com/labstack/pitot/internal/engine","name":"engine","synopsis":"","isRedistributable":true}
