Skip to content

Commit 3abed69

Browse files
committed
Fix distinct tests
1 parent 2f20064 commit 3abed69

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

packages/db-ivm/src/operators/distinct.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export class DistinctOperator<
3636
// Compute the new multiplicity for each value
3737
for (const message of this.inputMessages()) {
3838
for (const [value, diff] of message.getInner()) {
39+
console.log(`value: `, JSON.stringify(value, null, 2))
40+
console.log(
41+
`this.#by(value): `,
42+
JSON.stringify(this.#by(value), null, 2)
43+
)
3944
const hashedValue = hash(this.#by(value))
4045

4146
const oldMultiplicity =

packages/db-ivm/tests/operators/distinct.test.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { MultiSet } from "../../src/multiset.js"
44
import { distinct } from "../../src/operators/distinct.js"
55
import { output } from "../../src/operators/output.js"
66
import { MessageTracker, assertResults } from "../test-utils.js"
7+
import { hash } from "../../src/hashing/index.js"
78

89
describe(`Operators`, () => {
910
describe(`Efficient distinct operation`, () => {
@@ -39,9 +40,9 @@ function testDistinct() {
3940

4041
expect(data).toEqual([
4142
[
42-
[[1, `a`], 1],
43-
[[2, `b`], 1],
44-
[[2, `c`], 1],
43+
[[hash([1, `a`]), `a`], 1],
44+
[[hash([2, `b`]), `b`], 1],
45+
[[hash([2, `c`]), `c`], 1],
4546
],
4647
])
4748
})
@@ -74,7 +75,7 @@ function testDistinct() {
7475

7576
graph.run()
7677

77-
const data = messages.map((m) => m.getInner())[0]
78+
const data = messages.map((m) => m.getInner())[0]!
7879
const countries = data
7980
.map(([[_, value], multiplicity]) => [value.country, multiplicity])
8081
.sort()
@@ -118,8 +119,8 @@ function testDistinct() {
118119
`distinct with updates - initial`,
119120
initialResult,
120121
[
121-
[1, `a`],
122-
[1, `b`],
122+
[hash([1, `a`]), `a`],
123+
[hash([1, `b`]), `b`],
123124
], // Should have both distinct values
124125
4 // Max expected messages
125126
)
@@ -140,7 +141,7 @@ function testDistinct() {
140141
assertResults(
141142
`distinct with updates - second batch`,
142143
secondResult,
143-
[[1, `c`]], // Should only have 'c' remaining
144+
[[hash([1, `c`]), `c`]], // Should only have 'c' remaining
144145
4 // Max expected messages
145146
)
146147

@@ -186,9 +187,9 @@ function testDistinct() {
186187

187188
expect(data).toEqual([
188189
[
189-
[[`key1`, 1], 1],
190-
[[`key1`, 2], 1],
191-
[[`key2`, 1], 1],
190+
[[hash([`key1`, 1]), 1], 1],
191+
[[hash([`key1`, 2]), 2], 1],
192+
[[hash([`key2`, 1]), 1], 1],
192193
],
193194
])
194195
})
@@ -224,8 +225,8 @@ function testDistinct() {
224225
`distinct with multiple batches that cancel out`,
225226
result,
226227
[
227-
[`key1`, 1], // Should remain (multiplicity 2 -> 1 in distinct)
228-
[`key2`, 1], // Should remain (multiplicity 2 -> 1 in distinct)
228+
[hash([`key1`, 1]), 1], // Should remain (multiplicity 2 -> 1 in distinct)
229+
[hash([`key2`, 1]), 1], // Should remain (multiplicity 2 -> 1 in distinct)
229230
],
230231
6 // Max expected messages (generous upper bound)
231232
)

0 commit comments

Comments
 (0)