Repository navigation
fix(driver-sql): by-id writes, aggregate() and distinct() honour external.columnMap - #31349
Conversation
… on every dialect GROUP BY, the date-bucket expression, the aggregand and SELECT DISTINCT named the field verbatim, so a columnMap-ed federated object was asked for a column its remote table does not have. Identifiers are now the remote column; output keys, presentation and the per-field registries stay the field. buildDateBucketExpr gains a column parameter: the registries are read by the field, the statement names the column. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2euiyuLXizr6FW32R3
…hrough external.columnMap The by-id doors wrote WHERE "id" = ? whatever the map said: a failure on a remote table without an id column, and a match on the wrong column on one that has its own. They now match the key's mapped column, as the insert read-back already did. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2euiyuLXizr6FW32R3
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2euiyuLXizr6FW32R3
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2euiyuLXizr6FW32R3
📓 Docs Drift CheckThis PR changes 1 package(s): 5 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 1 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 13 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 d5c62026e218e0a386f2cf1b64c1bd6040c7bc05 && git checkout d5c62026e218e0a386f2cf1b64c1bd6040c7bc05
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin dc7f5c4b4aeb2cb401c68f37f65de19ee352c92a 05ecc9792248cad6861a306a3de9946d671b9a68 && git checkout -B drift-repro dc7f5c4b4aeb2cb401c68f37f65de19ee352c92a && git merge --no-ff 05ecc9792248cad6861a306a3de9946d671b9a68
node scripts/docs-audit/affected-docs.mjs --json dc7f5c4b4aeb2cb401c68f37f65de19ee352c92a
|
|
epic:#27261#1 · marchtian · session_017ihL2c5z3q4h8inrn5kwqV 维护者速读
席位意见:ACCEPT。无契约面: 席位核对
|
Requested by 田騏 · project thread
Fixes #31340
Clause-②: no
Metadata-protocol: none
维护者速读
external.columnMap把主键映射到远端列(如CUST_NO: 'id')时,update()、delete()、bulkDelete()现在按映射后的列匹配行,不再写死WHERE "id" = ?;aggregate()(分组、日期分桶、聚合字段)和distinct()也改为按远端列取值,输出键和展示仍用本地字段名。id的普通列时,旧语句在 SQLite / PostgreSQL / MySQL 上按错误的列匹配:更新返回空,删除会删掉没人指定的行,而且不报错。聚合和去重则直接报「列不存在」。columnMap的对象和轮转分片,生成的 SQL 与之前完全一致。只改packages/drivers/driver-sql,两个 patch changeset。回滚就是还原这个 PR。sql-driver-sequence-semantics.ts的update/delete,sql-driver-bulk-operations.ts的bulkDelete;sql-driver-aggregation.ts的columnOf;两个新测试文件。pnpm --filter @objectstack/driver-sql exec vitest run src/sql-driver-external-columnmap-writes.test.ts src/sql-driver-external-columnmap-aggregate.test.ts,预期 13 个用例全部通过。upsert同样没走映射,已另立 driver-sql: upsert() ignores external.columnMap for its conflict target and read-back — a mapped key refuses with "no such column: id", or answers a different row than the one it wrote #31342,不在本 PR。What changes
Two defects, one commit and one patch changeset each. Both fixes were first written on the Oracle federation card's branch; this PR lands them alone off
main, with nothing Oracle-specific (no spec change, no dialect arm).By-id writes.
update()(the statement and its read-back),delete()andbulkDelete()resolve the key column throughremoteColumn(object, 'id', 'id'), the same mappingcreate()'s read-back and the write payload (applyWriteColumnMap) already use. Rotation shards are never federated and keepid.Analytic reads.
aggregate()spells every identifier (GROUP BY, the structured group key, the date-bucket expression, the aggregand) as the remote column, anddistinct()selects and reads back the remote column. Output keys, presentation (readPresentationKind,presentReadValue) and the per-field registries stay keyed by the FIELD.buildDateBucketExprgains an optionalcolumnparameter: the field still drivestemporalFieldKindand the SQLite repair, and the bindings name the column.An object without a
columnMapcompiles the statement it compiled before.Why
ADR-0015 federation maps a local field to a remote column;
find(),count()and every WHERE honoured that, these five doors did not. The silent half: a remote table with its own unmappedidcolumn, where the unmappedWHERE "id" = ?matched the surrogate, so an update answerednulland a delete removed a row nobody named.Verification
Measured on this branch (sqlite, the in-tree driver), before the merge of main at 0ceca39 and re-run on the merge head:
sql-driver-external-columnmap-writes.test.ts: 5 of 5 fail withsql-driver-sequence-semantics.tsandsql-driver-bulk-operations.tsrestored toorigin/main; 5 pass with the fix.sql-driver-external-columnmap-aggregate.test.ts: 8 of 8 fail withsql-driver-aggregation.ts,sql-driver-distinct.tsandsql-driver-date-bucket.tsrestored toorigin/main; 8 pass with the fix.pnpm --filter @objectstack/driver-sql test: 240 files passed, 12 skipped; 3880 tests passed, 218 skipped (the live PG and MySQL cells, which run inTemporal Conformance (live PG + MySQL)onmain).pnpm --filter @objectstack/driver-sql run typecheck: exit 0.dispatch-gates --commands: 68 derived; all 68 run, every one exit 0;dispatch-gates --ran: 68 accounted, 0 NOT-MEASURED, 0 UNRUN.Out of scope, measured and filed:
upsert()on a columnMap-ed object uses the unmappedidas its conflict target and read-back key (#31342).Human Minimum
packages/specholds no runtime logic. (packages/specnot touched.)pnpm lintpasses. (eslint over the changed files, exit 0.)main, one pull request.@objectstack/driver-sqlpatch, two changesets.)packages/spectouched: its generated artifacts are regenerated and committed. (Not touched.)content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.Generated by Claude Code
🤖 Generated with Claude Code