MCPcopy Create free account
hub / github.com/TanStack/db / testJoin

Function testJoin

packages/db-ivm/tests/operators/join.test.ts:18–344  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16})
17
18function testJoin() {
19 test(`basic join operation`, () => {
20 const graph = new D2()
21 const inputA = graph.newInput<[number, string]>()
22 const inputB = graph.newInput<[number, string]>()
23 const tracker = new KeyedMessageTracker<number, [string, string]>()
24
25 inputA.pipe(
26 join(inputB),
27 output((message) => {
28 tracker.addMessage(message as MultiSet<[number, [string, string]]>)
29 }),
30 )
31
32 graph.finalize()
33
34 inputA.sendData(
35 new MultiSet([
36 [[1, `a`], 1],
37 [[2, `b`], 1],
38 ]),
39 )
40
41 inputB.sendData(
42 new MultiSet([
43 [[1, `x`], 1],
44 [[2, `y`], 1],
45 [[3, `z`], 1], // key 3 only exists in B, so no join output expected
46 ]),
47 )
48
49 graph.run()
50
51 const result = tracker.getResult()
52
53 // Assert only keys that can actually join (1, 2) are affected, not key 3
54 assertOnlyKeysAffected(`basic join operation`, result.messages, [1, 2])
55
56 // Assert the final materialized results are correct
57 assertKeyedResults(
58 `basic join operation`,
59 result,
60 [
61 [1, [`a`, `x`]],
62 [2, [`b`, `y`]],
63 ],
64 4, // Expected message count
65 )
66 })
67
68 test(`join with late arriving data`, () => {
69 const graph = new D2()
70 const inputA = graph.newInput<[number, string]>()
71 const inputB = graph.newInput<[number, string]>()
72 const tracker = new KeyedMessageTracker<number, [string, string]>()
73
74 inputA.pipe(
75 join(inputB),

Callers 1

join.test.tsFile · 0.70

Calls 13

newInputMethod · 0.95
addMessageMethod · 0.95
finalizeMethod · 0.95
runMethod · 0.95
getResultMethod · 0.95
expectFunction · 0.90
joinFunction · 0.85
outputFunction · 0.85
assertOnlyKeysAffectedFunction · 0.85
assertKeyedResultsFunction · 0.85
pipeMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected