MultiSet.consolidate merges keyed records whose keys or values differ only by number/string type
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 76/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- databases
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
- 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.
- Ngôn ngữ chính
- TypeScript
- Star
- 3.9k
- Fork
- 267
- Merge trung bình
- 1 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 134
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/db
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
SerovalUnsupportedTypeError when TanStack Start SSR dehydrates an on-demand query collectionĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 50/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
siyuan-note/siyuan#20040 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
RunestoneInteractive/rs#1574 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
remotion-dev/remotion#11901 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Poll constructor throws for an uncached channel while resolving a message context-menu interactionĐang mởbug need repro packages:discord.js
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
discordjs/discord.js#11645 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
🐞 bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Sitecore/content-sdk#641 ·
Maintainer thường phản hồi trong vòng 2 ngày