Skip to content

Commit

Permalink
Refactoring and renaming diff => isAddition
Browse files Browse the repository at this point in the history
  • Loading branch information
maartyman committed Nov 6, 2024
1 parent 10932ab commit 5a1daff
Show file tree
Hide file tree
Showing 50 changed files with 1,066 additions and 1,082 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import '@incremunica/incremental-jest';
import type { EventEmitter } from 'events';
import type { BindingsStream, QueryStringContext } from '@comunica/types';
import type { BindingsFactory } from '@comunica/utils-bindings-factory';
import { ActionContextKeyIsAddition } from '@incremunica/actor-merge-bindings-context-is-addition';
import { KeysBindings } from '@incremunica/context-entries';
import { DevTools } from '@incremunica/dev-tools';
import { StreamingStore } from '@incremunica/incremental-rdf-streaming-store';
import type { Quad } from '@incremunica/incremental-types';
Expand Down Expand Up @@ -64,12 +64,12 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('s'), DF.namedNode('s1') ],
[ DF.variable('p'), DF.namedNode('p1') ],
[ DF.variable('o'), DF.namedNode('o1') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true),
]).setContextEntry(KeysBindings.isAddition, true),
BF.bindings([
[ DF.variable('s'), DF.namedNode('s2') ],
[ DF.variable('p'), DF.namedNode('p2') ],
[ DF.variable('o'), DF.namedNode('o2') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true),
]).setContextEntry(KeysBindings.isAddition, true),
]);

streamingStore.addQuad(quad('s3', 'p3', 'o3'));
Expand All @@ -79,7 +79,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('s'), DF.namedNode('s3') ],
[ DF.variable('p'), DF.namedNode('p3') ],
[ DF.variable('o'), DF.namedNode('o3') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true),
]).setContextEntry(KeysBindings.isAddition, true),
]);

streamingStore.removeQuad(quad('s3', 'p3', 'o3'));
Expand All @@ -89,7 +89,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('s'), DF.namedNode('s3') ],
[ DF.variable('p'), DF.namedNode('p3') ],
[ DF.variable('o'), DF.namedNode('o3') ],
]).setContextEntry(new ActionContextKeyIsAddition(), false),
]).setContextEntry(KeysBindings.isAddition, false),
]);

streamingStore.end();
Expand All @@ -113,7 +113,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('o1'), DF.namedNode('o1') ],
[ DF.variable('p2'), DF.namedNode('p2') ],
[ DF.variable('o2'), DF.namedNode('o2') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true),
]).setContextEntry(KeysBindings.isAddition, true),
]);

streamingStore.addQuad(quad('o1', 'p3', 'o3'));
Expand All @@ -125,7 +125,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('o1'), DF.namedNode('o1') ],
[ DF.variable('p2'), DF.namedNode('p3') ],
[ DF.variable('o2'), DF.namedNode('o3') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true),
]).setContextEntry(KeysBindings.isAddition, true),
]);

streamingStore.removeQuad(quad('o1', 'p3', 'o3'));
Expand All @@ -137,7 +137,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('o1'), DF.namedNode('o1') ],
[ DF.variable('p2'), DF.namedNode('p3') ],
[ DF.variable('o2'), DF.namedNode('o3') ],
]).setContextEntry(new ActionContextKeyIsAddition(), false),
]).setContextEntry(KeysBindings.isAddition, false),
]);

streamingStore.end();
Expand Down
26 changes: 13 additions & 13 deletions engines/query-sparql-incremental/test/QuerySparql-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { EventEmitter } from 'node:events';
import * as http from 'node:http';
import type { Bindings, BindingsStream, QueryStringContext } from '@comunica/types';
import type { BindingsFactory } from '@comunica/utils-bindings-factory';
import { ActionContextKeyIsAddition } from '@incremunica/actor-merge-bindings-context-is-addition';
import { KeysBindings } from '@incremunica/context-entries';
import { DevTools } from '@incremunica/dev-tools';
import { StreamingStore } from '@incremunica/incremental-rdf-streaming-store';
import type { Quad } from '@incremunica/incremental-types';
Expand Down Expand Up @@ -65,12 +65,12 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('s'), DF.namedNode('s1') ],
[ DF.variable('p'), DF.namedNode('p1') ],
[ DF.variable('o'), DF.namedNode('o1') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true),
]).setContextEntry(KeysBindings.isAddition, true),
BF.bindings([
[ DF.variable('s'), DF.namedNode('s2') ],
[ DF.variable('p'), DF.namedNode('p2') ],
[ DF.variable('o'), DF.namedNode('o2') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true),
]).setContextEntry(KeysBindings.isAddition, true),
]);

streamingStore.addQuad(quad('s3', 'p3', 'o3'));
Expand All @@ -80,7 +80,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('s'), DF.namedNode('s3') ],
[ DF.variable('p'), DF.namedNode('p3') ],
[ DF.variable('o'), DF.namedNode('o3') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true),
]).setContextEntry(KeysBindings.isAddition, true),
]);

