|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +import type { SemanticMigration } from '../../types.js'; |
| 4 | + |
| 5 | +// The dimension-side sibling of `dataset-measure-aggregate-field-type-refused`: |
| 6 | +// a group key over a field no driver stores. The narrowing itself registered |
| 7 | +// `not-required (no-migration-prescription)` — no key is added, removed or |
| 8 | +// re-shaped — so this entry carries no conversion and has no automatic |
| 9 | +// rewrite: which stored field should carry the value is the author's call. |
| 10 | +export const entry: SemanticMigration = { |
| 11 | + id: 'dataset-dimension-virtual-field-refused', |
| 12 | + surface: 'dataset and cube dimensions over a VIRTUAL field — `datasets[].dimensions[].field` ' |
| 13 | + + '(`DatasetDimensionSchema`) and `analyticsCubes[].dimensions.KEY.sql` naming a field whose ' |
| 14 | + + 'declared type is `formula` (`SEARCH_VIRTUAL_TYPES`, `isVirtualSearchField`), whatever its ' |
| 15 | + + '`returnType`, on the base object or, for a dotted path, on the leaf\'s own object', |
| 16 | + replacement: 'store the value in a field of its own on the object (written by a hook or a flow ' |
| 17 | + + 'when its source changes) and point the dimension at that field, or remove the dimension. ' |
| 18 | + + 'There is no automatic rewrite: which stored field should carry the value, and what writes ' |
| 19 | + + 'it, is the author\'s judgement. A stored field the formula already reads is a candidate only ' |
| 20 | + + 'when grouping by it answers the same question the formula did', |
| 21 | + reason: |
| 22 | + 'A dimension is a GROUP KEY: a dataset dimension compiles to a cube dimension whose `sql` is ' |
| 23 | + + 'its `field`, and a query selecting it groups (or date-buckets) by that column. A `formula` ' |
| 24 | + + 'is computed on read and never stored, so no driver materialises a column for it and there is ' |
| 25 | + + 'nothing to group by. Before this narrowing the dataset compiled, registered and published, ' |
| 26 | + + 'and its stored dimensions were served; only a query grouping by the formula dimension was ' |
| 27 | + + 'refused — `400 INVALID_FIELD` at `groupBy.N`, in front of whoever opened the dashboard tile — ' |
| 28 | + + 'and authoring reported nothing. The measure side already refused a total over a formula at ' |
| 29 | + + 'both doors; this is the dimension half. ⚠️ The refusal is the WHOLE dataset, not the one ' |
| 30 | + + 'member: a dataset carrying such a dimension no longer compiles, so its other, stored ' |
| 31 | + + 'dimensions stop being served with it until the dimension moves', |
| 32 | + acceptanceCriteria: |
| 33 | + 'Every dataset compiles and `os validate` / `os build` / `os lint` report no ' |
| 34 | + + '`dimension-virtual-field-refused`. The two doors that refuse it, in their own words: the ' |
| 35 | + + 'dataset compile (`registerDataset`, `queryDataset` and every door that compiles through ' |
| 36 | + + 'them) answers `400 DATASET_INVALID` with "[dataset-compiler] dataset "NAME" dimension "DIM" (dimensions.N) ' |
| 37 | + + 'groups by field "FIELD", which object "OBJECT" declares as `formula` — its value is computed ' |
| 38 | + + 'on read and never stored, so no driver materialises a column to group by, and every query ' |
| 39 | + + 'selecting this dimension is refused. Denormalise the value onto "OBJECT" (a stored field, ' |
| 40 | + + 'written when the source changes) and point the dimension at that field."; the authoring ' |
| 41 | + + 'rules — the three CLI commands and the runtime dataset save (`422`) — answer ' |
| 42 | + + '`dimension-virtual-field-refused` (error) at `datasets[N].dimensions[M].field` or ' |
| 43 | + + '`analyticsCubes[N].dimensions.KEY.sql` with "groups by field "FIELD" (`formula` on object "OBJECT"), a value ' |
| 44 | + + 'computed on read and never stored, so no query can group by it" and the hint "Store the ' |
| 45 | + + 'value in a stored field of "OBJECT" (written when its source changes) and point this ' |
| 46 | + + 'dimension at that field, or remove the dimension." `os explain ' |
| 47 | + + 'dimension-virtual-field-refused` gives the reasoning. A dimension over a stored field and a ' |
| 48 | + + 'date or datetime dimension, with or without `dateGranularity`, are unchanged, as is every ' |
| 49 | + + 'measure verdict. ⚠️ The compile does not judge a dotted dimension (it answers for the base ' |
| 50 | + + 'object only); the lint rule and the query-time refusal still do, so sweep with `os validate`', |
| 51 | + relevantWhen: { kind: 'stack-declares', keys: ['datasets', 'analyticsCubes'] }, |
| 52 | +}; |
0 commit comments