fix(analytics): timeDimensions 分桶维度回到结果的 rows 与 fields (#4033) - #4069
Merged
Conversation
…and fields
A query bucketing by `timeDimensions` alone grouped correctly — the echoed SQL
read `date_trunc('month', due_date) AS "due_date"` — but the row mapper and
buildFieldMeta both enumerated `query.dimensions` only, so the bucket was
dropped on the way out:
rows: [{ count: 2 }, { count: 8 }]
fields: [{ name: 'count', type: 'number' }]
A trend chart therefore got N values and no x-axis. Found by driving a live
showcase app, not by static review: the numbers were right, so nothing
downstream errored — only the labels were gone. Writing the same query as
`dimensions: ['due_date']` was always fine, which is why it survived.
Grouping, row mapping (both the direct and cross-object paths) and field
metadata now derive their projected set from one `projectedDimensions()`
helper: `dimensions` plus every GRANULAR `timeDimensions` entry not already
among them. Granularity is the right gate because it is exactly what the three
groupBy sites key on — an entry without one contributes only a `dateRange`
predicate, and projecting it would declare a column the engine never grouped
by. The cross-object path already had its own correct-but-parallel loop; it now
shares the single definition rather than being a second place to keep in sync.
Closes #4033
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPxNwPnjcn599ujXpU3ibJ
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 6 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
os-zhuang
marked this pull request as ready for review
July 30, 2026 08:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4033。
问题
只用
timeDimensions分桶的 analytics 查询,分组是对的 —— 回显的 SQL 就是date_trunc('month', due_date) AS "due_date"—— 但结果里没有这个维度:趋势图因此拿到 N 个数值却没有 x 轴标签。数值全对,所以下游没有任何报错,只是标签没了;把同一个查询写成
dimensions: ['due_date']又完全正常 —— 这就是它一直没被发现的原因。是 dogfood 真实跑 showcase app 时发现的,不是静态审出来的。根因
ObjectQLStrategy里三处对「哪些维度被投影」各有一套判断:generateSql/ cross-object):dimensions+ 带granularity的timeDimensions✅query.dimensions❌buildFieldMeta:只枚举query.dimensions❌引擎按时间桶分了组、行里也带着它,映射这一步把它丢了。
修法
三方(分组、行映射、字段元数据)统一由一个
projectedDimensions()推导:dimensions加上所有带granularity且不重复的timeDimensions。以
granularity为闸门是因为那正是三处 groupBy 的判据 —— 不带 granularity 的条目只贡献dateRange谓词,把它投影出去会声明一个引擎从没分组过的列。cross-object 那份「正确但平行」的循环也并入同一定义,不再是第二个需要同步的地方。验证
新增
objectql-timedimension-projection.test.ts(5 例)。先验证它能抓到 bug:在未修复的代码上跑 → 3 失败 2 通过(通过的那 2 个是负向断言,本就该过);修复后 5/5。覆盖:桶进 rows、桶进 fields、
timeDimensions写法与dimensions写法结果一致、同时出现时不重复、不带 granularity 的条目不得被投影。🤖 Generated with Claude Code
https://claude.ai/code/session_01TPxNwPnjcn599ujXpU3ibJ
Generated by Claude Code