streamingStore.removeQuad(quad('s3', 'p3', 'o3'));
Expand All @@ -90,7 +90,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('s'), DF.namedNode('s3') ],
[ DF.variable('p'), DF.namedNode('p3') ],
[ DF.variable('o'), DF.namedNode('o3') ],
]).setContextEntry(new ActionContextKeyIsAddition(), false),
]).setContextEntry(KeysBindings.isAddition, false),
]);

streamingStore.end();
Expand All @@ -114,7 +114,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('o1'), DF.namedNode('o1') ],
[ DF.variable('p2'), DF.namedNode('p2') ],
[ DF.variable('o2'), DF.namedNode('o2') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true),
]).setContextEntry(KeysBindings.isAddition, true),
]);

streamingStore.addQuad(quad('o1', 'p3', 'o3'));
Expand All @@ -126,7 +126,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('o1'), DF.namedNode('o1') ],
[ DF.variable('p2'), DF.namedNode('p3') ],
[ DF.variable('o2'), DF.namedNode('o3') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true),
]).setContextEntry(KeysBindings.isAddition, true),
]);

streamingStore.removeQuad(quad('o1', 'p3', 'o3'));
Expand All @@ -138,7 +138,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('o1'), DF.namedNode('o1') ],
[ DF.variable('p2'), DF.namedNode('p3') ],
[ DF.variable('o2'), DF.namedNode('o3') ],
]).setContextEntry(new ActionContextKeyIsAddition(), false),
]).setContextEntry(KeysBindings.isAddition, false),
]);

streamingStore.end();
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('s'), DF.namedNode('http://localhost:8787/s1') ],
[ DF.variable('p'), DF.namedNode('http://localhost:8787/p1') ],
[ DF.variable('o'), DF.namedNode('http://localhost:8787/o1') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true));
]).setContextEntry(KeysBindings.isAddition, true));
});

it('simple addition update query', async() => {
Expand All @@ -222,7 +222,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('s'), DF.namedNode('http://localhost:8787/s1') ],
[ DF.variable('p'), DF.namedNode('http://localhost:8787/p1') ],
[ DF.variable('o'), DF.namedNode('http://localhost:8787/o1') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true));
]).setContextEntry(KeysBindings.isAddition, true));

fetchData.dataString += '\n<http://localhost:8787/s2> <http://localhost:8787/p2> <http://localhost:8787/o2> .';
fetchData.etag = '1';
Expand All @@ -233,7 +233,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('s'), DF.namedNode('http://localhost:8787/s2') ],
[ DF.variable('p'), DF.namedNode('http://localhost:8787/p2') ],
[ DF.variable('o'), DF.namedNode('http://localhost:8787/o2') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true));
]).setContextEntry(KeysBindings.isAddition, true));
});

it('simple deletion update query', async() => {
Expand All @@ -252,7 +252,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('s'), DF.namedNode('http://localhost:8787/s1') ],
[ DF.variable('p'), DF.namedNode('http://localhost:8787/p1') ],
[ DF.variable('o'), DF.namedNode('http://localhost:8787/o1') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true));
]).setContextEntry(KeysBindings.isAddition, true));

fetchData.dataString = '';
fetchData.etag = '1';
Expand All @@ -263,7 +263,7 @@ describe('System test: QuerySparql (without polly)', () => {
[ DF.variable('s'), DF.namedNode('http://localhost:8787/s1') ],
[ DF.variable('p'), DF.namedNode('http://localhost:8787/p1') ],
[ DF.variable('o'), DF.namedNode('http://localhost:8787/o1') ],
]).setContextEntry(new ActionContextKeyIsAddition(), false));
]).setContextEntry(KeysBindings.isAddition, false));
});

// eslint-disable-next-line jest/no-commented-out-tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '@comunica/bus-merge-bindings-context';
import type { IActorTest, TestResult } from '@comunica/core';
import { passTestVoid } from '@comunica/core';
import type { IActionContextKey } from '@comunica/types';

