MultiSet.consolidate merges keyed records whose keys or values differ only by number/string type
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
- 领域
- databases
调研方向
Start in packages/db-ivm/src/utils.ts with getStringId, then locate the keyed consolidation path that builds compositeKey. Run the consolidation oracle and add the primitive key/value and join-tuple witnesses described in the issue, removing its exclusion; done means cross-type records remain distinct and a changeset is included for @tanstack/db-ivm.
由索引模型根据 Issue 内容生成。
描述
- I've validated the bug against the latest version of DB packages (
origin/mainatb5d92ceb)
Describe the bug
MultiSet.consolidate() merges keyed records whose keys or primitive values differ only in type. A number and a string with the same text, such as 1 and "1", become one identity. Multiplicities for two different records are then summed together. A retraction of one record can erase an insert of a different record.
The keyed path builds a string identity. getStringId in packages/db-ivm/src/utils.ts encodes every primitive as `str_${String(value)}`, and consolidate joins the key the same way:
getStringId(value: any): string {
if (value === null) return `null`
if (value === undefined) return `undefined`
if (typeof value !== `object`) return `str_${String(value)}`
return `obj_${this.getId(value)}`
}
// ...
const compositeKey = key + `|` + valueId
So 1 and "1" both produce str_1, and the keys 1 and "1" both produce 1|.
To Reproduce
import { MultiSet } from '@tanstack/db-ivm'
new MultiSet<any>([[[1, 'v'], 1], [['1', 'v'], 1]]).consolidate().getInner()
// [[[1, 'v'], 2]] expected two records, each with multiplicity 1
new MultiSet<any>([[['k', 1], 1], [['k', '1'], -1]]).consolidate().getInner()
// [] expected [[['k', 1], 1], [['k', '1'], -1]]
new MultiSet<any>([[['k', [1, null]], 1], [['k', ['1', null]], -1]]).consolidate().getInner()
// [] expected both records (join tuples have the same collision)
The unkeyed path is correct:
new MultiSet<any>([[1, 1], ['1', -1]]).consolidate().getInner()
// [[1, 1], ['1', -1]]
Expected behavior
Keyed consolidation should keep the identity rule it documents. Keys compare by value, and values compare by reference. A number and a string are different values, so records that differ only in that type must stay separate.
Scope
-
Object values are compared by reference and are not affected. The collision needs a primitive key or a primitive value, or a join tuple that holds a primitive.
-
In
@tanstack/db, the collision needs one of these:- one collection with numeric and string keys that print the same, such as
1and"1"; - a keyed stream that carries primitive values.
I have not traced which query shapes produce such a stream.
- one collection with numeric and string keys that print the same, such as
-
A code-weight change to
MultiSet.consolidateis in progress. It keeps this behavior unchanged on purpose. Its consolidation oracle excludes these cross-type values from its grammar and links to this issue. A fix should remove that exclusion.
Suggested fix and test
- Include the type in the primitive identity, for example
`${typeof value}:${String(value)}`. Also encode the key with its type before the|join. - Remove the exclusion from the consolidation oracle, and add these cases as witnesses. Each case should fail before the fix and pass after it.
- Add a changeset for
@tanstack/db-ivm.
- 主要语言
- TypeScript
- 星标
- 3.9k
- 派生
- 272
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 210
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/db 的其他 Issue
-
难度 5/5 一周以上 新手友好度 5/100
维护者通常 1 天内回复
-
browser-db-sqlite-persistence: option to load the wa-sqlite WASM by URL instead of inlined base64未关闭
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 72/100
维护者通常 1 天内回复
-
electric-db-collection: on-demand + persistence fails after relaunch with "Snapshot requests are not supported in full mode"可能已有人在做 @KyleAMathews 于 4 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 68/100
TanStack/db#2056 · 1 个 reaction ·
维护者通常 1 天内回复
相似的 Issue
-
bug cli service
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
create-element: same editorAlias silent-fallback bug as #201, not covered by that fix可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭generated-by-ai
难度 2/5 1-3 小时 新手友好度 78/100
umbraco/Umbraco-CMS-MCP-Editor#208 · 1 条评论 ·
维护者通常 1 天内回复
-
Table: Space fires onActivate in single-selection mode — the reference doc and the JSDoc disagree未关闭
难度 2/5 1-3 小时 新手友好度 68/100
sidorares/react-x11-components#764 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
backnotprop/plannotator#1840 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
JoviDeCroock/pracht#432 ·
维护者通常 1 天内回复