Skip to content

Commit a922779

Browse files
fix(service-analytics)!: the delegated fallback face refuses a date bucket over a formula or non-date field, as the engine face does (#29364) (#29500)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9XpkaL2vbksEkNq2jVX5pqa)_ Fixes #29364 Clause-②: no (narrowing) — a cube query or `/analytics/sql` dry run that `FallbackDelegateStrategy` hands to the host's fallback analytics service is refused `INVALID_FIELD` / 400 at `groupBy.N.dateGranularity` when it buckets a `formula` field or a field declared anything but a date or a datetime, with the engine face's refusal field for field, before the fallback service is called. Measured: on `origin/main` `aca58cdb` the fallback face answered 200 with one `null` group (formula, 3 of 3 rows) and a `null` group beside a parsed text value (text); on this head both are refused on the query and the dry run. Only a host composing the fallback face sees it; no shipped composition reaches that face. Nothing is widened: no export, public member, answer member, error code or status is added. Metadata-protocol: none Skills-docs: none — no file under `skills/**` or `content/docs` says the analytics fallback service can date-bucket a formula or a text field; the fallback face is not documented as an authoring surface. Card thread: `session_01ADHkmNhTaQLPMwKLDKtX46`. Seat ruling: option A, record 6581612223 (on the dev's measurement and options, os-dev-report 6581581002). ## 维护者速读 - **改了什么**:分析服务的「后备委托」出口(`FallbackDelegateStrategy`,把查询转交给宿主注册的另一个分析服务,例如内存驱动的 `MemoryAnalyticsService`)现在也先过同一道日期分桶门:按日期粒度对公式字段或非日期字段分桶,查询和 `/analytics/sql` 预演都给出与引擎出口逐字段相同的拒绝(`INVALID_FIELD` / 400,位置 `groupBy.N.dateGranularity`),不再把全部行装进一个空(null)分组答 200。 - **为什么改**:卡 #29364(p3),来自 #29167 合约评审的发现。实测:默认组装下这个出口走不到(自动挂载的插件总把分桶查询交给引擎,引擎早已拒绝);但公开 API 能走到(`new AnalyticsService({ fallbackService })`,或插件配 `objectqlAggregate: false`),席位裁定 A:复用现成的那道门,不加第三份文字、不碰 spec。 - **风险与回滚**:收窄(标题带 `!`),只影响自行组装后备出口的宿主;日期、日期时间分桶照常委托(已钉住);宿主没给字段类型时不判,与草稿预览、预演一致。回滚即 revert。 - **先看**:① `packages/services/service-analytics/src/analytics-service.ts` 里新的 `assertDelegatedDateBucketsTemporal` 及 `FallbackDelegateStrategy` 两处调用;② 新测试 `src/__tests__/fallback-delegate-date-bucket-type.test.ts`(与真实 ObjectQL + SQLite 引擎出口逐字段比对);③ changeset。 - **两分钟验证**:`pnpm --filter @objectstack/service-analytics exec vitest run src/__tests__/fallback-delegate-date-bucket-type.test.ts`,预期 1 个文件 9 passed。 - **需要你做的**:无,席位跑合约评审并落地。 ## What changes - **`@objectstack/service-analytics`, `analytics-service.ts`.** `FallbackDelegateStrategy.execute` and `.generateSql` call a new module-local `assertDelegatedDateBucketsTemporal(query, ctx)` before handing the query to `ctx.fallbackService`. It makes the one call to the service's existing door, `assertDatasetDateBucketsTemporal` (`dataset-date-bucket-door.ts`), with the keys the ObjectQL strategy's direct path would build (`aggregateGroupKeys`, so positions are the engine's), the cube's object (`aggregateObjectOf`) and the context's `declaredFieldType` (the host's `sourceFieldMeta`; `AnalyticsServicePlugin` answers it from the data engine). No third copy of the sentence, no new error code, no spec edit. - **`dataset-date-bucket-door.ts`.** Doc comment only: names the fallback face as the third face that hands no engine the keys. - **Changeset** `.changeset/29364-fallback-date-bucket-refused-alike.md`: patch, BREAKING banner, one ADR-0087 marker (`not-required (no-migration-prescription)`), and it says only a host composing the fallback face sees the change. ## Why #29167 (PR #29347) made the engine door, the draft preview and the dry run refuse a date bucket over a virtual or non-date field alike. The delegated fallback service folds a bucket itself and reads no field type, so it stayed the one face answering 200 with a `null` group. Step 0 measured reachability before any code (os-dev-report 6581581002): | composition | formula month bucket | text month bucket | datetime (control) | |:--|:--|:--|:--| | `new AnalyticsService({ fallbackService: MemoryAnalyticsService })`, with or without `sourceFieldMeta` | 200, `[{calc: null, count: 3}]` | 200, `[{region: null, count: 2}, {region: '2026-03', count: 1}]` | 200, right buckets | | `AnalyticsServicePlugin` + pre-registered `MemoryAnalyticsService`, no data engine | 503 at the exposure door | 503 | 503 | | same + data engine, default capabilities | engine (ObjectQLStrategy) | engine | engine | | same + `queryCapabilities` with `objectqlAggregate: false` | 200, one `null` group | 200, as row 1 | 200, right buckets | No shipped composition reaches the face; the public construction paths do, and the seat ruled the fix (A) on that. ## Tests New file `packages/services/service-analytics/src/__tests__/fallback-delegate-date-bucket-type.test.ts`, 9 cases. The engine face is the default composition on real ObjectQL + SqlDriver (better-sqlite3); the fallback faces are both public construction paths with a recording delegate: - On `new AnalyticsService({ fallbackService })` and on `AnalyticsServicePlugin` with `objectqlAggregate: false`: a formula by month, a text column by month, and a formula after a datetime bucket (`groupBy.1`) are each refused on the query AND the dry run with exactly the engine face's refusal (message, code, status, httpStatus, object, param, path, field, fields), and the delegate's `query` / `generateSql` are never called. - Control on both faces: a datetime month bucket is delegated (rows passed through, dry run returns the delegate's statement). - A host with no `sourceFieldMeta` is not judged (delegated), as on the preview and the dry run. No existing test was edited (no forced test edits). Ablation (the door taken out, measured, restored; `node scripts/ablation-replace.mjs`, which proves the mutation on disk and the restore by blob and `git diff HEAD`). The suite imports `src` relatively, so no `dist` leg applies. <details><summary>Ablation readings</summary> - Leg 1, whole door (helper returns before judging), head `1074fbba`: `Tests 6 failed | 3 passed (9)`, first failure `Error: fallback query: expected a refusal, but it resolved`; the three still green are the two controls and the no-types case. Restored: `ok restored: blob == HEAD (362478f) and git diff HEAD is empty`. - Leg 2, dry-run call only (`generateSql`), head `cf460c16` (same runtime code; `1074fbba` changed only a type cast): `Tests 6 failed | 3 passed (9)`, failure `Error: fallback sql: expected a refusal, but it resolved`. Restored, `git diff HEAD` empty. </details> ## Acceptance notes - The door judges only when the host gives field types (`sourceFieldMeta`), the same stand-down the preview and the dry run have; the plugin always wires it from the data engine. A host constructing `AnalyticsService` without it keeps today's delegated answer (pinned). - Only the date-bucket door is put in front of the delegate, as the ruling orders. The column-asked-twice door (`assertDatasetGroupColumnsDistinct`) the preview also runs is not added here. ## Verification All readings on head `1074fbba`, worktree based on `origin/main` `aca58cdb` (`origin/main` has since moved 11 commits, none in `packages/services/service-analytics`). - `pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2`: `Test Files 208 passed (208)`, `Tests 4950 passed | 282 skipped (5232)`, lock VERDICT command-exit 0. - `pnpm --filter @objectstack/service-analytics typecheck`: exit 0 (lock VERDICT command-exit 0). - `pnpm --filter @objectstack/driver-memory exec vitest run --maxWorkers=2` (the delegate's own analytics tests): `Test Files 74 passed (74)`, `Tests 1767 passed (1767)`. - Lint: the package has no `lint` script; root `eslint --no-inline-config packages/services/service-analytics`: exit 0. - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`: 62 commands, every one run, `--ran` reconciliation `62 derived, 62 run, 0 NOT-MEASURED, 0 UNRUN`. Three first answered exit 3 (prerequisite, not a verdict) and were re-run green: `check-plugin-teardown-shape.mjs --self-test` after fetching its pinned fixture commit, `check:dual-build-cjs-loads` after `turbo run build --filter='./packages/**'` (78/78), and `check:type-check-debt`, whose lock call waited behind this card's own dogfood run. <details><summary>Full dogfood battery (the narrowing arm), head 1074fbb</summary> `pnpm --filter @objectstack/dogfood test` under the lock after the `@objectstack/dogfood^...` closure build (68/68): `Test Files 2 failed | 395 passed | 3 skipped (400)`, `Tests 4 failed | 3261 passed | 28 skipped (3293)`, VERDICT command-exit 1. The two red files are `test/flow-runas.dogfood.test.ts` (3 cases, `RECORD_NOT_FOUND` 404 on the flow trigger) and `test/declarative-endpoint-anonymous-guest.dogfood.test.ts` (1 case). Neither reads analytics. Base leg: with `packages/services/service-analytics/src` restored to `aca58cdb` and its dist rebuilt (the door absent from dist, grep count 0), the same two files answer the same `4 failed | 8 passed (12)`, so they are red on base and not caused by this diff. Both files were re-pointed on `main` after the base by `6af3d2957` (#29451, "re-point the runAs and anonymous-guest flow pins to flow start admission's record rule"). The tree was restored (`git diff HEAD` empty) and the head dist rebuilt (door present, count 3). </details> Human Minimum: 1 n/a (no spec) · 2 yes · 3 yes (no formatter; lint exit 0) · 4 yes · 5 yes · 6 n/a · 7 yes · 8 yes. --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmNhTaQLPMwKLDKtX46)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c88467d commit a922779

4 files changed

Lines changed: 281 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/service-analytics': patch
3+
---
4+
5+
fix(service-analytics)!: the delegated fallback face refuses a date bucket over a formula or a field that is not a date, as the engine face does (#29364)
6+
7+
Clause-②: no (narrowing) — a cube query (or `/analytics/sql` dry run) that `FallbackDelegateStrategy` hands to the host's fallback analytics service is refused `INVALID_FIELD` / 400 at `groupBy.N.dateGranularity` when it buckets a `formula` field, or a field declared anything but a date or a datetime, with the engine face's refusal field for field, before the fallback service is called. It answered 200 with one `null` group before. Only a host that composes the fallback face sees the change; no shipped composition reaches it. Nothing is widened: no export, public member, answer member, error code or status is added.
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export or type changes: the analytics service's existing date-bucket door, already in front of the engine, the draft preview and the dry run, now also stands in front of the delegated fallback service. A refused query is fixed in the query (or by storing the value on a date or datetime field), so there is nothing for a migration to rewrite and no tombstone. -->
11+
12+
**BREAKING** accept-set narrowing on the analytics fallback face (`@objectstack/service-analytics`), for hosts that compose it.
13+
14+
- **Who sees it.** Only a host that composes the fallback face: `new AnalyticsService({ fallbackService })`, or `AnalyticsServicePlugin` capturing an analytics service registered before it (for example `MemoryAnalyticsService` from `@objectstack/driver-memory`) under a `queryCapabilities` override with `objectqlAggregate: false`. The default composition sends every bucketed query to the engine, which already refuses these, and is unchanged.
15+
- **Before.** The fallback service folded the bucket itself and read no field type. `MemoryAnalyticsService` put every row into one `null` group for a `formula` bucket, and a `null` group beside whatever text parsed as a date for a `text` bucket, under an ordinary 200. The dry run handed back the fallback service's statement.
16+
- **Now.** Both the query and the dry run answer the engine's refusal (`INVALID_FIELD` / 400, `param: 'groupBy'`, `path: 'groupBy.N.dateGranularity'`, the same message), and the fallback service is not called. The field's type is read from the host's `sourceFieldMeta`, which `AnalyticsServicePlugin` answers from the data engine.
17+
- **Unchanged.** A date or datetime bucket is delegated as before. A host that wired no field types (`sourceFieldMeta`) is not judged, as on the draft preview and the dry run.
18+
19+
**The remedy.** Bucket a date or datetime field. For a formula, store the value on a date or datetime field written when its source changes, and bucket that.
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#29364] The delegated fallback face (`FallbackDelegateStrategy`) refuses a
5+
* date bucket over a field that is not a date or a datetime, as the engine face
6+
* refuses it, field for field.
7+
*
8+
* ## The shape this closes
9+
*
10+
* `FallbackDelegateStrategy` hands a cube query to the host's fallback
11+
* `IAnalyticsService` (`MemoryAnalyticsService` from `@objectstack/driver-memory`
12+
* is the in-repo one), which folds a bucketed time dimension itself and reads
13+
* no field type. Measured on `origin/main` `aca58cdb` with
14+
* `MemoryAnalyticsService` as the delegate, a month bucket over:
15+
*
16+
* | field | the fallback face answered |
17+
* |:--|:--|
18+
* | `formula` (virtual: no stored column) | 200, one `null` group holding every row |
19+
* | `text` | 200, a `null` group beside whatever text parsed as a date |
20+
* | `datetime` (the control) | 200, the right buckets |
21+
*
22+
* while the engine face (the default composition: real ObjectQL + SqlDriver on
23+
* SQLite) refused the first two with `INVALID_FIELD` / 400 at
24+
* `groupBy.N.dateGranularity`. No shipped composition reaches this face; the
25+
* public construction paths do, and both are pinned below:
26+
* `new AnalyticsService({ fallbackService })`, and `AnalyticsServicePlugin`
27+
* capturing a pre-registered analytics service under a `queryCapabilities`
28+
* override with `objectqlAggregate: false`.
29+
*
30+
* The delegate here is a recording double: the pin is the service's face (the
31+
* refusal, and that the delegate was never called), not the delegate's fold.
32+
*/
33+
34+
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
35+
import { ObjectQL } from '@objectstack/objectql';
36+
import { SqlDriver } from '@objectstack/driver-sql';
37+
import type { Cube } from '@objectstack/spec/data';
38+
import type { AnalyticsResult, IAnalyticsService } from '@objectstack/spec/contracts';
39+
import { AnalyticsService } from '../analytics-service.js';
40+
import { AnalyticsServicePlugin } from '../plugin.js';
41+
import { installDefaultOrganization } from './default-organization.testkit.js';
42+
43+
const DEAL = 'os29364_deal';
44+
const CUBE = 'os29364_cube';
45+
46+
const CUBES = [
47+
{
48+
name: CUBE,
49+
title: 'Fallback date bucket cube',
50+
sql: DEAL,
51+
public: true,
52+
measures: { amount_sum: { type: 'sum', sql: 'amount', label: 'Amount' } },
53+
dimensions: {
54+
calc: { type: 'time', sql: 'calc', label: 'Calc' },
55+
region: { type: 'time', sql: 'region', label: 'Region' },
56+
closed_at: { type: 'time', sql: 'closed_at', label: 'Closed at' },
57+
},
58+
},
59+
] as unknown as Cube[];
60+
61+
const quiet = { debug() {}, info() {}, warn() {}, error() {}, child() { return quiet; } };
62+
63+
type Query = Record<string, unknown>;
64+
const bucket = (...dims: Array<[dimension: string, granularity: string]>): Query => ({
65+
cube: CUBE,
66+
measures: [`${CUBE}.amount_sum`],
67+
timeDimensions: dims.map(([d, granularity]) => ({ dimension: `${CUBE}.${d}`, granularity })),
68+
});
69+
70+
/** The rows and statement the recording delegate answers with. */
71+
const DELEGATED: AnalyticsResult = {
72+
rows: [{ [`${CUBE}.closed_at`]: '2026-03', [`${CUBE}.amount_sum`]: 10 }],
73+
fields: [{ name: `${CUBE}.closed_at`, type: 'string' }, { name: `${CUBE}.amount_sum`, type: 'number' }],
74+
};
75+
const DELEGATED_SQL = { sql: 'SELECT 1 -- delegated', params: [] as unknown[] };
76+
77+
function recordingDelegate() {
78+
return {
79+
query: vi.fn(async () => DELEGATED),
80+
generateSql: vi.fn(async () => DELEGATED_SQL),
81+
getMeta: vi.fn(async () => []),
82+
};
83+
}
84+
85+
/** The refusal `p` rejects with, as the keys a caller reads; a resolution fails the case. */
86+
const refusalOf = async (face: string, p: Promise<unknown>) => {
87+
const err = (await p.then(
88+
() => { throw new Error(`${face}: expected a refusal, but it resolved`); },
89+
(e: unknown) => e,
90+
)) as Error & Record<string, unknown>;
91+
return {
92+
message: err.message, code: err.code, status: err.status, httpStatus: err.httpStatus,
93+
object: err.object, param: err.param, path: err.path, field: err.field, fields: err.fields,
94+
};
95+
};
96+
97+
describe('[#29364] the fallback face refuses a date bucket over a field that is not a date, as the engine face does', () => {
98+
let engine: ObjectQL;
99+
/** The engine face: the default composition, no `queryCapabilities` override. */
100+
let engineFace: AnalyticsService;
101+
102+
/** A field's declaration on the engine, as the plugin's `sourceFieldMeta` reads it. */
103+
const fieldMeta = (object: string, field: string) => {
104+
const f = (engine as unknown as { getObject(o: string): { fields?: Record<string, { type?: string }> } | undefined })
105+
.getObject(object)?.fields?.[field];
106+
return f ? { type: f.type } : undefined;
107+
};
108+
109+
beforeAll(async () => {
110+
const driver = new SqlDriver({ client: 'better-sqlite3', connection: { filename: ':memory:' }, useNullAsDefault: true } as never);
111+
engine = new ObjectQL({ logger: quiet } as never);
112+
engine.registerDriver(driver as never, true);
113+
await engine.init();
114+
engine.registry.registerObject({
115+
name: DEAL,
116+
label: 'Deal',
117+
fields: {
118+
region: { name: 'region', type: 'text' },
119+
amount: { name: 'amount', type: 'number' },
120+
closed_at: { name: 'closed_at', type: 'datetime' },
121+
closed_on: { name: 'closed_on', type: 'date' },
122+
// A formula the table stores no column for, whose result is a date.
123+
calc: { name: 'calc', type: 'formula', expression: 'closed_on', returnType: 'date' },
124+
},
125+
} as never);
126+
await engine.syncSchemas();
127+
await installDefaultOrganization(engine as never);
128+
await engine.insert(DEAL, {
129+
id: 'd1', region: 'amer', amount: 10, closed_at: '2026-03-01T00:00:00.000Z', closed_on: '2026-03-02',
130+
} as never);
131+
132+
const registered: Record<string, unknown> = {};
133+
await new AnalyticsServicePlugin({ cubes: CUBES } as never).init({
134+
getService: (name: string) => (name === 'data' ? engine : registered[name]),
135+
registerService: (name: string, svc: unknown) => { registered[name] = svc; },
136+
replaceService: (name: string, svc: unknown) => { registered[name] = svc; },
137+
hook: () => {},
138+
logger: quiet,
139+
} as never);
140+
engineFace = registered.analytics as AnalyticsService;
141+
});
142+
143+
afterAll(async () => {
144+
try { await engine?.destroy(); } catch { /* noop */ }
145+
});
146+
147+
/** `new AnalyticsService({ fallbackService })` with the host's field types. */
148+
const constructedFace = () => {
149+
const delegate = recordingDelegate();
150+
const face = new AnalyticsService({
151+
cubes: CUBES,
152+
logger: quiet as never,
153+
fallbackService: delegate as unknown as IAnalyticsService,
154+
sourceFieldMeta: fieldMeta,
155+
} as never);
156+
return { face, delegate };
157+
};
158+
159+
/** `AnalyticsServicePlugin` capturing a pre-registered analytics service, `objectqlAggregate: false`. */
160+
const pluginFace = async () => {
161+
const delegate = recordingDelegate();
162+
const registered: Record<string, unknown> = { analytics: delegate };
163+
await new AnalyticsServicePlugin({
164+
cubes: CUBES,
165+
queryCapabilities: () => ({ nativeSql: false, objectqlAggregate: false, inMemory: false }),
166+
} as never).init({
167+
getService: (name: string) => (name === 'data' ? engine : registered[name]),
168+
registerService: (name: string, svc: unknown) => { registered[name] = svc; },
169+
replaceService: (name: string, svc: unknown) => { registered[name] = svc; },
170+
hook: () => {},
171+
logger: quiet,
172+
} as never);
173+
return { face: registered.analytics as AnalyticsService, delegate };
174+
};
175+
176+
const FACES = [
177+
['new AnalyticsService({ fallbackService })', constructedFace],
178+
['AnalyticsServicePlugin, objectqlAggregate: false', pluginFace],
179+
] as const;
180+
181+
const REFUSED: Array<[label: string, query: Query, field: string, path: string]> = [
182+
['a formula by month', bucket(['calc', 'month']), 'calc', 'groupBy.0.dateGranularity'],
183+
['a text column by month', bucket(['region', 'month']), 'region', 'groupBy.0.dateGranularity'],
184+
['a formula after a datetime bucket', bucket(['closed_at', 'year'], ['calc', 'month']), 'calc', 'groupBy.1.dateGranularity'],
185+
];
186+
187+
for (const [faceLabel, makeFace] of FACES) {
188+
describe(faceLabel, () => {
189+
it.each(REFUSED)('refuses %s with the engine face\'s refusal, on the query and the dry run, and never calls the delegate', async (_l, query, field, path) => {
190+
const { face, delegate } = await makeFace();
191+
const asEngine = await refusalOf('engine', engineFace.query({ ...query } as never));
192+
// The engine face's own refusal, so a reader can see what is being matched.
193+
expect(asEngine).toMatchObject({ code: 'INVALID_FIELD', status: 400, object: DEAL, param: 'groupBy', path, field, fields: [field] });
194+
195+
expect(await refusalOf('fallback query', face.query({ ...query } as never)), 'the fallback query vs the engine face').toEqual(asEngine);
196+
expect(await refusalOf('fallback sql', face.generateSql({ ...query } as never)), 'the fallback dry run vs the engine face').toEqual(asEngine);
197+
expect(delegate.query).not.toHaveBeenCalled();
198+
expect(delegate.generateSql).not.toHaveBeenCalled();
199+
});
200+
201+
it('serves a datetime bucket through the delegate, as before (the control)', async () => {
202+
const { face, delegate } = await makeFace();
203+
const query = bucket(['closed_at', 'month']);
204+
const result = await face.query({ ...query } as never);
205+
expect(delegate.query).toHaveBeenCalledTimes(1);
206+
expect(result.rows).toEqual(DELEGATED.rows);
207+
expect(await face.generateSql({ ...query } as never)).toEqual(DELEGATED_SQL);
208+
expect(delegate.generateSql).toHaveBeenCalledTimes(1);
209+
});
210+
});
211+
}
212+
213+
it('does not judge a bucket the host gave no field type for (no sourceFieldMeta), as the preview and the dry run', async () => {
214+
const delegate = recordingDelegate();
215+
const face = new AnalyticsService({
216+
cubes: CUBES,
217+
logger: quiet as never,
218+
fallbackService: delegate as unknown as IAnalyticsService,
219+
} as never);
220+
await face.query({ ...bucket(['calc', 'month']) } as never);
221+
expect(delegate.query).toHaveBeenCalledTimes(1);
222+
});
223+
});

‎packages/services/service-analytics/src/analytics-service.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5009,6 +5009,36 @@ export function inferredCallerMeasureSql(measure: string, cubeName: string): str
50095009
return inferMeasure(key, { member: measure, cube: cubeName }).sql;
50105010
}
50115011

