table_aggregate
Groups and measures with per-measure filter and order_by.
Flags
| Flag | Value |
|---|---|
| Kind | construct: makes a value from values |
| Rows | changes the rows |
| Deterministic | yes |
| Order matters | no |
| Decomposable | yes, by per-group measure states |
| Makes | a table value |
Parameters
| Parameter | Type | Required | Notes |
|---|---|---|---|
table |
reference | yes | A value's reference. |
group_by |
array of named | no | The grouping keys; null is one key. |
measures |
array of measure | no | Aggregate calls, each with an optional filter and, for ordered ones, an order. |
grouping_sets |
array of array of integer | no | Grouping sets as lists of group_by indices; a key outside a set is null in its rows, and [] is the grand total. Rows come by set, then key order. |
set_index |
string | no | With grouping_sets: the name of an Int64 column, after the keys, holding each row's set index. |
response_format |
"concise" | "detailed" | no | The byte budget: 64 KiB concise, 512 KiB detailed. |
Example
Over the example tables orders; ${input:name} is an input's reference and ${verb} the value an earlier call made.
table_aggregate {
"table": "${input:orders}",
"group_by": [
{
"name": "customer",
"expr": {
"col": 1
}
}
],
"measures": [
{
"name": "n",
"expr": {
"fn": "count_all",
"args": []
}
}
]
}Result
40 rows
{
"ref": "sha256:aff8cc31c2dbd3daa22533f05fca52f27235c1ffb98edadb5a5b0b24a2538469",
"kind": "table",
"rows": 40,
"schema": {
"fields": [
{
"name": "customer",
"type": {
"kind": "int64"
},
"nullable": true,
"metadata": {}
},
{
"name": "n",
"type": {
"kind": "int64"
},
"nullable": false,
"metadata": {}
}
],
"metadata": {}
}
}In the hint language
The same step as a plan, as the language prints it.
output out = from orders
aggregate {n = count_all()} by:{customer}Diagnostics
A refusal comes back as ok: false with coded diagnostics; every code, with its fix, is on the diagnostics page. A parameter that does not match the schema above is ARG_INVALID, with the parameter's path.