You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8742938
Browse filesBrowse the repository at this point in the historyBrowse files
fix(objectql, mcp): unlisted rank values keep their own order; review should-fixes
Contract review S1: a column named by a rank key now stays among the
directive's trailing ascending keys (NULL last), so the values the rank
does not list, which share one rank, keep a deterministic order and a cut
among them answers the same groups on every run. Pinned over real SQLite
in runtime (two unlisted values and a NULL at a cut boundary, same answer
twice, the tie-break in the statement); the engine and stdio directive
pins now show the ranked column among the trailing keys.
S2: the aggregate_records description states that a per-record-currency
amount ranks by bare numbers across currencies and says to rank inside one
currency by filtering on the currency code field; pinned in tools/list.
S3: a runtime pin with a registered read middleware narrowing ast.where:
the cut rows and totalGroups count only the admitted groups, the uncut
aggregate agreeing.
N1: the changeset, the engine docblocks and the driver comments say what a
rank does in each direction and how the unlisted values order. N3: a pin
measures the tool's rank maximum against the engine's at the boundary
(500 sent and served, 501 not sent and refused). N4: the stdio read-option
constants sit above unwrapRows' docblock. The changeset also names
KEY__label on the cut answer.
Claude-Session: https://claude.ai/code/session_01JQwxbWDsbbJizuYnDwBxT8
Co-authored-by: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: .changeset/35144-aggregate-order-cut.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,10 +15,11 @@ A ranking question ("the top five customers by revenue") over more groups than t
15
15
16
16
- An order key that names no column of the aggregated row is refused `INVALID_SORT` / 400, naming the columns the query projects.
17
17
- Only a driver that runs the cut in its own SQL statement serves it: `driver-sql` (every dialect it speaks; the window `count(*) over ()` needs MySQL 8 or later), the WASM SQLite driver, and the Turso driver's local and replica faces. Every other driver (the in-memory driver, MongoDB, OData, Turso's remote face), an aggregate the engine computes in memory (a date bucket, a reference timezone or a measure filter the driver does not run), and an aggregate with `having` are refused `INVALID_QUERY` / 400 before anything is read. Groups are never ordered or cut in the application.
18
-
-A NULL ranks last in either direction, except a `sum` or a count with no value, which ranks as the `0` it is served as. Group keys the order does not namebreak ties, ascending.
19
-
- An order key may carry a `rank`, a list of the column's values: the statement ranks each listed value by its position and every other value (a NULL among them) after them, before the cut. It is the tool's own, never an `aggregate_records` argument.
18
+
-On an order key without a `rank`, a NULL ranks last in either direction, except a `sum` or a count with no value, which ranks as the `0` it is served as. Group keys the order does not name, and a group key it names only by a `rank`, break ties, ascending, NULL last, so two runs of one call answer the same groups in the same order.
19
+
- An order key may carry a `rank`, a list of the column's values: the statement ranks each listed value by its position and every other value (a NULL among them) on one rank past them, before the cut, so the unlisted values come after the listed ones ascending and before them descending; among themselves they follow the column's own ascending order, NULL last. It is the tool's own, never an `aggregate_records` argument.
20
20
- A `limit` with no `orderBy` keeps the declared option order the uncut answer already follows: groups keyed by a leading select or radio field come back in the order the field declares its options, a value no option declares last, and the database takes that order before the cut, so the cut keeps the first declared groups. An `orderBy` the caller sends overrides it.
21
-
- A fixed-currency amount names its currency in `currencies` on the cut answer too.
21
+
- The cut answer carries what the uncut one does: a fixed-currency amount's currency in `currencies`, and `KEY__label` beside each lookup or master-detail group key, the record's name read with the caller's own permissions.
22
+
- An amount whose records each carry their own currency is ranked by its bare numbers across currencies: the tool description says to rank it inside one currency by filtering `where` on its currency code field.
22
23
- Without `orderBy` and `limit` the tool answers as before.
23
24
24
25
`@objectstack/objectql` exports `AGGREGATE_ORDER_CUT`, the engine-internal read option of `aggregate` that carries the request (a symbol, so no wire request can set it), with the `AggregateOrderCutRequest`, `AggregateOrderKey` and `AggregateOrderCutOutcome` types. `McpDataBridge` gains the optional member `aggregateGroups`; a bridge without it refuses `orderBy` / `limit` with `NOT_IMPLEMENTED` / 501 and keeps serving the rest of the tool. Nothing that was accepted before is refused.
0 commit comments