5012+
/**
5013+
* [#29364] The service's date-bucket door (`dataset-date-bucket-door.ts`) in
5014+
* front of the delegated service, on both the query and the dry run.
5015+
*
5016+
* The delegate (`MemoryAnalyticsService` is the in-repo one) folds a bucketed
5017+
* time dimension itself and reads no field type, so on `origin/main` `aca58cdb`
5018+
* a month bucket over a `formula` answered 200 with one `null` group holding
5019+
* every row, and over a `text` column one `null` group beside whatever text
5020+
* happened to parse as a date — while the engine face refused both. It is
5021+
* judged here with the keys the ObjectQL strategy's direct path would build
5022+
* and the context's `declaredFieldType` (the host's `sourceFieldMeta`), so this
5023+
* face answers the engine's refusal field for field. A host that wired no
5024+
* field types is not judged, as on the preview and the dry run.
5025+
*
5026+
* Reached by no shipped composition (the auto-mounted plugin always bridges
5027+
* `executeAggregate`, so every bucketed query goes to the engine); reached by
5028+
* a host composing `new AnalyticsService({ fallbackService })`, or a
5029+
* `queryCapabilities` override with `objectqlAggregate: false`.
5030+
*/
5031+
function assertDelegatedDateBucketsTemporal(query: AnalyticsQuery, ctx: StrategyContext): void {
5032+
const cube = ctx.getCube(query.cube!);
5033+
if (!cube) return;
5034+
const object = aggregateObjectOf(cube);
5035+
assertDatasetDateBucketsTemporal(
5036+
object,
5037+
aggregateGroupKeys(query, cube),
5038+
(field) => (ctx as DatasetScopedStrategyContext).declaredFieldType?.(object, field),
5039+
);
5040+
}
5041+
50125042
/**
50135043
* FallbackDelegateStrategy — Internal strategy for fallback service delegation.
50145044
*
@@ -5026,10 +5056,12 @@ class FallbackDelegateStrategy implements AnalyticsStrategy {
50265056
}
50275057

50285058
async execute(query: AnalyticsQuery, ctx: StrategyContext): Promise<AnalyticsResult> {
5059+
assertDelegatedDateBucketsTemporal(query, ctx);
50295060
return ctx.fallbackService!.query(query);
50305061
}
50315062

50325063
async generateSql(query: AnalyticsQuery, ctx: StrategyContext): Promise<{ sql: string; params: unknown[] }> {
5064+
assertDelegatedDateBucketsTemporal(query, ctx);
50335065
if (ctx.fallbackService?.generateSql) {
50345066
return ctx.fallbackService.generateSql(query);
50355067
}

‎packages/services/service-analytics/src/dataset-date-bucket-door.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
* missing-column backstop. All three now answer the engine's
3838
* `INVALID_FIELD` / 400 at `groupBy.N.dateGranularity`, field for field.
3939
*
40+
* [#29364] …and a third face that hands no engine the keys: the delegated
41+
* fallback service behind `FallbackDelegateStrategy`, which folds a bucket in
42+
* memory and read no field type. It is judged with the keys the strategy's
43+
* direct path would build and the strategy context's `declaredFieldType`, on
44+
* both its query and its dry run (`analytics-service.ts`,
45+
* `assertDelegatedDateBucketsTemporal`).
46+
*
4047
* Why a copy of the sentence: `@objectstack/objectql` is a dev dependency of
4148
* this package, never a runtime one, and its root does not export the door.
4249
* The message, code, status and keys are the engine's, and

0 commit comments

Comments
 (0)