Repository navigation
Commit 990d063
docs(data): a structured groupBy alias is the row key on the SQL face too (#35051)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBLW6dHPW6sSheA32XPKZzPV)_
Fixes #35015
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:两页文档各改一句。`queries.mdx` 原来说「SQL 驱动忽略结构化 groupBy 的
`alias`,结果列永远叫字段名」;`query-syntax.mdx` 原来说「`alias`
只在内存路径生效」。现在两处都改为:下推到数据库和内存兜底两条路径上,结果列都叫 `alias`。另加一个 driver-sql
测试文件,在每种方言上钉住结果行的键。
- 为什么改:在 SQLite 和 PostgreSQL 16 上实测 `engine.aggregate`,下推和内存兜底两条路径都返回
`alias` 作为列名。驱动自 #6401 起就这样做,旧文档是过期的。查询技能 `aggregation.md` 写的是对的,没有改动。
- 风险与回滚:只改文档,加了一个测试文件,没有产品代码,也没有发布面;回滚就是还原这个 PR。
- 先看:`content/docs/data-modeling/queries.mdx` 第 714–718
行,`packages/drivers/driver-sql/src/sql-driver-35015-groupby-alias-row-key.test.ts`,`content/docs/protocol/objectql/query-syntax.mdx`
第 1151 行。
- 两分钟验证:`pnpm --filter @objectstack/driver-sql exec vitest run
src/sql-driver-35015-groupby-alias-row-key.test.ts`,预期 sqlite 4 条用例通过;设置
`OS_TEST_POSTGRES_URL` 时 PG 也是 4 条通过。
- 需要你做的:无,席位落地。
## What changes
- `content/docs/data-modeling/queries.mdx`, in the date-bucketing warn
callout. The old paragraph said the SQL driver ignores a structured
`groupBy` node's `alias` and "always projects the bucket under the
**field name**". It now says the alias renames the projected column on
both paths, that grouping still keys on the field, that the result is
read under `alias ?? field`, and that `having` references that name.
Once an alias is set, a `having` on the field name is refused.
- `content/docs/protocol/objectql/query-syntax.mdx:1151`: "(or `alias`,
on the in-memory path)" now reads "or under `alias` when the node sets
one (pushed down or in memory alike)". This file joined the claim
through amendment 6964093495.
-
`packages/drivers/driver-sql/src/sql-driver-35015-groupby-alias-row-key.test.ts`
(new, test only). It runs on every `DIALECT_CELLS` cell and pins the
exact key set of each row on the pushed-down face:
- a quarter bucket with `alias: 'quarter'` yields keys
`quarter,revenue`;
- the unaliased control yields `closed_at,revenue`;
- a plain alias `r` beside the bucket alias yields `quarter,r,revenue`.
- The skill (`skills/objectstack-query/rules/aggregation.md`) is
**unchanged**. Its text ("results are correct either way, including the
column keys"; "Read the result under `alias ?? field`, and reference
that same name from `having`") matches every measured arm. No eval case
was added: the order asks for one only if the skill text changes.
Because no `skills/**` file changed, this branch is cut from
`origin/main` (6d2db1d), not from the head of #35012. It shares no
file with #35012: `overlap-check` answered `VERDICT clean exit 0`
against origin/main 367e324, with 0 PR heads sharing a file.
## Tests
<details><summary>Phase 1 reading: engine.aggregate on a real SqlDriver,
SQLite and live PostgreSQL 16.15</summary>
The probe was a scratch script (not committed). It used `ObjectQL` plus
`SqlDriver` against a `datetime` field. The driver's `aggregate` and
`find` were wrapped to record which path the engine took. Every run
exited 0. Four runs: `sqlite`, `sqlite` with `quarter` capability off,
`pg`, and `pg` with `quarter` off.
| case | sqlite | pg | keys (every arm) |
|---|---|---|---|
| bucket `alias: 'quarter'`, UTC | NATIVE | NATIVE | `quarter, revenue`
|
| same, `timezone: '+00:00'` | IN-MEMORY | IN-MEMORY | `quarter,
revenue` |
| same, `timezone: 'Asia/Taipei'` | IN-MEMORY | NATIVE (zoned) |
`quarter, revenue` |
| same, driver declares no `quarter` | IN-MEMORY | IN-MEMORY | `quarter,
revenue` |
| `having: { quarter: … }` | served, filtered | served, filtered |
`quarter, revenue` |
| `having: { closed_at: … }` with alias set | INVALID_FILTER / 400 |
INVALID_FILTER / 400 | refused |
| plain `{ field: 'region', alias: 'r' }` | NATIVE | NATIVE | `r,
revenue` |
| plain `r` + bucket `quarter`, `+00:00` | IN-MEMORY | IN-MEMORY | `r,
quarter, revenue` |
| no alias (control) | NATIVE | NATIVE | `closed_at, revenue` |
Bucket values and sums were identical on every arm (`2025-Q1 = 30`,
`2025-Q2 = 12`).
The code lines that decide the key:
- `packages/drivers/driver-sql/src/sql-driver-aggregation.ts:239`:
`const outKey = g.alias ?? g.field`. It is used by the bucket projection
(line 252) and the plain-field projection (line 276).
- `packages/objectql/src/in-memory-aggregation.ts:194`: `g.alias ??
g.field`.
- `packages/objectql/src/having-filter.ts:1126-1131`:
`aggregatedRowColumns`, which builds the `having` namespace from `alias
?? field`.
- The engine's fork is
`packages/objectql/src/engine-delete-and-aggregate.ts:1431-1488`
(`allStructuredSupported`, `tzRequiresInMemory`, `nativeAggregate`).
</details>
<details><summary>Pin and ablation</summary>
The pin at head 0682686 ran with `OS_TEST_POSTGRES_URL` set to a
local PostgreSQL 16 cluster. Result: `Test Files 1 passed (1)`, `Tests 8
passed | 1 skipped (9)`, `live postgres RAN`. The skipped one is the
named live-mysql cell. Lock line: `VERDICT command-exit 0`.
Ablation, after the fix was committed:
- `scripts/ablation-replace.mjs` replaced `const outKey = g.alias ??
g.field;` with `const outKey = g.field /* ablated-35015 */;` in
`sql-driver-aggregation.ts`. Anchor count went 1 → 0, blob 1e81807
→ 524fc156d99c.
- Result: `Tests 4 failed | 4 passed | 1 skipped`. The two alias cases
failed on both sqlite and live postgres; the control and the capability
case stayed green.
- Restore: blob after restore 1e81807, equal to the HEAD blob; `git
diff HEAD` is empty. The suite imports `../src/index.js`, so no `dist/`
is involved.
</details>
<details><summary>Package suite and typecheck</summary>
- `pnpm --filter @objectstack/driver-sql exec vitest run --maxWorkers=2`
at 0682686: `Test Files 261 passed | 13 skipped (274)`, `Tests 4358
passed | 253 skipped (4611)`, `VERDICT command-exit 0`.
- `pnpm --filter @objectstack/driver-sql typecheck`: exit 0. `tsc
--listFiles` includes the new test file.
</details>
## Acceptance notes
- Claim 6963952530; amendment 6964093495 added
`content/docs/protocol/objectql/query-syntax.mdx`.
- Driver defect: none. The SQL face has honoured the alias since #6401.
Existing pins on other faces and dialects:
`sql-driver-13714-aggregate-alias-single-identifier.test.ts:228-239`
(bucket alias, every cell); `sql-driver-aggregation-conformance.test.ts`
(`groupByAlias` case, every cell);
`sql-driver-33697-zoned-date-bucket.test.ts:181` (zoned PG bucket
alias); `packages/objectql/src/in-memory-aggregation.test.ts:44-53`
(in-memory `qtr`); `engine-aggregate-having-comparand-shape.test.ts:728`
(`having` on the field name is refused once aliased).
- `skip-changeset`: content/docs is not published, and `driver-sql`
publishes only `dist`, which carries no test file.
## Verification
- Local gates: `dispatch-gates --commands` derived 82 families, run at
f7e7a14. 81 exited 0. `pnpm check:dual-build-cjs-loads` exited 3
(PREREQUISITE NOT MET, needs a full build), so it is NOT MEASURED
locally and left to CI. `--ran` reconciliation: 82 accounted, 81 run, 1
NOT-MEASURED.
- The head commit 0682686 changed only the type-import path in the
new test file. These families were re-run at that head, all exit 0:
`cross-package-test-inputs`, `test-source-alias`, `nul-bytes`,
`undeclared-dep-imports`, `issue-citations`, `engine-double-contract`,
`driver-conformance`, `tier-file-adoption`, `where-matcher`,
`org-identifier`, `role-word`, `keyed-text-bounds`, `refd-timer-probe`,
`objectql-double-limit`, `driver-memory-census`,
`comment-mask-adoption`, `comment-mask-corpus`, `doc-authoring`, plus
`check-skills-token-ratchet`.
- The CI check-runs are cited in the report once they finish; this body
does not wait for them.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzfrh8TiPJf1i2kMSoa)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01WGufzfrh8TiPJf1i2kMSoa
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufzfrh8TiPJf1i2kMSoa -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent eb7b09d commit 990d063
3 files changed
Lines changed: 109 additions & 4 deletions
File tree
- content/docs
- data-modeling
- protocol/objectql
- packages/drivers/driver-sql/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
711 | 711 | | |
712 | 712 | | |
713 | 713 | | |
714 | | - | |
715 | | - | |
716 | | - | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
717 | 719 | | |
718 | 720 | | |
719 | 721 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1148 | 1148 | | |
1149 | 1149 | | |
1150 | 1150 | | |
1151 | | - | |
| 1151 | + | |
1152 | 1152 | | |
1153 | 1153 | | |
1154 | 1154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
0 commit comments