inspect

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 15 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 inspect implements `dtctl inspect`: a small, fixed set of pure-Go analytics primitives over a spilled query-result file (Layer 2 of the result spill design). Its genuinely new capability over the Layer 1 manifest is row access (--head/--tail/--page/--fields); --schema/--stats/--sample re-derive the manifest from disk for a file whose envelope is no longer in context.

The package is pure: it reads files and returns data structures. It never writes to stdout, parses CLI flags, or talks to Grail — the command layer owns those. It deliberately exposes no query/expression language (D16): aggregate questions go back to DQL, complex local analysis goes to an external tool on the file.

Index

Constants

View Source
const DefaultRowCount = 10

DefaultRowCount is the row cap applied to head/tail/sample (and a bare --fields, which defaults to head) when the caller does not specify one. Kept small so a row-access call stays inline and agent-context-friendly by default.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code        string
	Message     string
	Suggestions []string
	// Err is an optional wrapped cause for errors.Is/As chains; it is not shown
	// to the user (Message already carries the human-readable text).
	Err error
}

Error is a typed inspect failure carrying a stable envelope error code (D32 / INSPECT IN9) and actionable suggestions. The command layer surfaces Code and Suggestions in the agent envelope (via errorToDetail) and Message to humans.

func BadFlags

func BadFlags(message string, suggestions ...string) *Error

BadFlags builds an inspect_bad_flags error. It is exported for the command layer, which owns flag parsing and one-primitive-per-call validation (IN9), so usage errors share the same stable envelope code as engine-side failures.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Primitive

type Primitive string

Primitive is the single analytics operation an inspect call performs. Exactly one is chosen per call (IN1); the set is closed (IN6) — adding to it is a deliberate decision, not an open extension point, which is how "no second query language" stays true over time.

const (
	// Row-access primitives — the reason inspect exists (D30). They return
	// arbitrary rows the Layer 1 manifest never carried.
	PrimHead Primitive = "head" // first N rows
	PrimTail Primitive = "tail" // last N rows
	PrimPage Primitive = "page" // a paginated window: offset O, limit L

	// Re-derivation primitives — conveniences for a file whose manifest is no
	// longer in context (a stale spill, a cross-session hand-off). They re-emit
	// the Layer 1 manifest shape from disk rather than re-querying Grail.
	PrimSchema Primitive = "schema" // columns + types + null counts
	PrimStats  Primitive = "stats"  // per-column profile
	PrimSample Primitive = "sample" // N representative (leading) rows

	// PrimFilter streams every record in the file through a caller-supplied jq
	// program and collects the objects it emits — full-file predicate filtering
	// (the missing "give me only the matching rows" capability) without a bespoke
	// query language (D16: jq is a general post-processor the caller opts into,
	// not dtctl's own DQL alternative). It is selected by --jq; a row-access
	// window (--head/--tail/--page) carried in the request bounds the output, and
	// the whole-file no-window form is mandatory-guarded by the re-spill machinery
	// because its output is otherwise unbounded.
	PrimFilter Primitive = "filter"
)

type Reader

type Reader interface {
	// Columns returns the column names when the format carries a cheap schema
	// (Parquet footer, CSV header). It returns nil when the schema is only
	// knowable by scanning rows (NDJSON / JSON), in which case the caller falls
	// back to the sidecar schema or best-effort discovery.
	Columns() []string
	// Next returns the next record, or io.EOF when the stream is exhausted. The
	// returned map is owned by the caller.
	Next() (map[string]interface{}, error)
	// Close releases the underlying file/handles.
	Close() error
}

Reader streams records out of a spilled file one at a time, so a row-access primitive reads only what it returns and memory never scales with the file size. Row order is file order (= spill order = the DQL result order); a reader never re-sorts (sorting is a query concern — push `| sort` into DQL, IN7).

type Request

type Request struct {
	Path      string
	Primitive Primitive

	// N is the row count for head/tail/sample.
	N int
	// Offset/Limit are the page window for PrimPage.
	Offset, Limit int
	// Fields projects row-access output to these columns, in DQL `fields` style.
	// Empty means all columns.
	Fields []string
	// StatsColumns restricts PrimStats to these columns. Empty means all.
	StatsColumns []string

	// Filter is a jq program run per record over the WHOLE file (PrimFilter). When
	// non-empty it takes precedence over the row-access switch and turns the call
	// into a streaming filter; Primitive then carries the optional bounding window
	// (PrimHead/PrimTail/PrimPage) or PrimFilter for the unbounded whole-file form.
	Filter string

	// ActiveContext / ActiveTenant are the live dtctl context name and tenant id,
	// used for the structural cross-context/tenant refusal (D9/D32).
	ActiveContext string
	ActiveTenant  string
}

Request is a fully-validated inspect invocation. The command layer parses flags, enforces one-primitive-per-call, and resolves the active context/tenant before constructing it; the engine assumes it is well-formed.

type Result

type Result struct {
	Kind     string
	Records  []map[string]interface{}
	Summary  *output.ResultFileManifest
	Format   string
	Sidecar  *output.SidecarManifest
	Warnings []string
}

Result is the engine output. Exactly one of Records / Summary is populated, matching Kind (output.KindRecords for row access, output.KindFileSummary for the re-derived manifest primitives).

func Run

func Run(req Request) (*Result, error)

Run executes a validated inspect request against the spilled file. It resolves the file format and provenance (sidecar), refuses a cross-context/tenant file structurally before opening it (D9/D32), then dispatches the chosen primitive. All failure paths return a *Error carrying a stable envelope code.

Jump to

Keyboard shortcuts

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