|
32 | 32 | * the engine's groupBy door and its `min` / `max` door refuse it first. The |
33 | 33 | * aggregated column's type carries no `multiple` flag, and the rows below |
34 | 34 | * hold that it needs none. |
| 35 | + * - [#29304] Nor does a `formula` column: it is virtual (no stored value to |
| 36 | + * group), and the engine's groupBy storage door |
| 37 | + * (`assertGroupByTargetsAreStored`) refuses a group over it first. A |
| 38 | + * formula pair at `having` is refused there, before the verdict is asked. |
35 | 39 | * |
36 | 40 | * The `where` column is measured in `packages/rest` |
37 | 41 | * (`aggregation-filter-where-doors.test.ts`), where a real `SqlDriver` answers |
@@ -228,6 +232,10 @@ function expectedAt(position: Position, target: string, referent: string): Expec |
228 | 232 | // The `multiple` seam (pointer 5944816815): no aggregated column holds a list. |
229 | 233 | return { kind: 'refused first by', door: 'the groupBy door (a multi-value or JSON field is not grouped by)', code: 'INVALID_FIELD' }; |
230 | 234 | } |
| 235 | + if (position === 'having' && (FIELDS[target].type === 'formula' || FIELDS[referent].type === 'formula')) { |
| 236 | + // [#29304] No aggregated column holds a formula: a group over one is refused. |
| 237 | + return { kind: 'refused first by', door: 'the groupBy storage door (a formula is not grouped by)', code: 'INVALID_FIELD' }; |
| 238 | + } |
231 | 239 | if (position === 'aggregations[i].filter' && FIELDS[target].type === 'formula') { |
232 | 240 | // `where` meets the same door first: a formula is computed on read, never filtered on. |
233 | 241 | return { kind: 'refused first by', door: 'the materializable-filter door (a formula key)', code: 'INVALID_FIELD' }; |
@@ -420,16 +428,17 @@ describe('[#21299] the card\'s four measured shapes are refused before any read, |
420 | 428 | }); |
421 | 429 |
|
422 | 430 | it('…and at having, an addDays pair from a formula projection, which was answered: refused, naming the formula', async () => { |
| 431 | + // [#29304] The formula projection itself is refused now, at its groupBy |
| 432 | + // position, before `having` is read: no aggregated column holds a formula. |
423 | 433 | const { engine, calls } = await makeEngine(OBJ); |
424 | 434 | const out = await outcomeOf(() => engine.aggregate(OBJECT, { |
425 | 435 | groupBy: ['due_f', { field: 'due_on', dateGranularity: 'day', alias: 'due_day' }], |
426 | 436 | aggregations: [{ function: 'count', alias: 'n' }], |
427 | 437 | having: { due_f: { $lte: { $field: 'due_day', addDays: 1 } } }, |
428 | 438 | } as unknown as EngineAggregateOptions), () => []); |
429 | | - expect(out).toMatchObject({ refused: true, code: 'INVALID_FILTER', status: 400 }); |
| 439 | + expect(out).toMatchObject({ refused: true, code: 'INVALID_FIELD', status: 400 }); |
430 | 440 | expect(calls).toEqual({ aggregate: 0, find: 0 }); |
431 | | - expect(out.message).toContain('the target field "due_f" (type "formula")'); |
432 | | - expect(out.message).toContain('{ "$field": "due_day" } with addDays'); |
| 441 | + expect(out.message).toContain("groupBy.0 groups by 'due_f', but 'due_f' is a formula field"); |
433 | 442 | }); |
434 | 443 |
|
435 | 444 | it('the same-class control on the same object answers as before', async () => { |
|
0 commit comments