-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
609 additions
and
164 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/zql/ivm/graph/operators/DifferenceEffectOperator.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {expect, test} from 'vitest'; | ||
import {DifferenceStreamWriter} from '../DifferenceStreamWriter.js'; | ||
import {DifferenceEffectOperator} from './DifferenceEffectOperator.js'; | ||
import {Multiset} from '../../Multiset.js'; | ||
|
||
test('calls effect with raw difference events', () => { | ||
const inputWriter = new DifferenceStreamWriter<number>(); | ||
const inputReader = inputWriter.newReader(); | ||
const output = new DifferenceStreamWriter<number>(); | ||
|
||
let called = false; | ||
let value = 0; | ||
let mult = 0; | ||
new DifferenceEffectOperator(inputReader, output, (v, m) => { | ||
called = true; | ||
value = v; | ||
mult = m; | ||
}); | ||
|
||
inputWriter.queueData([1, new Multiset([[1, 1]])]); | ||
inputWriter.notify(1); | ||
|
||
// effect not run until commit | ||
expect(called).toBe(false); | ||
|
||
inputWriter.notifyCommitted(1); | ||
expect(called).toBe(true); | ||
expect(value).toBe(1); | ||
expect(mult).toBe(1); | ||
|
||
called = false; | ||
value = 0; | ||
mult = 0; | ||
inputWriter.queueData([2, new Multiset([[1, -1]])]); | ||
inputWriter.notify(2); | ||
|
||
// effect not run until commit | ||
expect(called).toBe(false); | ||
|
||
inputWriter.notifyCommitted(2); | ||
expect(called).toBe(true); | ||
expect(value).toBe(1); | ||
expect(mult).toBe(-1); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import {expect, test} from 'vitest'; | ||
import {FilterOperator} from './FilterOperator.js'; | ||
import {DifferenceStreamWriter} from '../DifferenceStreamWriter.js'; | ||
import {Multiset} from '../../Multiset.js'; | ||
import {NoOp} from './Operator.js'; | ||
|
||
test('does not emit any rows that fail the filter', () => { | ||
const inputWriter = new DifferenceStreamWriter<number>(); | ||
const inputReader = inputWriter.newReader(); | ||
const output = new DifferenceStreamWriter<number>(); | ||
|
||
new FilterOperator(inputReader, output, _ => false); | ||
|
||
const outReader = output.newReader(); | ||
outReader.setOperator(new NoOp()); | ||
|
||
inputWriter.queueData([ | ||
1, | ||
new Multiset([ | ||
[1, 1], | ||
[2, 2], | ||
[1, -1], | ||
[2, -2], | ||
]), | ||
]); | ||
inputWriter.notify(1); | ||
inputWriter.notifyCommitted(1); | ||
const items = outReader.drain(1); | ||
|
||
expect(items.length).toBe(1); | ||
expect([...items[0].entries].length).toBe(0); | ||
}); | ||
|
||
test('emits all rows that pass the filter (including deletes / retractions)', () => { | ||
const inputWriter = new DifferenceStreamWriter<number>(); | ||
const inputReader = inputWriter.newReader(); | ||
const output = new DifferenceStreamWriter<number>(); | ||
|
||
new FilterOperator(inputReader, output, _ => true); | ||
|
||
const outReader = output.newReader(); | ||
outReader.setOperator(new NoOp()); | ||
|
||
inputWriter.queueData([ | ||
1, | ||
new Multiset([ | ||
[1, 1], | ||
[2, 2], | ||
[1, -1], | ||
[2, -2], | ||
]), | ||
]); | ||
inputWriter.notify(1); | ||
inputWriter.notifyCommitted(1); | ||
const items = outReader.drain(1); | ||
|
||
expect(items.length).toBe(1); | ||
const entries = [...items[0].entries]; | ||
expect(entries).toMatchObject([ | ||
[1, 1], | ||
[2, 2], | ||
[1, -1], | ||
[2, -2], | ||
]); | ||
}); | ||
|
||
test('test that filter is lazy / the filter is not actually run until we pull on it', () => { | ||
const inputWriter = new DifferenceStreamWriter<number>(); | ||
const inputReader = inputWriter.newReader(); | ||
const output = new DifferenceStreamWriter<number>(); | ||
|
||
let called = false; | ||
new FilterOperator(inputReader, output, _ => { | ||
called = true; | ||
return true; | ||
}); | ||
|
||
const outReader = output.newReader(); | ||
outReader.setOperator(new NoOp()); | ||
|
||
inputWriter.queueData([ | ||
1, | ||
new Multiset([ | ||
[1, 1], | ||
[2, 2], | ||
[1, -1], | ||
[2, -2], | ||
]), | ||
]); | ||
inputWriter.notify(1); | ||
inputWriter.notifyCommitted(1); | ||
|
||
// we run the graph but the filter is not run until we pull on it | ||
expect(called).toBe(false); | ||
|
||
const items = outReader.drain(1); | ||
// consume all the rows | ||
[...items[0].entries]; | ||
expect(called).toBe(true); | ||
}); |
Oops, something went wrong.