/**
* A incremunica actor for the creation of merge handlers for binding context keys.
Expand All @@ -26,15 +25,10 @@ export class ActorMergeBindingsContextIsAddition extends ActorMergeBindingsConte
const handlerFunc = (...args: boolean[]): boolean => args.reduce((acc, cur) => acc && cur);
return {
mergeHandlers: {
'@incremunica/actor-query-operation-incremental-distinct-hash:isAddition': {
'@incremunica/bindings:isAddition': {
run: handlerFunc,
},
},
};
}
}

export class ActionContextKeyIsAddition implements IActionContextKey<boolean> {
public readonly name = '@incremunica/actor-query-operation-incremental-distinct-hash:isAddition';
public readonly dummy: boolean | undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
},
"dependencies": {
"@comunica/bus-merge-bindings-context": "^4.0.1",
"@comunica/core": "^4.0.1",
"@comunica/types": "^4.0.1"
"@comunica/core": "^4.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ActionContext, Bus } from '@comunica/core';
import type { IActionContext } from '@comunica/types';
import type { BindingsFactory } from '@comunica/utils-bindings-factory';
import { KeysBindings } from '@incremunica/context-entries';
import { DevTools } from '@incremunica/dev-tools';
import { DataFactory } from 'rdf-data-factory';
import { ActionContextKeyIsAddition, ActorMergeBindingsContextIsAddition } from '../lib';
import { ActorMergeBindingsContextIsAddition } from '../lib';
import '@incremunica/incremental-jest';

const DF = new DataFactory();
Expand All @@ -27,7 +28,7 @@ describe('ActorMergeBindingsContextIsAddition', () => {
await expect(actor.run({ context })).resolves.toMatchObject(
{
mergeHandlers: {
'@incremunica/actor-query-operation-incremental-distinct-hash:isAddition': {
'@incremunica/bindings:isAddition': {
run: expect.any(Function),
},
},
Expand All @@ -38,7 +39,7 @@ describe('ActorMergeBindingsContextIsAddition', () => {
let mergeHandler: (...args: boolean[]) => boolean;
beforeEach(async() => {
mergeHandler = (await actor.run({ context }))
.mergeHandlers['@incremunica/actor-query-operation-incremental-distinct-hash:isAddition'].run;
.mergeHandlers['@incremunica/bindings:isAddition'].run;
});

it('should return false if the first is false', async() => {
Expand Down Expand Up @@ -77,25 +78,25 @@ describe('ActorMergeBindingsContextIsAddition', () => {
it('should work with addition bindings', async() => {
const bindings1 = BF.bindings([
[ DF.variable('a'), DF.literal('1') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true);
]).setContextEntry(KeysBindings.isAddition, true);
const bindings2 = BF.bindings([
[ DF.variable('a'), DF.literal('1') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true);
]).setContextEntry(KeysBindings.isAddition, true);
expect(bindings1.merge(bindings2)).toEqualBindings(BF.bindings([
[ DF.variable('a'), DF.literal('1') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true));
]).setContextEntry(KeysBindings.isAddition, true));
});

it('should work with deletion bindings', async() => {
const bindings1 = BF.bindings([
[ DF.variable('a'), DF.literal('1') ],
]).setContextEntry(new ActionContextKeyIsAddition(), false);
]).setContextEntry(KeysBindings.isAddition, false);
const bindings2 = BF.bindings([
[ DF.variable('a'), DF.literal('1') ],
]).setContextEntry(new ActionContextKeyIsAddition(), true);
]).setContextEntry(KeysBindings.isAddition, true);
expect(bindings1.merge(bindings2)).toEqualBindings(BF.bindings([
[ DF.variable('a'), DF.literal('1') ],
]).setContextEntry(new ActionContextKeyIsAddition(), false));
]).setContextEntry(KeysBindings.isAddition, false));
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
} from '@comunica/types';
import type { Bindings } from '@comunica/utils-bindings-factory';
import { getSafeBindings, getSafeQuads } from '@comunica/utils-query-operation';
import { ActionContextKeyIsAddition } from '@incremunica/actor-merge-bindings-context-is-addition';
import { KeysBindings } from '@incremunica/context-entries';
import type { Quad } from '@incremunica/incremental-types';
import type { AsyncIterator } from 'asynciterator';
import type * as RDF from 'rdf-js';
Expand Down Expand Up @@ -84,7 +84,7 @@ export class ActorQueryOperationIncrementalDistinctHash extends ActorQueryOperat
return (bindings: Bindings) => {
const hash = hashFunction(bindings, variables);
const hasMapValue = hashes.get(hash);
if (bindings.getContextEntry(new ActionContextKeyIsAddition())) {
if (bindings.getContextEntry(KeysBindings.isAddition)) {
if (hasMapValue) {
hashes.set(hash, hasMapValue + 1);
return false;
Expand Down Expand Up @@ -118,8 +118,8 @@ export class ActorQueryOperationIncrementalDistinctHash extends ActorQueryOperat
const quad = <Quad>rdfQuad;
const hash = hashFunction(quad);
const hasMapValue = hashes.get(hash);
quad.diff = quad.diff ?? true;
if (quad.diff) {
quad.isAddition = quad.isAddition ?? true;
if (quad.isAddition) {
if (hasMapValue) {
hashes.set(hash, hasMapValue + 1);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@comunica/types": "^4.0.1",
"@comunica/utils-bindings-factory": "^4.0.1",
"@comunica/utils-query-operation": "^4.0.2",
"@incremunica/actor-merge-bindings-context-is-addition": "^1.3.0",
"@incremunica/context-entries": "^1.3.0",
"rdf-js": "^4.0.2",
"sparqlalgebrajs": "^4.3.8"
}
Expand Down
Loading

0 comments on commit 5a1daff

Please sign in to comment.