Repository navigation
fix(service-analytics): a date-dimension series answers every bucket of its window, the empty ones included - #27109
Conversation
…of its window, the empty ones included A grouped query answers one row per bucket that holds rows, so a month with no closed-won deal disappeared from a 12-month revenue trend and the chart drew its neighbours side by side. The dataset executor now invents the missing buckets from its own calendar helpers (bucketOrdinalOfDay, bucketKeyAtOrdinal), inside the time dimension's dateRange window, or between the first and last bucket returned when no window is stated; fillEmptyGroups then gives them the empty-group value (count/sum 0, avg/min/max unset). A limit/offset, an order on a measure and compareTo skip the fill, and a fill past 2,000 grid rows does not run at all. Claude-Session: https://claude.ai/code/session_01FEkQ5poCcDpczhMAcc1W8M Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5poCcDpczhMAcc1W8M Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift Check8 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run. What this run could not see
Coarse fallback — 10 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin e2e3b2581efd91f9d7615b19707177f77a5e7fc6 && git checkout e2e3b2581efd91f9d7615b19707177f77a5e7fc6
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin a27f889a0508a8c27c0e3b8bfa7ae844ccd4764d 32cdaee790422299976f49e2a125fb1ca1fadb79 && git checkout -B drift-repro a27f889a0508a8c27c0e3b8bfa7ae844ccd4764d && git merge --no-ff 32cdaee790422299976f49e2a125fb1ca1fadb79
node scripts/docs-audit/affected-docs.mjs --json a27f889a0508a8c27c0e3b8bfa7ae844ccd4764d |
席位核对ACCEPT · The maintainer's standing authorisation for landing reviewed PRs, verbatim: 「按照 pm-dispatch 规则复核过的都授权」.
Generated by Claude Code |
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5msvniAz5h2mP2QABA
Requested by Leehom · project thread
Fixes #26893
Clause-②: no
Metadata-protocol: none
维护者速读
POST /api/v1/analytics/dataset/query),现在会把窗口内没有记录的月/日/周补成空桶返回:count、sum 为 0,avg/min/max 不给值。有dateRange时补满整个窗口;没有dateRange时只补首尾之间的空缺。dataset-executor.ts的后处理,不动 SQL;带limit/offset、按度量排序、compareTo的查询不补;补完超过 2000 行的不补(整体不补,绝不补一半)。回滚即 revert。packages/services/service-analytics/src/dataset-executor.ts的fillEmptyTimeBuckets与timeBucketFillPlan;src/__tests__/dataset-time-bucket-zero-fill.test.ts。pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2 src/__tests__/dataset-time-bucket-zero-fill.test.ts,预期 21/21 通过。What changes
DatasetExecutor.executeSelectiongains one step, after the measure-scoped andcompareTomerges and before the empty-group fill:fillEmptyTimeBucketsinvents a row for every time bucket the grouped query emitted none for. The bucket is placed withbucketOrdinalOfDayand spelled withbucketKeyAtOrdinal(core'sbucketDateKey, the labeller the grouping uses), the same helperscompareToalignment counts with. No second date walker; nothing underui/.timeDimensions[].dateRangewindow, in the zonebuildQueryresolves the query in. A preset goes through the loweringcompareTouses (lowerDatasetCompareDateRange+inclusiveCalendarDayWindow); an explicit pair is read bound by bound (a bare day is that day, an instant is its day in the reference zone). With nodateRange, only the gaps between the first and last bucket returned. ⛔ Never beyond what is known: no window and no rows answer no rows.fillEmptyGroupsthen gives its measures what an empty group already reads throughemptyGroupValueFor:0for count/sum, avg/min/max left unset. No second empty-value table.fillEmptyGroups' docblock now names the one place a row is invented.limitoroffset; anorderon anything but a dimension (a measure,__comparecolumn or derived measure); acompareTo; a grid with two bucketed time dimensions; an axis key that is not a bucket key of the granularity.MAX_ZERO_FILLED_GRID_ROWS = 2000(window buckets × combinations). Past it the fill does not run at all, never a partial fill. 2,000 lets adayaxis span five years as one series and stops adayaxis over ten years. Not re-exported from the package index, so the public surface is unchanged.Seat rulings, as measured
src/index.ts, no type change, no input refused:Clause-②: no,Metadata-protocol: none,patch.dateRangeis read.runtimeFilteris NOT: measured, no server seam lowers a filter into a window (the only reader of a closed bound pair,extractDateWindows/boundedDateWindow, lives inui/packages/plugin-dashboard/src/DatasetWidget.tsx;grepoverpackages/services/service-analytics/srcandpackages/core/srcfinds none), and HotCRM's two filed widgets carry a ONE-bound filter (executive.dashboard.tsrevenue_trend:close_date: { $gte: '{12_months_ago}' };service.dashboard.tsdaily_case_volume:created_at: { $gte: '{30_days_ago}' }, on hotcrm173b488), so there is no closed pair to read anyway. Those series get their interior gaps filled, which is exactly the filed May/August and Sep 30/Oct 1 gaps.Tests
src/__tests__/dataset-time-bucket-zero-fill.test.ts(21): served through the realAnalyticsServicePlugin, a realObjectQLengine andSqliteWasmDriver. Month series over a 12-month explicit window with May/August empty → 12 rows in order, count/sum 0, avg unset; a wider window fills the edges and adds no field; a preset (this_year, frozen clock); week keys across the 2025/2026 ISO week-year; day series with the 30-day window only inruntimeFilter→ interior gaps only; HotCRM's one-bound filter → May/August filled, nothing before March; no window + no rows → none; window + no rows → the window's buckets; month × owner → each owner filled, an owner with no row not invented; non-UTC pin:Asia/Shanghai,last_7_daysfrozen at2026-03-06T20:00Z→ eight Shanghai days ending2026-03-07(the UTC calendar would end on the 6th), the real row keyed2026-03-05by the query and not re-invented. Controls: full window unchanged, top-N, measure order, limit, no time dimension,compareTo(previousYear, the two empty months stay absent), the bound (day over ten years untouched). Unit: null bucket kept, non-bucket key declines, bound exact at 2,000 / 2,001.#26893comment):aggregate-datetime-measure-refusal.test.ts(its double keyed the row by the dimension name, so it landed in the null bucket; now keyed by the field as the engine answers → 12 months, May 3),bucket-key-readers-four-digit-year.test.ts(pins the two real keys; the year axis gains 1,975 empty years, finer ones exceed the bound),dataset-time-axis-order.test.ts(+2026-Q2),dataset-window-timedimension-bucketing.test.ts(+ u2 February at 0),drill-sidecars-emission.test.ts(four grid rows).packages/qa/dogfood/test/analytics-timezone.dogfood.test.ts(claim amendment 6461493732): underAmerica/Los_Angeles,2024-03-01lies between the boundary leads and the seed's own, so it is now present at0; assertedtoBe(0)exactly, so an absent bucket (the base behaviour) still reds it.Live red/green through the REST door (app-crm, opportunity_metrics)
pnpm dev:crm -- --fresh, signed in as the dev admin,POST /api/v1/analytics/dataset/querywithdatasetName: opportunity_metrics. Red = base blob ofdataset-executor.ts(fbc16563) written over the file and@objectstack/service-analyticsrebuilt (dist markerMAX_ZERO_FILLED_GRID_ROWS: 0 hits); green = HEAD rebuilt (2 hits); restore proven bygit diff HEADempty and the blob hash equal to HEAD's.A — month,
dateRange: ['2025-11-01','2026-10-31'],runtimeFilter: { stage: 'closed_won' }:B — HotCRM
revenue_trendshape,runtimeFilter: { stage: 'closed_won', close_date: { $gte: '{12_months_ago}' } }:C — top-N control (
order: { total_amount: 'desc' }, limit: 3): 2 rows on both, identical.The dogfood file above is red on the base dist (
expected 0, received undefined, 1 failed / 1 passed) and green on HEAD (2/2).Acceptance notes
compareTodrops empty buckets too (measured, not widened into): a bucket empty in both windows stays absent (compareTo keeps its shapecontrol: May–August vs previous year answers only June and July). A bucket empty only in the current window already appears through the comparison merge. Filling undercompareTois a separate change.revenue_trendasks{ $gte: '{12_months_ago}' }with no upper bound, so a trailing-twelve-months chart whose earliest months are empty still starts at its first deal. Bounding that edge needs the widget to state its window (adateRange, or a closed pair the server could read); the order rules that the server does not read a window out ofruntimeFilter.nulls.Verification
All at head
32cdaee7.pnpm --filter @objectstack/service-analytics test: 192 files, 4668 passed / 282 skipped, VERDICT command-exit 0.pnpm --filter @objectstack/service-analytics typecheck+packages/qa/dogfoodtsc --noEmit: exit 0.eslint --no-inline-config packages/services/service-analytics/src packages/qa/dogfood/test/analytics-timezone.dogfood.test.ts: exit 0.@objectstack/service-analytics):@objectstack/restanalytics dataset suites (5 files, 83/83),@objectstack/runtimeanalytics-authored-cube-format-granularity.test.ts(3/3), and every dogfood file that posts a dataset query (9 files +empty-group-bucket-parity.test.ts, 96 tests; the one red was the timezone file above, then fixed).node scripts/pm/dispatch-gates.mjs --commands: 63 derived families, all run, all exit 0 (check-plugin-teardown-shape --self-testafter the documentedgit fetch --depth=1of its fixture commit);--ranreconciliation: 63 derived, 63 run, 0 NOT-MEASURED.test:repo(the diff touches no repo-project test; CI's Test Core runs it); the full dogfood battery (no!, no(narrowing)arm).Generated by Claude Code