Skip to content

Query engine ​

The query engine turns a flat JSON or TOML query document into a QueryResponse: catalog resolution, a chunk-level read plan, and optionally mmap-backed decode plus aggregates or transformed output.

You can run queries through:

  • tet query — CLI with plan-only or execute modes (CLI reference)
  • Rust crate — execute_query_json, plan_query_with_tet_mmap, embedder materialize helpers (Rust quick start)
  • Python (tet-py) — pip install tet-py; same wire documents via f.execute, reductions, and NumPy materialize (Python quick start)

What you can do ​

CapabilityExample
Scalar reductionsMean, sum, min, max, count, var, std over a selection
Partial-axis reductions"mean": 0 or "sum": [0, 1] — reduce along named or numeric axes
Selections & previewsHalf-open slices, strided steps, coordinate label bounds
QC countsnan_count, null_count, inf_count, any_inf, any_nan, all_finite
Tier-C statsmedian, quantile, histogram, covariance, correlation
Transformszscore, minmax, softmax, … with RAM, spill, or sidecar output
Export spillWrite the full logical selection to a binary file ("spill": "out.bin")
Named axes"mean": "time" when footer dim_names is set
Label slicesstart_label / stop_label when footer coords exist

The engine reads one dataset per query from a sealed .tet file. It never loads the whole file into RAM unless the selection and operation require it — tier-A/B reductions use streaming fold over touched chunks.

End-to-end flow ​

mermaid
flowchart LR
    Q["Query JSON/TOML"] --> Parse["Parse + validate"]
    Parse --> Plan["Read plan\n(chunk list + geometry)"]
    Plan --> Exec{"Execute?"}
    Exec -->|no| Resp["QueryResponse\n(plan only)"]
    Exec -->|yes| Decode["Decode tiles\n+ fold / materialize"]
    Decode --> Resp2["QueryResponse\n+ execution"]
  1. Parse — Flat document; one top-level operation key; unknown fields rejected.
  2. Plan — Resolve selection to a global box; list intersecting chunks from the catalog.
  3. Execute (optional) — Decode only touched chunks; run the operation, transform, or spill export.

CLI mapping:

FlagEffect
-t PATHAttach .tet for catalog + read plan
-x / --executeRun decode and operation
--preview NCap preview sample values (default 64 for full/json); Python: preview=N on f.mean / query_execute → QueryResult.preview
--formatfull, json, stats, plan, quiet, table
--deviceOptional GPU routing (experimental; needs -x)

Plan-only (no -x):

bash
tet query mean.toml -t data.tet --format plan
tet query mean.json -t data.tet --format plan

Execute with one-line output:

bash
tet query mean.toml -t data.tet -x -q
# dataset=temperature status=ok op=mean mean=3.5

Query document shape ​

Documents are flat — use "mean": [] / mean = [], not nested "operation": { "type": "mean" }. Examples below use tabbed JSON / TOML blocks.

json
{ "dataset": "temperature", "mean": [] }
toml
dataset = "temperature"
mean = []

At most one reduction key per document (mean, sum, transform, spill, …). See Query document for the full wire format.

Implementation tiers ​

Operations fall into tiers that determine memory use and performance:

TierPatternOperations
A — Scalar foldSingle pass over all elements; no full tensor in RAMsum, mean, min, max, count, var, std, product, norm_l1, norm_l2, QC counts, arg_min, arg_max, …
B — Partial-axis foldSame streaming path; combine along selected axesAny tier-A op with non-empty axis list
C — Materialize-requiredFull logical tensor (or temp spill file)median, quantile, histogram, covariance, correlation
D — Out of scopeSeparate APIs, not JSON opstet convert, tet export, multi-dataset joins, FFT/ML

Tier-A/B ops on large selections stay fast: the engine folds per chunk (parallel when in-core, linear scan when out-of-core on contiguous raw payloads). See Execution strategies.

What is not supported ​

These are intentional non-goals for the JSON query surface:

  • Multi-dataset joins — run two queries or materialize and join in caller code
  • SQL-style filter/group-by on coordinate values (label slicing is supported; filter-by-value is deferred)
  • Spectral / ML ops (FFT, conv, train) — export a hyperslab, then use NumPy / PyTorch / etc.
  • Arbitrary user callbacks per chunk
  • Query result cache in .tet — use tet qhist for recent query JSON in platform cache only

Supported dtypes ​

Wire tagTypeQuery execution
1f32Full support; optional GPU for tier-A/B
2f64Full support
3–4i32, i64Tier-A/B fold; aggregates promote to f64
5–7, 9–10u8, u16, i16, u32, u64, f16Tier-A/B fold; f16 promoted to f32 on GPU
—transformf32 / f64 only

Further reading ​

PageTopics
Query documentFields, TOML equivalents, execution hints
Operations referenceEvery op, response fields, examples
Selections & metadataSlices, striding, dim names, coord labels
Execution strategiesMemory budget, spill, transforms, GPU
Query cookbookCopy-paste examples
tet queryCLI flags and output formats
tet qhistQuery history in platform cache

Upstream implementation detail: query_engine.md in the tetration repo.