Skip to content

Commit

Permalink
Update to Comunica v4 prerelease
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Oct 10, 2024
1 parent 9e83d5c commit 1640873
Show file tree
Hide file tree
Showing 20 changed files with 4,821 additions and 2,009 deletions.
6 changes: 0 additions & 6 deletions .github/get-next-alpha-version.sh

This file was deleted.

20 changes: 0 additions & 20 deletions .github/typedoc-json.sh

This file was deleted.

Empty file.
12 changes: 10 additions & 2 deletions engines/config-query-sparql-hdt/config/config-default.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/config-query-sparql/^3.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/config-query-sparql/^4.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/config-query-sparql-hdt/^3.0.0/components/context.jsonld"
],
"import": [
"ccqs:config/bindings-aggregator-factory/actors.json",
"ccqs:config/bindings-aggregator-factory/mediators.json",
"ccqs:config/context-preprocess/actors.json",
"ccqs:config/context-preprocess/mediators.json",
"ccqs:config/expression-evaluator-factory/actors.json",
"ccqs:config/expression-evaluator-factory/mediators.json",
"ccqs:config/function-factory/actors.json",
"ccqs:config/function-factory/mediators.json",
"ccqs:config/hash-bindings/actors.json",
"ccqs:config/hash-bindings/mediators.json",
"ccqs:config/hash-quads/actors.json",
Expand Down Expand Up @@ -60,6 +66,8 @@
"ccqs:config/rdf-update-hypermedia/actors.json",
"ccqs:config/rdf-update-hypermedia/mediators.json",
"ccqs:config/rdf-update-quads/actors.json",
"ccqs:config/rdf-update-quads/mediators.json"
"ccqs:config/rdf-update-quads/mediators.json",
"ccqs:config/term-comparator-factory/actors.json",
"ccqs:config/term-comparator-factory/mediators.json"
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/runner/^3.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/runner/^4.0.0/components/context.jsonld",

"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-source-identify-hdt/^3.0.0/components/context.jsonld"
],
Expand Down
6 changes: 5 additions & 1 deletion engines/config-query-sparql-hdt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"description": "default configuration files for Comunica SPARQL HDT",
"lsd:module": true,
"license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/comunica-association"
},
"homepage": "https://comunica.dev/",
"repository": {
"type": "git",
Expand Down Expand Up @@ -41,6 +45,6 @@
"build:components": "componentsjs-generator"
},
"dependencies": {
"@comunica/config-query-sparql": "~3.3.0"
"@comunica/config-query-sparql": "~4.0.1-alpha.48.0"
}
}
Empty file.
391 changes: 243 additions & 148 deletions engines/query-sparql-hdt/package.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
"npmClient": "yarn",
"npmClientArgs": [
"--frozen-lockfile"
]
}
],
"lerna-script-tasks": "./node_modules/@comunica/utils-monorepo/lib/depCheck.js"
}
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"test-ci": "jest --ci --maxWorkers=4 --coverage",
"lint": "eslint . --cache",
"clean": "rm -rf ./node_modules && rm -rf ./packages/*/node_modules",
"depcheck": "lerna-script depcheckTask @comunica/config-query-sparql-hdt",
"depcheck:fix": "lerna-script depfixTask @comunica/config-query-sparql-hdt",
"ncu:all": "lerna-script updateTask",
"ncu:major:all": "lerna-script updateTaskMajor",
"build": "npm run build:ts && npm run build:components",
"build:ts": "tsc",
"build:components": "componentsjs-generator engines/* packages/*",
Expand All @@ -22,30 +26,35 @@
"publish": "yarn run build",
"publish-release": "lerna publish",
"publish-bare": "lerna exec -- npm publish --silent",
"publish-canary": "yarn run build && lerna version prerelease --preid alpha.$(.github/get-next-alpha-version.sh) --exact --ignore-scripts --force-publish --no-push --no-git-tag-version --yes && git update-index --assume-unchanged $(git ls-files | tr '\\n' ' ') && lerna publish from-package --no-git-reset --pre-dist-tag next --force-publish --no-push --no-git-tag-version --yes && git update-index --no-assume-unchanged $(git ls-files | tr '\\n' ' ') && git checkout .",
"doc": "./.github/typedoc-json.sh create && typedoc && ./.github/typedoc-json.sh remove",
"publish-canary": "yarn run build && lerna version prerelease --preid alpha.$(node_modules/@comunica/utils-monorepo/sh/get-next-alpha-version.sh @comunica/query-sparql-hdt) --exact --ignore-scripts --force-publish --no-push --no-git-tag-version --yes && git update-index --assume-unchanged $(git ls-files | tr '\\n' ' ') && lerna publish from-package --no-git-reset --pre-dist-tag next --force-publish --no-push --no-git-tag-version --yes && git update-index --no-assume-unchanged $(git ls-files | tr '\\n' ' ') && git checkout .",
"doc": "node_modules/@comunica/utils-monorepo/sh/typedoc-json.sh create && typedoc && node_modules/@comunica/utils-monorepo/sh/typedoc-json.sh remove",
"postinstall": "yarn run build && lerna run prepare",
"version": "manual-git-changelog onversion"
},
"devDependencies": {
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.4",
"@comunica/jest": "^3.3.0",
"@comunica/packager": "4.0.1-alpha.48.0",
"@comunica/utils-jest": "4.0.1-alpha.48.0",
"@comunica/utils-monorepo": "4.0.1-alpha.48.0",
"@rubensworks/eslint-config": "^3.0.0",
"@rubensworks/process-sparql-benchmark-results": "^1.3.4",
"@types/jest": "^29.0.0",
"@types/node": "^20.0.0",
"asynciterator": "^3.2.1",
"babel-loader": "^9.0.0",
"componentsjs-generator": "^4.0.1",
"componentsjs-generator": "^4.2.0",
"cross-fetch": "^4.0.0",
"depcheck": "^1.4.3",
"eslint": "^8.57.0",
"immutable": "^4.0.0",
"jest": "^29.0.0",
"jest-rdf": "^1.7.0",
"lerna": "^8.0.0",
"lerna-script": "^1.4.0",
"manual-git-changelog": "^1.0.0",
"nodemon": "^3.0.0",
"npm-check-updates": "^17.0.0",
"pre-commit": "^1.2.2",
"rdf-data-factory": "^1.1.0",
"rdf-quad": "^1.5.0",
Expand Down
Empty file.
1 change: 1 addition & 0 deletions packages/actor-query-source-identify-hdt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ After installing, this package can be added to your engine's configuration as fo

### Config Parameters

* `httpInvalidator`: An optional actor that listens to HTTP invalidation events.
* `mediatorMergeBindingsContext`: A mediator over the [Merge Bindings Context bus](https://github.com/comunica/comunica/tree/master/packages/bus-merge-bindings-context).
* `maxBufferSize`: The maximum number of triples that can be retrieved from HDT files in a single call, defaults to `128`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BindingsFactory } from '@comunica/bindings-factory';
import type { ActorHttpInvalidateListenable, IActionHttpInvalidate } from '@comunica/bus-http-invalidate';
import type { MediatorMergeBindingsContext } from '@comunica/bus-merge-bindings-context';
import type {
IActionQuerySourceIdentify,
Expand All @@ -8,41 +8,54 @@ import type {
import {
ActorQuerySourceIdentify,
} from '@comunica/bus-query-source-identify';
import type { IActorTest } from '@comunica/core';
import { ActionContext } from '@comunica/core';
import { KeysInitQuery } from '@comunica/context-entries';
import type { IActorTest, TestResult } from '@comunica/core';
import { ActionContext, failTest, passTestVoid } from '@comunica/core';
import { BindingsFactory } from '@comunica/utils-bindings-factory';
import * as HDT from 'hdt';
import { QuerySourceHdt } from './QuerySourceHdt';

/**
* A comunica Hdt Query Source Identify Actor.
*/
export class ActorQuerySourceIdentifyHdt extends ActorQuerySourceIdentify {
public readonly httpInvalidator: ActorHttpInvalidateListenable;
private createdSources: WeakRef<QuerySourceHdt>[] = [];

public readonly mediatorMergeBindingsContext: MediatorMergeBindingsContext;
public readonly maxBufferSize: number;

public constructor(args: IActorQuerySourceIdentifyHdtArgs) {
super(args);
this.httpInvalidator.addInvalidateListener(
({ url }: IActionHttpInvalidate) => {
if (!url) {
// eslint-disable-next-line ts/no-floating-promises
this.clearCache();
}
},
);
}

public async test(action: IActionQuerySourceIdentify): Promise<IActorTest> {
public async test(action: IActionQuerySourceIdentify): Promise<TestResult<IActorTest>> {
const source = action.querySourceUnidentified;
if (source.type !== 'hdt') {
throw new Error(`${this.name} requires a single query source with hdt type to be present in the context.`);
return failTest(`${this.name} requires a single query source with hdt type to be present in the context.`);
}
if (typeof source.value !== 'string') {
throw new TypeError(`${this.name} received an invalid hdt query source.`);
return failTest(`${this.name} received an invalid hdt query source.`);
}
return true;
return passTestVoid();
}

public async run(action: IActionQuerySourceIdentify): Promise<IActorQuerySourceIdentifyOutput> {
const dataFactory = action.context.getSafe(KeysInitQuery.dataFactory);
const path = <string> action.querySourceUnidentified.value;
const source = new QuerySourceHdt(
path,
await HDT.fromFile(path),
await BindingsFactory.create(this.mediatorMergeBindingsContext, action.context),
dataFactory,
await BindingsFactory.create(this.mediatorMergeBindingsContext, action.context, dataFactory),
this.maxBufferSize,
);
this.createdSources.push(new WeakRef(source));
Expand All @@ -55,16 +68,22 @@ export class ActorQuerySourceIdentifyHdt extends ActorQuerySourceIdentify {
};
}

public override async deinitialize(): Promise<any> {
public async clearCache(): Promise<any> {
for (const source of this.createdSources) {
await source.deref()?.dispose();
}
this.createdSources = [];
return super.deinitialize();
}
}

export interface IActorQuerySourceIdentifyHdtArgs extends IActorQuerySourceIdentifyArgs {
/* eslint-disable max-len */
/**
* An actor that listens to HTTP invalidation events
* @default {<default_invalidator> a <npmd:@comunica/bus-http-invalidate/^4.0.0/components/ActorHttpInvalidateListenable.jsonld#ActorHttpInvalidateListenable>}
*/
httpInvalidator: ActorHttpInvalidateListenable;
/* eslint-enable max-len */
/**
* A mediator for creating binding context merge handlers
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MetadataValidationState } from '@comunica/metadata';
import { MetadataValidationState } from '@comunica/utils-metadata';
import type * as RDF from '@rdfjs/types';
import type { BufferedIteratorOptions } from 'asynciterator';
import { BufferedIterator } from 'asynciterator';
Expand Down
17 changes: 13 additions & 4 deletions packages/actor-query-source-identify-hdt/lib/QuerySourceHdt.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import type { BindingsFactory } from '@comunica/bindings-factory';
import { quadsToBindings } from '@comunica/bus-query-source-identify';
import { KeysQueryOperation } from '@comunica/context-entries';
import { MetadataValidationState } from '@comunica/metadata';
import type { IQuerySource, FragmentSelectorShape, IActionContext, BindingsStream } from '@comunica/types';
import type {
IQuerySource,
FragmentSelectorShape,
IActionContext,
BindingsStream,
ComunicaDataFactory,
} from '@comunica/types';
import type { BindingsFactory } from '@comunica/utils-bindings-factory';
import { MetadataValidationState } from '@comunica/utils-metadata';
import type * as RDF from '@rdfjs/types';
import type { AsyncIterator } from 'asynciterator';
import { ArrayIterator } from 'asynciterator';
Expand Down Expand Up @@ -35,18 +41,21 @@ export class QuerySourceHdt implements IQuerySource {
public referenceValue: string;
protected readonly hdtPath: string;
protected readonly hdtDocument: HDT.Document;
private readonly dataFactory: ComunicaDataFactory;
private readonly bindingsFactory: BindingsFactory;
private readonly maxBufferSize: number;

public constructor(
hdtPath: string,
hdtDocument: HDT.Document,
dataFactory: ComunicaDataFactory,
bindingsFactory: BindingsFactory,
maxBufferSize: number,
) {
this.hdtPath = hdtPath;
this.referenceValue = hdtPath;
this.hdtDocument = hdtDocument;
this.dataFactory = dataFactory;
this.bindingsFactory = bindingsFactory;
this.maxBufferSize = maxBufferSize;
}
Expand All @@ -66,7 +75,6 @@ export class QuerySourceHdt implements IQuerySource {
it.setProperty('metadata', {
state: new MetadataValidationState(),
cardinality: { type: 'exact', value: 0 },
canContainUndefs: false,
});
} else {
// Create an iterator over the HDT document
Expand All @@ -82,6 +90,7 @@ export class QuerySourceHdt implements IQuerySource {
return quadsToBindings(
it,
operation,
this.dataFactory,
this.bindingsFactory,
Boolean(context.get(KeysQueryOperation.unionDefaultGraph)),
);
Expand Down
21 changes: 13 additions & 8 deletions packages/actor-query-source-identify-hdt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"description": "A hdt query-source-identify actor",
"lsd:module": true,
"license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/comunica-association"
},
"homepage": "https://comunica.dev/",
"repository": {
"type": "git",
Expand Down Expand Up @@ -37,17 +41,18 @@
"build:components": "componentsjs-generator"
},
"dependencies": {
"@comunica/bindings-factory": "^3.3.0",
"@comunica/bus-merge-bindings-context": "^3.3.0",
"@comunica/bus-query-source-identify": "^3.3.0",
"@comunica/context-entries": "^3.3.0",
"@comunica/core": "^3.3.0",
"@comunica/metadata": "^3.3.0",
"@comunica/types": "^3.3.0",
"@comunica/bus-http-invalidate": "4.0.1-alpha.48.0",
"@comunica/bus-merge-bindings-context": "4.0.1-alpha.48.0",
"@comunica/bus-query-source-identify": "4.0.1-alpha.48.0",
"@comunica/context-entries": "4.0.1-alpha.48.0",
"@comunica/core": "4.0.1-alpha.48.0",
"@comunica/types": "4.0.1-alpha.48.0",
"@comunica/utils-bindings-factory": "4.0.1-alpha.48.0",
"@comunica/utils-metadata": "4.0.1-alpha.48.0",
"@rdfjs/types": "*",
"asynciterator": "^3.9.0",
"hdt": "^3.1.1",
"rdf-data-factory": "^1.1.1",
"sparqlalgebrajs": "^4.3.3"
"sparqlalgebrajs": "^4.3.8"
}
}
Loading

2 comments on commit 1640873

@rubensworks
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmarks total results

Benchmark suite Current: 1640873 Previous: 9e83d5c Ratio
WatDiv-HDT 2988 ms 3894 ms 0.77
BSBM-HDT 413 ms 720 ms 0.57

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance benchmarks succeeded! 🚀

[Summarized results] [Detailed results]

Please sign in to comment.