Skip to content

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 ​

FieldJSONTOML
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.

MeaningJSONTOML
Scalar mean"mean": []mean = []
Mean along axis 0"mean": 0mean = 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.

json
{
  "dataset": "temperature",
  "selection": [
    { "start": 0, "stop": 100, "step": 2 },
    { "start": 0, "stop": 3 }
  ],
  "mean": []
}
toml
dataset = "temperature"
mean = []

[[selection]]
start = 0
stop = 100
step = 2

[[selection]]
start = 0
stop = 3
FieldNotes
startInclusive lower bound (default 0)
stopExclusive upper bound (default axis length)
stepStride; must be non-zero (default 1)
start_label / stop_labelResolve to indices via footer coords

Shorthand box form:

json
{
  "dataset": "temperature",
  "selection": { "start": [0, 0], "stop": [2, 3] }
}
toml
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:

  1. Zone-map chunk skip — drop tiles whose zone min/max/null cannot match. read_plan.zone_filter_skipped_chunks is that count. Missing zone maps mean no skip. Zone maps may come from embedded footer spills (preferred) or generation sidecars — Embedded indexes.
  2. Value-posting skip (optional) — for a single exact eq whose literal encodes as one raw value, a sealed INDEX may drop more of the survivors. read_plan.index_filter_skipped_chunks is that count (default 0). Discovery: embed → sidecar (+ MANIFEST hash when package) → missing. Ranges, ne, null tests, and inexact literals do not use it.
  3. 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, or fill_value). Integer materialize under filter without 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.

json
{
  "dataset": "temperature",
  "filter": { "ge": 0 },
  "sum": []
}
toml
dataset = "temperature"
sum = []

[filter]
ge = 0

Label 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_postings in INDEX.json may skip chunks that cannot contain the label (index_filter_skipped_chunks). Missing index still matches positions from footer labels.
  • AND with cell filter when both are set.
json
{
  "dataset": "temperature",
  "label_filter": { "axis": "station", "eq": "nyc" },
  "sum": []
}
toml
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:

FormPartitions byexecution.group_count
Array of dimension names or decimal indicesEach index along those axesProduct 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.

json
{
  "dataset": "temperature",
  "group_by": ["col"],
  "sum": []
}
toml
dataset = "temperature"
group_by = ["col"]
sum = []
json
{
  "dataset": "temperature",
  "group_by": { "by": "labels", "axes": ["col"] },
  "sum": []
}
toml
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).

modeBehavior
binsNon-overlapping chunks of size. align start (default) puts a short remainder at the end; end at the start. window_count = ceil(extent / size).
rollingLength-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.

FieldRequiredNotes
axisyesDimension name or decimal index
sizeyesPositive integer length along that axis
modeyesbins or rolling
padnonone (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
stepnoRolling stride (≥ 1). Omitted → 1. Present with mode bins is rejected
alignnostart (default) / end — short-bin side, or rolling overhang side under pad. Rolling + align end requires pad other than none
min_countnoMinimum 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.

json
{
  "dataset": "temperature",
  "window": { "axis": "time", "size": 3, "mode": "bins" },
  "mean": []
}
toml
dataset = "temperature"
mean = []

[window]
axis = "time"
size = 3
mode = "bins"
json
{
  "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.

FieldRequiredNotes
withyesSecond dataset name (must differ from dataset)
axesyesNon-empty list of dimension names or decimal indices

Mutually exclusive with selection / filter / group_by / window / reduction / pipeline / spill / write. Closed keys only.

json
{
  "dataset": "a",
  "align": { "with": "b", "axes": ["row", "col"] }
}
toml
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.

json
{
  "dataset": "temperature",
  "pipeline": [
    { "select": [{}, {}] },
    { "group_by": ["1"], "sum": [] }
  ]
}
toml
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:

json
{
  "dataset": "temperature",
  "mean": [],
  "execution": {
    "memory_budget_percent": 40,
    "fold_parallel": false,
    "device": "auto"
  }
}
toml
dataset = "temperature"
mean = []

[execution]
memory_budget_percent = 40
fold_parallel = false
device = "auto"
FieldEffect
memory_budget_bytesHard cap on anonymous RAM for dense paths (highest precedence)
memory_budget_percentPercent of host RAM (100 = 100%; stored as basis points internally)
fold_parallelfalse forces sequential chunk visits; does not enable linear scan
devicecpu, 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:

json
{
  "dataset": "temperature",
  "transform": { "method": "zscore", "axis": 0 },
  "write": { "target": "sidecar", "timestamp": false }
}
toml
dataset = "temperature"

[transform]
method = "zscore"
axis = 0

[write]
target = "sidecar"
timestamp = false
TargetBehavior
switch (default)RAM when selection fits budget; spill otherwise
ramDense buffer in memory
spillWrite to caller path (write.path or top-level spill semantics)
sidecarPublish 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:

json
{
  "dataset": "temperature",
  "spill": "slice.bin"
}
toml
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 ​

SourceDetection
File .json / .tomlExtension
Inline or stdinLeading { → JSON; otherwise TOML
- or omitted QUERYRead stdin
bash
# 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 -q

Validation limits ​

Untrusted input is bounded:

  • Payload size ≤ 1 MiB
  • JSON nesting depth ≤ 64
  • Unknown top-level fields rejected (deny_unknown_fields)
  • selection rank, operation.axes, group_by keys, and pipeline steps 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 shapeTOML
Scalar opmean = []
Single axis indexmean = 0
Multiple axessum = [0, 1]
Named axismean = "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.