Repository navigation
fix(service-analytics): a compareTo dataset answer fills the time buckets empty in both windows - #27213
Conversation
…kets empty in both windows Lift timeBucketFillPlan's compareTo early return so a compareTo answer gets the same zero-fill plan a plain series gets, over the primary window. The __compare columns were already in the empty-group fill, so a filled row reads 0 for count/sum and leaves avg/min/max unset on both sides. Claude-Session: https://claude.ai/code/session_01FEkQ5mEZzWjC6chaa9yue6 Co-authored-by: Claude <noreply@anthropic.com>
… days the fill now adds; changeset Claude-Session: https://claude.ai/code/session_01FEkQ5mEZzWjC6chaa9yue6 Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift Check2 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 3795b2ef00fe43abf7a173bddef132985f2515ca && git checkout 3795b2ef00fe43abf7a173bddef132985f2515ca
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 9dacccf96127755bd196e1844ce5c4cd61717d57 48871d4f71f4250a903fed0d873a3872915afeea && git checkout -B drift-repro 9dacccf96127755bd196e1844ce5c4cd61717d57 && git merge --no-ff 48871d4f71f4250a903fed0d873a3872915afeea
node scripts/docs-audit/affected-docs.mjs --json 9dacccf96127755bd196e1844ce5c4cd61717d57 |
…reTo as unfilled Claude-Session: https://claude.ai/code/session_01FEkQ5mEZzWjC6chaa9yue6 Co-authored-by: Claude <noreply@anthropic.com>
…angeset states that it supersedes its compareTo line Claude-Session: https://claude.ai/code/session_01FEkQ5mEZzWjC6chaa9yue6 Co-authored-by: Claude <noreply@anthropic.com>
席位核对ACCEPT · The maintainer's standing authorisation for landing reviewed PRs, verbatim: 「按照 pm-dispatch 规则复核过的都授权」.
Generated by Claude Code |
Requested by Leehom · project thread
Fixes #27111
Clause-②: no
Metadata-protocol: none
维护者速读
compareTo(同比/环比)的数据集查询,现在也会补上“两个时间段都没有数据”的时间桶:计数和求和读0(本期列和__compare对照列都是),平均/最小/最大不写这个键。生产代码只删了一处:timeBucketFillPlan里对compareTo的提前返回,补零沿用 Time-series charts drop empty date buckets and draw straight through them (a month with 0 revenue disappears from a 12-month trend) #26893 的同一套规则。compareTo被刻意跳过。同比趋势图里,两年都空的月份仍然缺失,图表把它两边的月份画成相邻。compareTo的查询上生效;任一窗口有数据的桶、limit/offset、按度量或__compare列排序、2,000 行上限等守卫都不变,普通序列逐字节不变。回滚即 revert。packages/services/service-analytics/src/dataset-executor.ts(timeBucketFillPlan的一行与其文档注释);packages/services/service-analytics/src/__tests__/dataset-time-bucket-zero-fill.test.ts(新的两个[#27111]describe 块)。pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2 src/__tests__/dataset-time-bucket-zero-fill.test.ts,预期 27/27 通过;把那一处提前返回加回去,同一文件 5 条失败(两边都空的月份消失),2 条对照仍绿。What changes
DatasetExecutor.timeBucketFillPlanreturned no plan whenselection.compareTowas set, the deliberate skip #26893 (PR #27109) left for this card. The skip is lifted; nothing else in the production path changes.compareToanswer gets the sameTimeBucketFillPlanand the samefillEmptyTimeBucketswalk a plain series gets. No second walker, no new helper.timeDimensions[].dateRange, never the shifted one. It runs after the comparison merge, wherealignedCompareBucketKeyhas already restated the comparison rows in primary bucket keys (when the axis is the anchor), so a bucket either window holds is already a row and keeps the merge's values. What the fill adds is only a bucket empty in both windows.__comparecolumns. Measured, not changed:fillColumnsalready listsMEASURE__comparebeside each base measure (dataset-executor.tsL1364), andfillEmptyGroupsruns after the bucket fill. So an added row reads0forcount/sumin both the measure and its__compare, andavg/min/maxare absent keys on both sides (pinned in the tests and seen live below). Derived measures are evaluated after the fill, as before.compareTo.limit/offset, anorderon a non-dimension key (a measure, a__comparecolumn, a derived measure), more than one bucketed axis, andMAX_ZERO_FILLED_GRID_ROWS.dateRangeof its own (the comparison anchored on another, window-only date dimension) gets its interior gaps filled and no edges, the same one-bound rule a plain series follows. That is the only "unbounded"compareToshape that exists:compareTorefuses an anchor without a two-bounddateRange(resolveCompareDimension,explicitDateRangeWindow).timeBucketFillPlandocblock now states thecompareToreading instead of "a separate question".Tests
packages/services/service-analytics/src/__tests__/dataset-time-bucket-zero-fill.test.ts(the realAnalyticsServicePluginover a real ObjectQL engine and a real SQLite driver, as in #26893):compareTo keeps its shapecontrol pinned the skip, so it is replaced by the card's own case: May–August 2026 vs the previous year (2025-05..08 empty) answers2026-05, 06, 07, 08, withtotal_amount[0, 70, 80, 0], every__compare0,opp_count/opp_count__comparetoBe(0)on May and August, andavg_amount/avg_amount__compareabsent keys.cmp_probe), one month in each state: both windows, primary only, compare only, neither. Cases:2026-03|1|1, 04|1|0, 05|0|1, 06|0|0, 07|1|0, 08|0|0(count, count__compare) plus the sums: the three one-window months and the both-window month keep the merge's values, June and August are added;compareToanswer equal the plain series' answer for the same window (one fill rule);previousPeriod(June–August vs March–May, ordinal alignment):06|0|1, 07|1|1, 08|0|0;dateRange(anchorclosed_at, window-only): every month between the first and last bucket the grid holds (2025-03…2026-07), none before or after;limitwithcompareTo, and anorderonopp_count__compare, are not filled (4 rows, the base answer).dataset-compare-bucket-alignment.test.tsdayuses a window (1–4 March) wider than its rows (2–3 March), so 1 and 4 March now come back at0 / 0. The expected rows are updated with exact values; the alignment it pins (03-02↔ 5,03-03↔ 6) is unchanged.Ablation: restoring the compareTo early return
node scripts/ablation-replace.mjsondataset-executor.ts, anchorif (selection.limit != null || selection.offset != null) return undefined;→if (selection.compareTo || selection.limit != null || selection.offset != null) return undefined;(anchor x1 → x0, replacement x0 → x1, blob201a3ec3→0fe9ae21). The suite imports the executor fromsrc/, so no build sits between the mutation and the run.The base answer for the fixture case was
2026-03|1|1, 04|1|0, 05|0|1, 07|1|0: the one-window months are the same rows with the same values. Restore: blob after restore201a3ec3= HEAD,git diff HEADempty.Live red/green through the REST door (app-crm, opportunity_metrics)
pnpm dev:crm -- --fresh -p PORTafter a fullpnpm build, signed in as the dev admin,POST /api/v1/analytics/dataset/querywithdatasetName: opportunity_metrics,runtimeFilter: { stage: 'closed_won' },timeDimensions: [{ dimension: 'close_date', dateRange: ['2026-06-01', '2026-10-31'] }], measuresopp_count,total_amount,avg_amount. The seed's closed-won deals sit in 2026-07, 2026-10, 2025-09 and 2025-10. Red = the base blob ofdataset-executor.ts(55592517) written over the file and@objectstack/service-analyticsrebuilt (dist markerselection.compareTo || selection.limit: 1 hit each inindex.js/index.cjs); green = HEAD rebuilt (0 hits). Restore proven by the blob hash equal to HEAD's andgit diff HEADempty. Columns: count / count__compare, sum / sum__compare, avg.Acceptance notes
compareToanswer gains rows it lacked.Metadata-protocol: none..changeset/26893-time-series-empty-buckets.md(unreleased, from PR fix(service-analytics): a date-dimension series answers every bucket of its window, the empty ones included #27109) still listscompareTounder Not filled. It is left at its base bytes: the requiredCheck Changesetgate refuses any change to a changeset this PR did not add (finding: random changeset filenames collide silently across parallel agents — a round overwrote a sibling PR'sminorchangeset and every gate stayed green #17712). Instead, this PR's own changeset ends with a sentence that supersedes thatcompareTomention for the same release (seat claim amendment 2,6467147455).compareTo(git grep -l compareTo -- packages/qais empty), and this diff changes an answer only whencompareTois set, so the full battery is not run (no!and no(narrowing)arm).Verification
All on head
93470eef(this branch withorigin/mainb322b5damerged in), afterpnpm install --frozen-lockfile && pnpm build:pnpm --filter @objectstack/service-analytics test: 194 files, 4698 passed, 282 skipped.typecheck: exit 0.build: exit 0.pnpm --filter @objectstack/spec check:generated: exit 0 (spec moved onmain; untouched here).@objectstack/restanalytics suites (vitest run src/analytics-, reading the rebuilt@objectstack/service-analyticsdist): 23 files, 298 passed, 22 skipped.pnpm exec eslint --no-inline-config packages/services/service-analytics: exit 0.node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack: 59 derived families, all run, all exit 0.--ranreconciliation:59 derived, 59 run, 0 NOT-MEASURED, 0 UNRUN. (check-plugin-teardown-shape --self-testafter the documentedgit fetch --depth=1of its fixture commit.)1083b988, before the merge, whose incoming commits do not touchdataset-executor.tsor the two test files.Generated by Claude Code