Query cookbook
Copy-paste query patterns for common tasks. All examples assume a dataset named temperature in data.tet unless noted.
Query documents are flat — use "mean": [] / mean = [], not nested "operation" objects. Every example below shows JSON and TOML; both compile to the same wire document.
See the Query engine overview for architecture and limits.
Scalar reductions
Mean:
{ "dataset": "temperature", "mean": [] }dataset = "temperature"
mean = []tet query mean.toml -t data.tet -x -q
# dataset=temperature status=ok op=mean mean=3.5Sum, min, max, count — swap the operation key:
{ "dataset": "temperature", "sum": [] }dataset = "temperature"
sum = []| Op | JSON | TOML |
|---|---|---|
| min | "min": [] | min = [] |
| max | "max": [] | max = [] |
| count | "count": [] | count = [] |
Variance and standard deviation:
{ "dataset": "a", "var": [] }dataset = "a"
var = []{ "dataset": "a", "std": [] }dataset = "a"
std = []Product and norms:
{ "dataset": "a", "product": [] }
{ "dataset": "a", "norm_l1": [] }
{ "dataset": "a", "norm_l2": [] }dataset = "a"
product = []
# Separate files, or swap the key:
# norm_l1 = []
# norm_l2 = []NaN-skipping mean/std:
{ "dataset": "temperature", "nan_mean": [] }dataset = "temperature"
nan_mean = []{ "dataset": "temperature", "nan_std": [] }dataset = "temperature"
nan_std = []Partial-axis reductions
Sum along axis 0:
{ "dataset": "a", "sum": 0 }dataset = "a"
sum = 0Reduce over multiple axes:
{ "dataset": "a", "sum": [0, 1] }dataset = "a"
sum = [0, 1]Mean along a named axis (requires footer dim_names):
{ "dataset": "temperature", "mean": "time" }dataset = "temperature"
mean = "time"tet info data.tet --metadata # check dim_namesSelections and previews
Full 2×3 slice preview:
{
"dataset": "temperature",
"selection": { "start": [0, 0], "stop": [2, 3] }
}dataset = "temperature"
[selection]
start = [0, 0]
stop = [2, 3]tet query slice.toml -t data.tet -x --format table --preview 62×2 sub-slice:
{
"dataset": "temperature",
"selection": { "start": [0, 0], "stop": [2, 2] }
}dataset = "temperature"
[selection]
start = [0, 0]
stop = [2, 2]Strided selection:
{
"dataset": "temperature",
"selection": [
{ "start": 0, "stop": 100, "step": 2 },
{ "start": 0, "stop": 48 }
],
"mean": []
}dataset = "temperature"
mean = []
[[selection]]
start = 0
stop = 100
step = 2
[[selection]]
start = 0
stop = 48Slice by coordinate label (requires footer coords):
{
"dataset": "temperature",
"selection": [
{ "start_label": "2024-01-01", "stop_label": "2024-01-03" },
{ "start": 0, "stop": 2 }
],
"mean": []
}dataset = "temperature"
mean = []
[[selection]]
start_label = "2024-01-01"
stop_label = "2024-01-03"
[[selection]]
start = 0
stop = 2QC counts
Scalar QC (swap the key for each op):
{ "dataset": "temperature", "nan_count": [] }dataset = "temperature"
nan_count = []Also: null_count, inf_count, any_inf, any_nan, all_finite — same shape with = [].
Null count with explicit fill value:
{
"dataset": "temperature",
"null_count": { "fill": -999, "axis": 0 }
}dataset = "temperature"
[null_count]
fill = -999
axis = 0Partial-axis QC:
{ "dataset": "temperature", "nan_count": 0 }dataset = "temperature"
nan_count = 0Index operations
{ "dataset": "temperature", "arg_min": [] }dataset = "temperature"
arg_min = []{ "dataset": "temperature", "arg_max": 0 }dataset = "temperature"
arg_max = 0Quantiles and histograms
Median:
{ "dataset": "a", "median": [] }dataset = "a"
median = []{ "dataset": "a", "median": 0 }dataset = "a"
median = 0Quantile on axis 0:
{ "dataset": "a", "quantile": { "q": 0.95, "axis": 0 } }dataset = "a"
[quantile]
q = 0.95
axis = 0Histogram with auto edges from data min/max:
{ "dataset": "a", "histogram": { "bins": 10, "axis": 0 } }dataset = "a"
[histogram]
bins = 10
axis = 0Histogram with fixed range:
{ "dataset": "a", "histogram": { "bins": 10, "min": 0, "max": 1 } }dataset = "a"
[histogram]
bins = 10
min = 0
max = 1Covariance and correlation
For 2-D datasets where one axis is observations and the other is variables:
{ "dataset": "variables", "covariance": { "axis": 0 } }dataset = "variables"
[covariance]
axis = 0{ "dataset": "variables", "correlation": 0 }dataset = "variables"
correlation = 0Transforms
Z-score with sidecar output (stable filename):
{
"dataset": "temperature",
"transform": { "method": "zscore" },
"write": { "target": "sidecar", "timestamp": false }
}dataset = "temperature"
[transform]
method = "zscore"
[write]
target = "sidecar"
timestamp = falsetet query zscore_sidecar.toml -t data.tet -x -q
# Publishes temperature.zscore.tet beside data.tetOther methods: minmax, l1, l2, center, scale, log1p, sqrt, softmax.
Transform along an axis:
{
"dataset": "temperature",
"transform": { "method": "softmax", "axis": 0 },
"write": { "target": "ram" }
}dataset = "temperature"
[transform]
method = "softmax"
axis = 0
[write]
target = "ram"Write to spill file when selection is large:
{
"dataset": "temperature",
"transform": { "method": "zscore" },
"write": { "target": "spill", "path": "normalized.bin" }
}dataset = "temperature"
[transform]
method = "zscore"
[write]
target = "spill"
path = "normalized.bin"Spill export (full tensor slice)
Export logical selection to binary without a reduction:
{
"dataset": "temperature",
"selection": { "start": [0, 0], "stop": [100, 48] },
"spill": "slice.bin"
}dataset = "temperature"
spill = "slice.bin"
[selection]
start = [0, 0]
stop = [100, 48]Relative path resolves beside data.tet. Use --spill-allow for extra roots.
Memory and execution hints
Raise RAM budget for tier-C ops on large selections:
{
"dataset": "temperature",
"median": [],
"execution": { "memory_budget_percent": 50 }
}dataset = "temperature"
median = []
[execution]
memory_budget_percent = 50Force sequential chunk I/O:
{
"dataset": "temperature",
"mean": [],
"execution": { "fold_parallel": false }
}dataset = "temperature"
mean = []
[execution]
fold_parallel = falseExperimental GPU (requires built features):
{
"dataset": "temperature",
"mean": [],
"execution": { "device": "auto" }
}dataset = "temperature"
mean = []
[execution]
device = "auto"tet query gpu.toml -t data.tet -x --device auto -q
# --device CLI flag overrides execution.device when both are setOutput format cheat sheet
Works with either .json or .toml query files:
tet query q.toml -t data.tet # plan only, full JSON
tet query q.json -t data.tet -x -q # execute, one-line output
tet query q.toml -t data.tet -x --format stats
tet query q.toml -t data.tet -x --format table --preview 6
tet query q.toml -t data.tet --format planRe-run from history
tet qhist list --dataset temperature
tet qhist run 1 # re-run newest matching queryFixture queries
The tetration repo ships paired .json / .toml fixtures in fixtures/queries/:
| Fixture | Notes |
|---|---|
mean_temperature | Scalar mean |
mean_strided_temperature | Mean + strided selection |
slice_full_temperature | Full 2×3 preview |
slice_2x2_temperature | 2×2 sub-slice |
sum_a / sum_axis0_a | Multi-chunk u8 dataset |
var_a | Scalar variance |
quantile_axis0_a | Quantile on axis 0 |
Further reading
- Operations reference — every op and response field
- Selections & metadata — dim names, coord labels
- Execution strategies — memory, spill, GPU
- tet query — CLI flags