Part of #403. Depends on #408.
What
Allow callers to control the order of row and column axis members in the cells query. Currently rows and columns are returned in natural DuckDB order with no sort guarantee.
Request addition
Add an optional sort object to the cells request body:
{
"axes": { ... },
"window": { ... },
"sort": {
"rows": [{ "alias": "total_volume", "direction": "DESC" }],
"columns": [{ "alias": "date", "direction": "ASC" }]
}
}
alias references either a measure alias or a dimension field alias defined in the same request. Multiple sort entries are applied in order (primary sort, secondary sort, etc.).
Implementation
The sort must be applied to the axis member ordering, not to the cells themselves. The window (offset/limit) is applied after sorting, so the caller gets the Nth page of the sorted axis.
For sort.rows referencing a measure: the row members are ordered by the aggregate value of that measure (summed/averaged across all columns). This requires a sub-query or CTE that computes the per-row aggregate totals, then orders the rows by that.
For sort.rows referencing a row dimension field: standard ORDER BY field_alias ASC|DESC.
For sort.columns referencing a measure: same pattern as rows but for columns.
Validation
alias must refer to an alias defined in axes.rows / axes.columns / axes.measures — otherwise 422 SORT_TARGET_NOT_IN_QUERY
- A row sort by a column dimension alias is invalid (and vice versa) —
422 SORT_TARGET_NOT_IN_QUERY
direction must be ASC or DESC
Acceptance criteria
Part of #403. Depends on #408.
What
Allow callers to control the order of row and column axis members in the cells query. Currently rows and columns are returned in natural DuckDB order with no sort guarantee.
Request addition
Add an optional
sortobject to the cells request body:{ "axes": { ... }, "window": { ... }, "sort": { "rows": [{ "alias": "total_volume", "direction": "DESC" }], "columns": [{ "alias": "date", "direction": "ASC" }] } }aliasreferences either a measure alias or a dimension field alias defined in the same request. Multiple sort entries are applied in order (primary sort, secondary sort, etc.).Implementation
The sort must be applied to the axis member ordering, not to the cells themselves. The window (
offset/limit) is applied after sorting, so the caller gets the Nth page of the sorted axis.For
sort.rowsreferencing a measure: the row members are ordered by the aggregate value of that measure (summed/averaged across all columns). This requires a sub-query or CTE that computes the per-row aggregate totals, then orders the rows by that.For
sort.rowsreferencing a row dimension field: standardORDER BY field_alias ASC|DESC.For
sort.columnsreferencing a measure: same pattern as rows but for columns.Validation
aliasmust refer to an alias defined inaxes.rows/axes.columns/axes.measures— otherwise422 SORT_TARGET_NOT_IN_QUERY422 SORT_TARGET_NOT_IN_QUERYdirectionmust beASCorDESCAcceptance criteria
sort.rowsby measure alias returns rows in correct measure-sorted ordersort.rowsby dimension alias returns rows in field-sorted ordersort.columnsby measure alias works equivalently422 SORT_TARGET_NOT_IN_QUERYsortreturns results in natural order (no regression)