Query document
Query documents are flat JSON or TOML profiles. The wire format accepts exactly one top-level operation key per document. Nested "operation": { … } and "output": { … } objects are rejected at parse time.
TOML is converted to a JSON value tree, then the same wire parser runs — both formats are first-class.
Required field
| Field | JSON | TOML |
|---|---|---|
dataset | "dataset": "temperature" | dataset = "temperature" |
Must name a dataset in the .tet catalog; non-empty.
Operation keys (pick one)
Use any single key from the operations reference.
| Meaning | JSON | TOML |
|---|---|---|
| Scalar mean | "mean": [] | mean = [] |
| Mean along axis 0 | "mean": 0 | mean = 0 |
| Partial over axes 0 and 1 | "sum": [0, 1] | sum = [0, 1] |
| Mean along named axis | "mean": "time" | mean = "time" |
| 95th percentile on axis 0 | "quantile": { "q": 0.95, "axis": 0 } | [quantile] / q = 0.95 / axis = 0 |
| Histogram | "histogram": { "bins": 10, "axis": 0 } | [histogram] / bins = 10 / axis = 0 |
| Transform | "transform": { "method": "zscore" } | [transform] / method = "zscore" |
| Spill export | "spill": "slice.bin" | spill = "slice.bin" |
Parametric ops (quantile, histogram, transform, null_count, …) use inline JSON objects or TOML inline/subtables.
Selection
Optional half-open box per axis. Omitted selection means the full dataset shape.
{
"dataset": "temperature",
"selection": [
{ "start": 0, "stop": 100, "step": 2 },
{ "start": 0, "stop": 3 }
],
"mean": []
}dataset = "temperature"
mean = []
[[selection]]
start = 0
stop = 100
step = 2
[[selection]]
start = 0
stop = 3| Field | Notes |
|---|---|
start | Inclusive lower bound (default 0) |
stop | Exclusive upper bound (default axis length) |
step | Stride; must be non-zero (default 1) |
start_label / stop_label | Resolve to indices via footer coords |
Shorthand box form:
{
"dataset": "temperature",
"selection": { "start": [0, 0], "stop": [2, 3] }
}dataset = "temperature"
[selection]
start = [0, 0]
stop = [2, 3]See Selections & metadata for dimension names, coordinate labels, and striding behavior.
Filter
filter is a closed cell predicate: eq, ne, lt, le, gt, ge, is_null, and is_not_null, combined with AND. There is no expression language.
Three layers:
- Zone-map chunk skip — drop tiles whose zone min/max/null cannot match.
read_plan.zone_filter_skipped_chunksis that count. Missing zone maps mean no skip. Zone maps may come from embedded footer spills (preferred) or generation sidecars — Embedded indexes. - Value-posting skip (optional) — for a single exact
eqwhose literal encodes as one raw value, a sealed INDEX may drop more of the survivors.read_plan.index_filter_skipped_chunksis that count (default 0). Discovery: embed → sidecar (+ MANIFEST hash when package) → missing. Ranges,ne, null tests, and inexact literals do not use it. - Cell filter — apply the same predicate inside a kept chunk. A tier-A/B fold ignores non-matches. Materialize and transform keep the selection shape: non-matching floats (
f16/f32/f64) are NaN; non-matching integers are the dataset fill (_FillValue,missing_value, orfill_value). Integer materialize underfilterwithout a fill is refused.
Zone maps answer “can this chunk’s range contain the predicate?” Postings answer “which chunks contain this exact value?” when the dataset has at most 64 distinct non-null values. The cell filter is what the fold and the dense result use.
{
"dataset": "temperature",
"filter": { "ge": 0 },
"sum": []
}dataset = "temperature"
sum = []
[filter]
ge = 0Label filter
label_filter is closed footer label equality: { "axis": "…", "eq": "…" } (axis name or decimal index). It is pandas-style station == "nyc", not a cell-value compare.
- Requires footer coordinate labels on that axis (fail closed if missing).
- Optional
coord_label_postingsinINDEX.jsonmay skip chunks that cannot contain the label (index_filter_skipped_chunks). Missing index still matches positions from footer labels. - AND with cell
filterwhen both are set.
{
"dataset": "temperature",
"label_filter": { "axis": "station", "eq": "nyc" },
"sum": []
}dataset = "temperature"
sum = []
[label_filter]
axis = "station"
eq = "nyc"Group-by
group_by must pair with exactly one reduction. Empty reduction axes mean “fold the complement of group_by”. Explicit axes must be disjoint from the group axes and, together with them, cover the full rank. At least one axis must remain to reduce.
Two forms:
| Form | Partitions by | execution.group_count |
|---|---|---|
| Array of dimension names or decimal indices | Each index along those axes | Product of the group axes’ logical extents |
Object { "by": "labels", "axes": [...] } | Distinct coordinate labels on those axes (repeated labels collapse) | Product of distinct-label counts. Requires footer coords on those axes (fail closed if missing). Closed keys only (by / axes); by must be labels. |
Tier-A/B reductions stream one fold per group (memory_strategy = streaming_fold). Tier-C ops such as median materialize. transform, covariance, and correlation are rejected.
{
"dataset": "temperature",
"group_by": ["col"],
"sum": []
}dataset = "temperature"
group_by = ["col"]
sum = []{
"dataset": "temperature",
"group_by": { "by": "labels", "axes": ["col"] },
"sum": []
}dataset = "temperature"
group_by = { by = "labels", axes = ["col"] }
sum = []Window
window folds an existing reduction over successive spans of one axis. It is not a new dataset, not a join, and not SQL OVER. Docs teach bins / rolling only (legacy tumbling / sliding are reject-closed).
mode | Behavior |
|---|---|
bins | Non-overlapping chunks of size. align start (default) puts a short remainder at the end; end at the start. window_count = ceil(extent / size). |
rolling | Length-size frames advancing by step (default 1). Without pad: window_count = floor((extent - size) / step) + 1. |
Worked example: extent 7, size 3 → bins → window_count 3; rolling (step 1) → window_count 5.
| Field | Required | Notes |
|---|---|---|
axis | yes | Dimension name or decimal index |
size | yes | Positive integer length along that axis |
mode | yes | bins or rolling |
pad | no | none (default) / 0 / nan / fill — edge fill for short bins or overhanging rolling windows. fill needs dataset _FillValue / missing_value / fill_value; nan refuses on integer dtypes |
step | no | Rolling stride (≥ 1). Omitted → 1. Present with mode bins is rejected |
align | no | start (default) / end — short-bin side, or rolling overhang side under pad. Rolling + align end requires pad other than none |
min_count | no | Minimum real (non-pad) cells (1…size, default 1). Fewer → NaN for that window |
Requires exactly one reduction. Empty reduction axes mean reduce only within each window along the windowed axis (other axes kept). Not valid with group_by, transform, covariance/correlation, or materialize-required ops. execution.window_count is the number of window positions. All wire dtypes.
{
"dataset": "temperature",
"window": { "axis": "time", "size": 3, "mode": "bins" },
"mean": []
}dataset = "temperature"
mean = []
[window]
axis = "time"
size = 3
mode = "bins"{
"dataset": "temperature",
"window": {
"axis": "time",
"size": 4,
"mode": "rolling",
"step": 2,
"pad": "nan",
"align": "end",
"min_count": 2
},
"mean": []
}Use "mode": "rolling" for overlapping length-size frames.
Align
align compares two catalog datasets in one sealed package on named axes — extents, dimension names, and coordinate labels. It does not join, broadcast, or produce a new array. Mismatch is a structured execution.alignment result (or a typed error for missing datasets / unresolvable axes), never a silent success.
| Field | Required | Notes |
|---|---|---|
with | yes | Second dataset name (must differ from dataset) |
axes | yes | Non-empty list of dimension names or decimal indices |
Mutually exclusive with selection / filter / group_by / window / reduction / pipeline / spill / write. Closed keys only.
{
"dataset": "a",
"align": { "with": "b", "axes": ["row", "col"] }
}dataset = "a"
[align]
with = "b"
axes = ["row", "col"]On execute (-x), execution.alignment.aligned is true when every compared axis agrees.
Pipeline
pipeline is an ordered step list lowered onto the flat document at parse time. Execution is still one pass. Step order is select, then filter, then one reduction (group_by or window plus one op, or a bare op), then spill or write. Repeats, unknown steps, empty lists, more than eight steps, and out-of-order stages fail. pipeline cannot sit beside those analytic keys at the top level. execution and dataset may.
{
"dataset": "temperature",
"pipeline": [
{ "select": [{}, {}] },
{ "group_by": ["1"], "sum": [] }
]
}dataset = "temperature"
[[pipeline]]
select = [{}, {}]
[[pipeline]]
group_by = ["1"]
sum = []The step key is select, not selection. Round-trip serialization keeps pipeline and omits the lowered fields.
Execution hints
Optional "execution" object controls memory and I/O:
{
"dataset": "temperature",
"mean": [],
"execution": {
"memory_budget_percent": 40,
"fold_parallel": false,
"device": "auto"
}
}dataset = "temperature"
mean = []
[execution]
memory_budget_percent = 40
fold_parallel = false
device = "auto"| Field | Effect |
|---|---|
memory_budget_bytes | Hard cap on anonymous RAM for dense paths (highest precedence) |
memory_budget_percent | Percent of host RAM (100 = 100%; stored as basis points internally) |
fold_parallel | false forces sequential chunk visits; does not enable linear scan |
device | cpu, auto, metal, cuda, cuda:N, rocm, cuda:multi, … (needs -x) |
Precedence for memory budget: query memory_budget_bytes → per-file TIDX header → query memory_budget_percent → TIDX percent → 256 MiB fallback.
CLI --device overrides execution.device. CLI -t supplies the .tet path — there is no .tet path field inside the query document.
Transform output routing
When using "transform", optional "write" controls where pass-2 output goes:
{
"dataset": "temperature",
"transform": { "method": "zscore", "axis": 0 },
"write": { "target": "sidecar", "timestamp": false }
}dataset = "temperature"
[transform]
method = "zscore"
axis = 0
[write]
target = "sidecar"
timestamp = false| Target | Behavior |
|---|---|
switch (default) | RAM when selection fits budget; spill otherwise |
ram | Dense buffer in memory |
spill | Write to caller path (write.path or top-level spill semantics) |
sidecar | Publish a one-chunk .tet beside the source file |
Sidecar auto filename: {stem}.{method}[.{timestamp}].tet. Catalog dataset name: {source}-{method} (e.g. temperature-zscore).
write is mutually exclusive with top-level "spill".
Spill export (no operation)
Export the full logical selection without a reduction key:
{
"dataset": "temperature",
"spill": "slice.bin"
}dataset = "temperature"
spill = "slice.bin"Relative paths resolve against the .tet file's directory, not the shell cwd. Paths must lie under the spill allowlist (see Execution strategies).
Input format detection
| Source | Detection |
|---|---|
File .json / .toml | Extension |
| Inline or stdin | Leading { → JSON; otherwise TOML |
- or omitted QUERY | Read stdin |
# TOML file
tet query mean.toml -t data.tet -x -q
# Inline JSON
tet query '{"dataset":"temperature","mean":[]}' -t data.tet -x -q
# Inline TOML (no leading brace)
tet query 'dataset = "temperature"
mean = []' -t data.tet -x -q
# Stdin TOML
echo 'dataset = "temperature"
mean = []' | tet query - -t data.tet -x -qValidation limits
Untrusted input is bounded:
- Payload size ≤ 1 MiB
- JSON nesting depth ≤ 64
- Unknown top-level fields rejected (
deny_unknown_fields) selectionrank,operation.axes,group_bykeys, andpipelinesteps each ≤ 8 (MAX_NDIM/ pipeline cap)- Axis tokens: non-negative decimal indices or dimension names — not arbitrary expressions
Treat echoed dataset names and axis labels as untrusted display data in logs and UIs.
TOML patterns for nested wire shapes
| Wire shape | TOML |
|---|---|
| Scalar op | mean = [] |
| Single axis index | mean = 0 |
| Multiple axes | sum = [0, 1] |
| Named axis | mean = "time" |
| Parametric op | [quantile] subtable with fields |
| Per-axis selection | [[selection]] array-of-tables |
| Box selection | [selection] with start = […], stop = […] |
| Execution block | [execution] subtable |
Not supported in either format: nested "operation" / "output" objects.