@comunica/actor-rdf-join-inner-multi-bind 4.4.2-alpha.49.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/ActorRdfJoinMultiBind.jsonld +0 -0
- package/components/components.jsonld +0 -0
- package/components/context.jsonld +0 -0
- package/lib/ActorRdfJoinMultiBind.d.ts +2 -2
- package/lib/ActorRdfJoinMultiBind.js +14 -15
- package/lib/ActorRdfJoinMultiBind.js.map +1 -1
- package/lib/index.d.ts +0 -0
- package/lib/index.js +0 -0
- package/lib/index.js.map +0 -0
- package/package.json +14 -14
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -6,8 +6,8 @@ import type { MediatorRdfJoinEntriesSort } from '@comunica/bus-rdf-join-entries-
|
|
|
6
6
|
import type { TestResult } from '@comunica/core';
|
|
7
7
|
import type { IMediatorTypeJoinCoefficients } from '@comunica/mediatortype-join-coefficients';
|
|
8
8
|
import type { Bindings, BindingsStream, IJoinEntryWithMetadata } from '@comunica/types';
|
|
9
|
-
import { AlgebraFactory, Algebra } from '@comunica/utils-algebra';
|
|
10
9
|
import { BindingsFactory } from '@comunica/utils-bindings-factory';
|
|
10
|
+
import { Factory, Algebra } from 'sparqlalgebrajs';
|
|
11
11
|
/**
|
|
12
12
|
* A comunica Multi-way Bind RDF Join Actor.
|
|
13
13
|
*/
|
|
@@ -30,7 +30,7 @@ export declare class ActorRdfJoinMultiBind extends ActorRdfJoin<IActorRdfJoinMul
|
|
|
30
30
|
* @param optional If the original bindings should be emitted when the resulting bindings stream is empty.
|
|
31
31
|
* @return {BindingsStream}
|
|
32
32
|
*/
|
|
33
|
-
static createBindStream(bindOrder: BindOrder, baseStream: BindingsStream, operations: Algebra.Operation[], operationBinder: (boundOperations: Algebra.Operation[], operationBindings: Bindings) => Promise<BindingsStream>, optional: boolean, algebraFactory:
|
|
33
|
+
static createBindStream(bindOrder: BindOrder, baseStream: BindingsStream, operations: Algebra.Operation[], operationBinder: (boundOperations: Algebra.Operation[], operationBindings: Bindings) => Promise<BindingsStream>, optional: boolean, algebraFactory: Factory, bindingsFactory: BindingsFactory): BindingsStream;
|
|
34
34
|
getOutput(action: IActionRdfJoin, sideData: IActorRdfJoinMultiBindTestSideData): Promise<IActorRdfJoinOutputInner>;
|
|
35
35
|
canBindWithOperation(operation: Algebra.Operation): boolean;
|
|
36
36
|
getJoinCoefficients(action: IActionRdfJoin, sideData: IActorRdfJoinTestSideData): Promise<TestResult<IMediatorTypeJoinCoefficients, IActorRdfJoinMultiBindTestSideData>>;
|
|
@@ -4,10 +4,10 @@ exports.ActorRdfJoinMultiBind = void 0;
|
|
|
4
4
|
const bus_rdf_join_1 = require("@comunica/bus-rdf-join");
|
|
5
5
|
const context_entries_1 = require("@comunica/context-entries");
|
|
6
6
|
const core_1 = require("@comunica/core");
|
|
7
|
-
const utils_algebra_1 = require("@comunica/utils-algebra");
|
|
8
7
|
const utils_bindings_factory_1 = require("@comunica/utils-bindings-factory");
|
|
9
8
|
const utils_query_operation_1 = require("@comunica/utils-query-operation");
|
|
10
9
|
const asynciterator_1 = require("asynciterator");
|
|
10
|
+
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
|
|
11
11
|
/**
|
|
12
12
|
* A comunica Multi-way Bind RDF Join Actor.
|
|
13
13
|
*/
|
|
@@ -51,7 +51,6 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
|
|
|
51
51
|
return new asynciterator_1.UnionIterator(baseStream.transform({
|
|
52
52
|
map: binder,
|
|
53
53
|
optional,
|
|
54
|
-
autoStart: false,
|
|
55
54
|
}), { autoStart: false });
|
|
56
55
|
default:
|
|
57
56
|
// eslint-disable-next-line ts/restrict-template-expressions
|
|
@@ -60,19 +59,19 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
|
|
|
60
59
|
}
|
|
61
60
|
async getOutput(action, sideData) {
|
|
62
61
|
const dataFactory = action.context.getSafe(context_entries_1.KeysInitQuery.dataFactory);
|
|
63
|
-
const algebraFactory = new
|
|
62
|
+
const algebraFactory = new sparqlalgebrajs_1.Factory(dataFactory);
|
|
64
63
|
const bindingsFactory = await utils_bindings_factory_1.BindingsFactory.create(this.mediatorMergeBindingsContext, action.context, dataFactory);
|
|
65
64
|
const entries = sideData.entriesSorted;
|
|
66
65
|
this.logDebug(action.context, 'First entry for Bind Join: ', () => ({
|
|
67
|
-
entry:
|
|
66
|
+
entry: entries[0].operation,
|
|
68
67
|
cardinality: entries[0].metadata.cardinality,
|
|
69
68
|
order: entries[0].metadata.order,
|
|
70
69
|
availableOrders: entries[0].metadata.availableOrders,
|
|
71
70
|
}));
|
|
72
|
-
//
|
|
71
|
+
// Close the non-smallest streams
|
|
73
72
|
for (const [i, element] of entries.entries()) {
|
|
74
73
|
if (i !== 0) {
|
|
75
|
-
element.output.bindingsStream.
|
|
74
|
+
element.output.bindingsStream.close();
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
77
|
// Take the stream with the lowest cardinality
|
|
@@ -108,15 +107,15 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
|
|
|
108
107
|
}
|
|
109
108
|
canBindWithOperation(operation) {
|
|
110
109
|
let valid = true;
|
|
111
|
-
|
|
112
|
-
[
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
[
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
110
|
+
sparqlalgebrajs_1.Util.recurseOperation(operation, {
|
|
111
|
+
[sparqlalgebrajs_1.Algebra.types.EXTEND]() {
|
|
112
|
+
valid = false;
|
|
113
|
+
return false;
|
|
114
|
+
},
|
|
115
|
+
[sparqlalgebrajs_1.Algebra.types.GROUP]() {
|
|
116
|
+
valid = false;
|
|
117
|
+
return false;
|
|
118
|
+
},
|
|
120
119
|
});
|
|
121
120
|
return valid;
|
|
122
121
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorRd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B,CAChD;SACJ,EAAE,EAAE,GAAG,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC,CAAC;IACtD,CAAC;CACF;AAhPD,sDAgPC","sourcesContent":["import type { MediatorMergeBindingsContext } from '@comunica/bus-merge-bindings-context';\nimport type { MediatorQueryOperation } from '@comunica/bus-query-operation';\nimport type {\n IActionRdfJoin,\n IActorRdfJoinOutputInner,\n IActorRdfJoinArgs,\n IActorRdfJoinTestSideData,\n} from '@comunica/bus-rdf-join';\nimport { ActorRdfJoin } from '@comunica/bus-rdf-join';\nimport type { MediatorRdfJoinEntriesSort } from '@comunica/bus-rdf-join-entries-sort';\nimport { KeysInitQuery, KeysQueryOperation } from '@comunica/context-entries';\nimport type { TestResult } from '@comunica/core';\nimport { passTestWithSideData, failTest } from '@comunica/core';\nimport type { IMediatorTypeJoinCoefficients } from '@comunica/mediatortype-join-coefficients';\nimport type {\n Bindings,\n BindingsStream,\n ComunicaDataFactory,\n IJoinEntryWithMetadata,\n IQueryOperationResultBindings,\n} from '@comunica/types';\nimport { AlgebraFactory, Algebra, algebraUtils } from '@comunica/utils-algebra';\nimport { BindingsFactory } from '@comunica/utils-bindings-factory';\nimport { getSafeBindings, materializeOperation } from '@comunica/utils-query-operation';\nimport { MultiTransformIterator, TransformIterator, UnionIterator } from 'asynciterator';\n\n/**\n * A comunica Multi-way Bind RDF Join Actor.\n */\nexport class ActorRdfJoinMultiBind extends ActorRdfJoin<IActorRdfJoinMultiBindTestSideData> {\n public readonly bindOrder: BindOrder;\n public readonly selectivityModifier: number;\n public readonly minMaxCardinalityRatio: number;\n public readonly mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;\n public readonly mediatorQueryOperation: MediatorQueryOperation;\n public readonly mediatorMergeBindingsContext: MediatorMergeBindingsContext;\n\n public constructor(args: IActorRdfJoinMultiBindArgs) {\n super(args, {\n logicalType: 'inner',\n physicalName: 'bind',\n canHandleUndefs: true,\n isLeaf: false,\n });\n }\n\n /**\n * Create a new bindings stream that takes every binding of the base stream\n * and binds it to the remaining patterns, evaluates those patterns, and emits all their bindings.\n *\n * @param bindOrder The order in which elements should be bound.\n * @param baseStream The base stream.\n * @param operations The operations to bind with each binding of the base stream.\n * @param operationBinder A callback to retrieve the bindings stream of bound operations.\n * @param optional If the original bindings should be emitted when the resulting bindings stream is empty.\n * @return {BindingsStream}\n */\n public static createBindStream(\n bindOrder: BindOrder,\n baseStream: BindingsStream,\n operations: Algebra.Operation[],\n operationBinder: (boundOperations: Algebra.Operation[], operationBindings: Bindings)\n => Promise<BindingsStream>,\n optional: boolean,\n algebraFactory: AlgebraFactory,\n bindingsFactory: BindingsFactory,\n ): BindingsStream {\n // Enable auto-start on sub-bindings during depth-first binding for best performance.\n const autoStartSubBindings = bindOrder === 'depth-first';\n\n // Create bindings function\n const binder = (bindings: Bindings): BindingsStream => {\n // We don't bind the filter because filters are always handled last,\n // and we need to avoid binding filters of sub-queries, which are to be handled first. (see spec test bind10)\n const subOperations = operations.map(operation => materializeOperation(\n operation,\n bindings,\n algebraFactory,\n bindingsFactory,\n { bindFilter: true },\n ));\n const bindingsMerger = (subBindings: Bindings): Bindings | undefined => subBindings.merge(bindings);\n return new TransformIterator(async() => (await operationBinder(subOperations, bindings))\n .transform({ map: bindingsMerger }), { maxBufferSize: 128, autoStart: autoStartSubBindings });\n };\n\n // Create an iterator that binds elements from the base stream in different orders\n switch (bindOrder) {\n case 'depth-first':\n return new MultiTransformIterator(baseStream, { autoStart: false, multiTransform: binder, optional });\n case 'breadth-first':\n return new UnionIterator(baseStream.transform({\n map: binder,\n optional,\n autoStart: false,\n }), { autoStart: false });\n default:\n // eslint-disable-next-line ts/restrict-template-expressions\n throw new Error(`Received request for unknown bind order: ${bindOrder}`);\n }\n }\n\n public async getOutput(\n action: IActionRdfJoin,\n sideData: IActorRdfJoinMultiBindTestSideData,\n ): Promise<IActorRdfJoinOutputInner> {\n const dataFactory: ComunicaDataFactory = action.context.getSafe(KeysInitQuery.dataFactory);\n const algebraFactory = new AlgebraFactory(dataFactory);\n const bindingsFactory = await BindingsFactory.create(\n this.mediatorMergeBindingsContext,\n action.context,\n dataFactory,\n );\n\n const entries = sideData.entriesSorted;\n this.logDebug(\n action.context,\n 'First entry for Bind Join: ',\n () => ({\n entry: { ...entries[0].operation, metadata: undefined },\n cardinality: entries[0].metadata.cardinality,\n order: entries[0].metadata.order,\n availableOrders: entries[0].metadata.availableOrders,\n }),\n );\n\n // Destroy the non-smallest streams\n for (const [ i, element ] of entries.entries()) {\n if (i !== 0) {\n element.output.bindingsStream.destroy();\n }\n }\n\n // Take the stream with the lowest cardinality\n const smallestStream: IQueryOperationResultBindings = entries[0].output;\n const remainingEntries = [ ...entries ];\n remainingEntries.splice(0, 1);\n\n // Bind the remaining patterns for each binding in the stream\n const subContext = action.context\n .set(KeysQueryOperation.joinLeftMetadata, entries[0].metadata)\n .set(KeysQueryOperation.joinRightMetadatas, remainingEntries.map(entry => entry.metadata));\n const bindingsStream: BindingsStream = ActorRdfJoinMultiBind.createBindStream(\n this.bindOrder,\n smallestStream.bindingsStream,\n remainingEntries.map(entry => entry.operation),\n async(operations: Algebra.Operation[], operationBindings: Bindings) => {\n // Send the materialized patterns to the mediator for recursive join evaluation.\n const operation = operations.length === 1 ?\n operations[0] :\n // Flattening should only take place if none of the input operations have associated metadata\n algebraFactory.createJoin(operations, operations.every(op => !op.metadata));\n const output = getSafeBindings(await this.mediatorQueryOperation.mediate(\n { operation, context: subContext?.set(KeysQueryOperation.joinBindings, operationBindings) },\n ));\n return output.bindingsStream;\n },\n false,\n algebraFactory,\n bindingsFactory,\n );\n\n return {\n result: {\n type: 'bindings',\n bindingsStream,\n metadata: () => this.constructResultMetadata(entries, entries.map(entry => entry.metadata), action.context),\n },\n physicalPlanMetadata: {\n bindIndex: sideData.entriesUnsorted.indexOf(entries[0]),\n bindOperation: entries[0].operation,\n bindOperationCardinality: entries[0].metadata.cardinality,\n bindOrder: this.bindOrder,\n },\n };\n }\n\n public canBindWithOperation(operation: Algebra.Operation): boolean {\n let valid = true;\n algebraUtils.visitOperation(operation, {\n [Algebra.Types.EXTEND]: { preVisitor: () => {\n valid = false;\n return { shortcut: true };\n } },\n [Algebra.Types.GROUP]: { preVisitor: () => {\n valid = false;\n return { shortcut: true };\n } },\n });\n\n return valid;\n }\n\n public async getJoinCoefficients(\n action: IActionRdfJoin,\n sideData: IActorRdfJoinTestSideData,\n ): Promise<TestResult<IMediatorTypeJoinCoefficients, IActorRdfJoinMultiBindTestSideData>> {\n let { metadatas } = sideData;\n\n // Order the entries so we can pick the first one (usually the one with the lowest cardinality)\n const entriesUnsorted = action.entries\n .map((entry, i) => ({ ...entry, metadata: metadatas[i] }));\n const entriesTest = await ActorRdfJoin\n .sortJoinEntries(this.mediatorJoinEntriesSort, entriesUnsorted, action.context);\n if (entriesTest.isFailed()) {\n return entriesTest;\n }\n const entriesSorted = entriesTest.get();\n metadatas = entriesSorted.map(entry => entry.metadata);\n\n const requestInitialTimes = ActorRdfJoin.getRequestInitialTimes(metadatas);\n const requestItemTimes = ActorRdfJoin.getRequestItemTimes(metadatas);\n\n // Determine first stream and remaining ones\n const remainingEntries = [ ...entriesSorted ];\n const remainingRequestInitialTimes = [ ...requestInitialTimes ];\n const remainingRequestItemTimes = [ ...requestItemTimes ];\n remainingEntries.splice(0, 1);\n remainingRequestInitialTimes.splice(0, 1);\n remainingRequestItemTimes.splice(0, 1);\n\n // Reject binding on some operation types\n if (remainingEntries\n .some(entry => !this.canBindWithOperation(entry.operation))) {\n return failTest(`Actor ${this.name} can not bind on Extend and Group operations`);\n }\n\n // Reject binding on modified operations, since using the output directly would be significantly more efficient.\n if (remainingEntries.some(entry => entry.operationModified)) {\n return failTest(`Actor ${this.name} can not be used over remaining entries with modified operations`);\n }\n\n // Only run this actor if the smallest stream is significantly smaller than the largest stream.\n // We must use Math.max, because the last metadata is not necessarily the biggest, but it's the least preferred.\n // If join entries are produced locally, we increase the possibility of doing this bind join, as it's cheap.\n const isRemoteAccess = requestItemTimes.some(time => time > 0);\n if (metadatas[0].cardinality.value * this.minMaxCardinalityRatio / (isRemoteAccess ? 1 : 3) >\n Math.max(...metadatas.map(metadata => metadata.cardinality.value))) {\n return failTest(`Actor ${this.name} can only run if the smallest stream is much smaller than largest stream`);\n }\n\n // Determine selectivities of smallest entry with all other entries\n const selectivities = await Promise.all(remainingEntries\n .map(async entry => (await this.mediatorJoinSelectivity.mediate({\n entries: [ entriesSorted[0], entry ],\n context: action.context,\n })).selectivity * this.selectivityModifier));\n\n // Determine coefficients for remaining entries\n const cardinalityRemaining = remainingEntries\n .map((entry, i) => entry.metadata.cardinality.value * selectivities[i])\n .reduce((sum, element) => sum + element, 0);\n const receiveInitialCostRemaining = remainingRequestInitialTimes\n .reduce((sum, element) => sum + element, 0);\n const receiveItemCostRemaining = remainingRequestItemTimes\n .reduce((sum, element) => sum + element, 0);\n\n return passTestWithSideData({\n iterations: metadatas[0].cardinality.value * cardinalityRemaining,\n persistedItems: 0,\n blockingItems: 0,\n requestTime: requestInitialTimes[0] +\n metadatas[0].cardinality.value * (\n requestItemTimes[0] +\n receiveInitialCostRemaining +\n cardinalityRemaining * receiveItemCostRemaining\n ),\n }, { ...sideData, entriesUnsorted, entriesSorted });\n }\n}\n\nexport interface IActorRdfJoinMultiBindArgs extends IActorRdfJoinArgs<IActorRdfJoinMultiBindTestSideData> {\n /**\n * The order in which elements should be bound\n * @default {depth-first}\n */\n bindOrder: BindOrder;\n /**\n * Multiplier for selectivity values\n * @range {double}\n * @default {0.0001}\n */\n selectivityModifier: number;\n /**\n * The number of times the smallest cardinality should fit in the maximum cardinality.\n * @range {double}\n * @default {60}\n */\n minMaxCardinalityRatio: number;\n /**\n * The join entries sort mediator\n */\n mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;\n /**\n * The query operation mediator\n */\n mediatorQueryOperation: MediatorQueryOperation;\n /**\n * A mediator for creating binding context merge handlers\n */\n mediatorMergeBindingsContext: MediatorMergeBindingsContext;\n}\n\nexport type BindOrder = 'depth-first' | 'breadth-first';\n\nexport interface IActorRdfJoinMultiBindTestSideData extends IActorRdfJoinTestSideData {\n entriesUnsorted: IJoinEntryWithMetadata[];\n entriesSorted: IJoinEntryWithMetadata[];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ActorRdfJoinMultiBind.js","sourceRoot":"","sources":["ActorRdfJoinMultiBind.ts"],"names":[],"mappings":";;;AAQA,yDAAsD;AAEtD,+DAA8E;AAE9E,yCAAgE;AAShE,6EAAmE;AACnE,2EAAwF;AACxF,iDAAyF;AACzF,qDAAyD;AAEzD;;GAEG;AACH,MAAa,qBAAsB,SAAQ,2BAAgD;IAQzF,YAAmB,IAAgC;QACjD,KAAK,CAAC,IAAI,EAAE;YACV,WAAW,EAAE,OAAO;YACpB,YAAY,EAAE,MAAM;YACpB,eAAe,EAAE,IAAI;YACrB,MAAM,EAAE,KAAK;SACd,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;OAUG;IACI,MAAM,CAAC,gBAAgB,CAC5B,SAAoB,EACpB,UAA0B,EAC1B,UAA+B,EAC/B,eAC0B,EAC1B,QAAiB,EACjB,cAAuB,EACvB,eAAgC;QAEhC,qFAAqF;QACrF,MAAM,oBAAoB,GAAG,SAAS,KAAK,aAAa,CAAC;QAEzD,2BAA2B;QAC3B,MAAM,MAAM,GAAG,CAAC,QAAkB,EAAkB,EAAE;YACpD,oEAAoE;YACpE,6GAA6G;YAC7G,MAAM,aAAa,GAAG,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,IAAA,4CAAoB,EACpE,SAAS,EACT,QAAQ,EACR,cAAc,EACd,eAAe,EACf,EAAE,UAAU,EAAE,IAAI,EAAE,CACrB,CAAC,CAAC;YACH,MAAM,cAAc,GAAG,CAAC,WAAqB,EAAwB,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACpG,OAAO,IAAI,iCAAiB,CAAC,KAAK,IAAG,EAAE,CAAC,CAAC,MAAM,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AAQ,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC,CAAC;IACtD,CAAC;CACF;AA/OD,sDA+OC","sourcesContent":["import type { MediatorMergeBindingsContext } from '@comunica/bus-merge-bindings-context';\nimport type { MediatorQueryOperation } from '@comunica/bus-query-operation';\nimport type {\n IActionRdfJoin,\n IActorRdfJoinOutputInner,\n IActorRdfJoinArgs,\n IActorRdfJoinTestSideData,\n} from '@comunica/bus-rdf-join';\nimport { ActorRdfJoin } from '@comunica/bus-rdf-join';\nimport type { MediatorRdfJoinEntriesSort } from '@comunica/bus-rdf-join-entries-sort';\nimport { KeysInitQuery, KeysQueryOperation } from '@comunica/context-entries';\nimport type { TestResult } from '@comunica/core';\nimport { passTestWithSideData, failTest } from '@comunica/core';\nimport type { IMediatorTypeJoinCoefficients } from '@comunica/mediatortype-join-coefficients';\nimport type {\n Bindings,\n BindingsStream,\n ComunicaDataFactory,\n IJoinEntryWithMetadata,\n IQueryOperationResultBindings,\n} from '@comunica/types';\nimport { BindingsFactory } from '@comunica/utils-bindings-factory';\nimport { getSafeBindings, materializeOperation } from '@comunica/utils-query-operation';\nimport { MultiTransformIterator, TransformIterator, UnionIterator } from 'asynciterator';\nimport { Factory, Algebra, Util } from 'sparqlalgebrajs';\n\n/**\n * A comunica Multi-way Bind RDF Join Actor.\n */\nexport class ActorRdfJoinMultiBind extends ActorRdfJoin<IActorRdfJoinMultiBindTestSideData> {\n public readonly bindOrder: BindOrder;\n public readonly selectivityModifier: number;\n public readonly minMaxCardinalityRatio: number;\n public readonly mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;\n public readonly mediatorQueryOperation: MediatorQueryOperation;\n public readonly mediatorMergeBindingsContext: MediatorMergeBindingsContext;\n\n public constructor(args: IActorRdfJoinMultiBindArgs) {\n super(args, {\n logicalType: 'inner',\n physicalName: 'bind',\n canHandleUndefs: true,\n isLeaf: false,\n });\n }\n\n /**\n * Create a new bindings stream that takes every binding of the base stream\n * and binds it to the remaining patterns, evaluates those patterns, and emits all their bindings.\n *\n * @param bindOrder The order in which elements should be bound.\n * @param baseStream The base stream.\n * @param operations The operations to bind with each binding of the base stream.\n * @param operationBinder A callback to retrieve the bindings stream of bound operations.\n * @param optional If the original bindings should be emitted when the resulting bindings stream is empty.\n * @return {BindingsStream}\n */\n public static createBindStream(\n bindOrder: BindOrder,\n baseStream: BindingsStream,\n operations: Algebra.Operation[],\n operationBinder: (boundOperations: Algebra.Operation[], operationBindings: Bindings)\n => Promise<BindingsStream>,\n optional: boolean,\n algebraFactory: Factory,\n bindingsFactory: BindingsFactory,\n ): BindingsStream {\n // Enable auto-start on sub-bindings during depth-first binding for best performance.\n const autoStartSubBindings = bindOrder === 'depth-first';\n\n // Create bindings function\n const binder = (bindings: Bindings): BindingsStream => {\n // We don't bind the filter because filters are always handled last,\n // and we need to avoid binding filters of sub-queries, which are to be handled first. (see spec test bind10)\n const subOperations = operations.map(operation => materializeOperation(\n operation,\n bindings,\n algebraFactory,\n bindingsFactory,\n { bindFilter: true },\n ));\n const bindingsMerger = (subBindings: Bindings): Bindings | undefined => subBindings.merge(bindings);\n return new TransformIterator(async() => (await operationBinder(subOperations, bindings))\n .transform({ map: bindingsMerger }), { maxBufferSize: 128, autoStart: autoStartSubBindings });\n };\n\n // Create an iterator that binds elements from the base stream in different orders\n switch (bindOrder) {\n case 'depth-first':\n return new MultiTransformIterator(baseStream, { autoStart: false, multiTransform: binder, optional });\n case 'breadth-first':\n return new UnionIterator(baseStream.transform({\n map: binder,\n optional,\n }), { autoStart: false });\n default:\n // eslint-disable-next-line ts/restrict-template-expressions\n throw new Error(`Received request for unknown bind order: ${bindOrder}`);\n }\n }\n\n public async getOutput(\n action: IActionRdfJoin,\n sideData: IActorRdfJoinMultiBindTestSideData,\n ): Promise<IActorRdfJoinOutputInner> {\n const dataFactory: ComunicaDataFactory = action.context.getSafe(KeysInitQuery.dataFactory);\n const algebraFactory = new Factory(dataFactory);\n const bindingsFactory = await BindingsFactory.create(\n this.mediatorMergeBindingsContext,\n action.context,\n dataFactory,\n );\n\n const entries = sideData.entriesSorted;\n this.logDebug(\n action.context,\n 'First entry for Bind Join: ',\n () => ({\n entry: entries[0].operation,\n cardinality: entries[0].metadata.cardinality,\n order: entries[0].metadata.order,\n availableOrders: entries[0].metadata.availableOrders,\n }),\n );\n\n // Close the non-smallest streams\n for (const [ i, element ] of entries.entries()) {\n if (i !== 0) {\n element.output.bindingsStream.close();\n }\n }\n\n // Take the stream with the lowest cardinality\n const smallestStream: IQueryOperationResultBindings = entries[0].output;\n const remainingEntries = [ ...entries ];\n remainingEntries.splice(0, 1);\n\n // Bind the remaining patterns for each binding in the stream\n const subContext = action.context\n .set(KeysQueryOperation.joinLeftMetadata, entries[0].metadata)\n .set(KeysQueryOperation.joinRightMetadatas, remainingEntries.map(entry => entry.metadata));\n const bindingsStream: BindingsStream = ActorRdfJoinMultiBind.createBindStream(\n this.bindOrder,\n smallestStream.bindingsStream,\n remainingEntries.map(entry => entry.operation),\n async(operations: Algebra.Operation[], operationBindings: Bindings) => {\n // Send the materialized patterns to the mediator for recursive join evaluation.\n const operation = operations.length === 1 ?\n operations[0] :\n // Flattening should only take place if none of the input operations have associated metadata\n algebraFactory.createJoin(operations, operations.every(op => !op.metadata));\n const output = getSafeBindings(await this.mediatorQueryOperation.mediate(\n { operation, context: subContext?.set(KeysQueryOperation.joinBindings, operationBindings) },\n ));\n return output.bindingsStream;\n },\n false,\n algebraFactory,\n bindingsFactory,\n );\n\n return {\n result: {\n type: 'bindings',\n bindingsStream,\n metadata: () => this.constructResultMetadata(entries, entries.map(entry => entry.metadata), action.context),\n },\n physicalPlanMetadata: {\n bindIndex: sideData.entriesUnsorted.indexOf(entries[0]),\n bindOperation: entries[0].operation,\n bindOperationCardinality: entries[0].metadata.cardinality,\n bindOrder: this.bindOrder,\n },\n };\n }\n\n public canBindWithOperation(operation: Algebra.Operation): boolean {\n let valid = true;\n Util.recurseOperation(operation, {\n [Algebra.types.EXTEND](): boolean {\n valid = false;\n return false;\n },\n [Algebra.types.GROUP](): boolean {\n valid = false;\n return false;\n },\n });\n\n return valid;\n }\n\n public async getJoinCoefficients(\n action: IActionRdfJoin,\n sideData: IActorRdfJoinTestSideData,\n ): Promise<TestResult<IMediatorTypeJoinCoefficients, IActorRdfJoinMultiBindTestSideData>> {\n let { metadatas } = sideData;\n\n // Order the entries so we can pick the first one (usually the one with the lowest cardinality)\n const entriesUnsorted = action.entries\n .map((entry, i) => ({ ...entry, metadata: metadatas[i] }));\n const entriesTest = await ActorRdfJoin\n .sortJoinEntries(this.mediatorJoinEntriesSort, entriesUnsorted, action.context);\n if (entriesTest.isFailed()) {\n return entriesTest;\n }\n const entriesSorted = entriesTest.get();\n metadatas = entriesSorted.map(entry => entry.metadata);\n\n const requestInitialTimes = ActorRdfJoin.getRequestInitialTimes(metadatas);\n const requestItemTimes = ActorRdfJoin.getRequestItemTimes(metadatas);\n\n // Determine first stream and remaining ones\n const remainingEntries = [ ...entriesSorted ];\n const remainingRequestInitialTimes = [ ...requestInitialTimes ];\n const remainingRequestItemTimes = [ ...requestItemTimes ];\n remainingEntries.splice(0, 1);\n remainingRequestInitialTimes.splice(0, 1);\n remainingRequestItemTimes.splice(0, 1);\n\n // Reject binding on some operation types\n if (remainingEntries\n .some(entry => !this.canBindWithOperation(entry.operation))) {\n return failTest(`Actor ${this.name} can not bind on Extend and Group operations`);\n }\n\n // Reject binding on modified operations, since using the output directly would be significantly more efficient.\n if (remainingEntries.some(entry => entry.operationModified)) {\n return failTest(`Actor ${this.name} can not be used over remaining entries with modified operations`);\n }\n\n // Only run this actor if the smallest stream is significantly smaller than the largest stream.\n // We must use Math.max, because the last metadata is not necessarily the biggest, but it's the least preferred.\n // If join entries are produced locally, we increase the possibility of doing this bind join, as it's cheap.\n const isRemoteAccess = requestItemTimes.some(time => time > 0);\n if (metadatas[0].cardinality.value * this.minMaxCardinalityRatio / (isRemoteAccess ? 1 : 3) >\n Math.max(...metadatas.map(metadata => metadata.cardinality.value))) {\n return failTest(`Actor ${this.name} can only run if the smallest stream is much smaller than largest stream`);\n }\n\n // Determine selectivities of smallest entry with all other entries\n const selectivities = await Promise.all(remainingEntries\n .map(async entry => (await this.mediatorJoinSelectivity.mediate({\n entries: [ entriesSorted[0], entry ],\n context: action.context,\n })).selectivity * this.selectivityModifier));\n\n // Determine coefficients for remaining entries\n const cardinalityRemaining = remainingEntries\n .map((entry, i) => entry.metadata.cardinality.value * selectivities[i])\n .reduce((sum, element) => sum + element, 0);\n const receiveInitialCostRemaining = remainingRequestInitialTimes\n .reduce((sum, element) => sum + element, 0);\n const receiveItemCostRemaining = remainingRequestItemTimes\n .reduce((sum, element) => sum + element, 0);\n\n return passTestWithSideData({\n iterations: metadatas[0].cardinality.value * cardinalityRemaining,\n persistedItems: 0,\n blockingItems: 0,\n requestTime: requestInitialTimes[0] +\n metadatas[0].cardinality.value * (\n requestItemTimes[0] +\n receiveInitialCostRemaining +\n cardinalityRemaining * receiveItemCostRemaining\n ),\n }, { ...sideData, entriesUnsorted, entriesSorted });\n }\n}\n\nexport interface IActorRdfJoinMultiBindArgs extends IActorRdfJoinArgs<IActorRdfJoinMultiBindTestSideData> {\n /**\n * The order in which elements should be bound\n * @default {depth-first}\n */\n bindOrder: BindOrder;\n /**\n * Multiplier for selectivity values\n * @range {double}\n * @default {0.0001}\n */\n selectivityModifier: number;\n /**\n * The number of times the smallest cardinality should fit in the maximum cardinality.\n * @range {double}\n * @default {60}\n */\n minMaxCardinalityRatio: number;\n /**\n * The join entries sort mediator\n */\n mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;\n /**\n * The query operation mediator\n */\n mediatorQueryOperation: MediatorQueryOperation;\n /**\n * A mediator for creating binding context merge handlers\n */\n mediatorMergeBindingsContext: MediatorMergeBindingsContext;\n}\n\nexport type BindOrder = 'depth-first' | 'breadth-first';\n\nexport interface IActorRdfJoinMultiBindTestSideData extends IActorRdfJoinTestSideData {\n entriesUnsorted: IJoinEntryWithMetadata[];\n entriesSorted: IJoinEntryWithMetadata[];\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
File without changes
|
package/lib/index.js
CHANGED
|
File without changes
|
package/lib/index.js.map
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-rdf-join-inner-multi-bind",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "A multi-bind rdf-join actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,18 +41,18 @@
|
|
|
41
41
|
"build:components": "componentsjs-generator"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@comunica/bus-merge-bindings-context": "4.
|
|
45
|
-
"@comunica/bus-query-operation": "4.
|
|
46
|
-
"@comunica/bus-rdf-join": "4.
|
|
47
|
-
"@comunica/bus-rdf-join-entries-sort": "4.
|
|
48
|
-
"@comunica/context-entries": "4.
|
|
49
|
-
"@comunica/core": "4.
|
|
50
|
-
"@comunica/mediatortype-join-coefficients": "4.
|
|
51
|
-
"@comunica/types": "4.
|
|
52
|
-
"@comunica/utils-
|
|
53
|
-
"@comunica/utils-
|
|
54
|
-
"
|
|
55
|
-
"
|
|
44
|
+
"@comunica/bus-merge-bindings-context": "^4.5.0",
|
|
45
|
+
"@comunica/bus-query-operation": "^4.5.0",
|
|
46
|
+
"@comunica/bus-rdf-join": "^4.5.0",
|
|
47
|
+
"@comunica/bus-rdf-join-entries-sort": "^4.5.0",
|
|
48
|
+
"@comunica/context-entries": "^4.5.0",
|
|
49
|
+
"@comunica/core": "^4.5.0",
|
|
50
|
+
"@comunica/mediatortype-join-coefficients": "^4.5.0",
|
|
51
|
+
"@comunica/types": "^4.5.0",
|
|
52
|
+
"@comunica/utils-bindings-factory": "^4.5.0",
|
|
53
|
+
"@comunica/utils-query-operation": "^4.5.0",
|
|
54
|
+
"asynciterator": "^3.9.0",
|
|
55
|
+
"sparqlalgebrajs": "^5.0.2"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "2bcd98c387a021fc5c08d375793c205ca3d1bf0d"
|
|
58
58
|
}
|