@comunica/actor-rdf-join-inner-multi-bind 2.4.0 → 2.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ActorRdfJoinMultiBind.js","sourceRoot":"","sources":["ActorRdfJoinMultiBind.ts"],"names":[],"mappings":";;;AACA,uEAA0F;AAM1F,yDAAsD;AAEtD,+DAA+D;AAI/D,iDAAyF;AACzF,qDAAmD;AAEnD;;GAEG;AACH,MAAa,qBAAsB,SAAQ,2BAAY;IAQrD,YAAmB,IAAgC;QACjD,KAAK,CAAC,IAAI,EAAE;YACV,WAAW,EAAE,OAAO;YACpB,YAAY,EAAE,MAAM;YACpB,eAAe,EAAE,IAAI;SACtB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;OAUG;IACI,MAAM,CAAC,gBAAgB,CAC5B,SAAoB,EACpB,UAA0B,EAC1B,UAA+B,EAC/B,eAC0B,EAC1B,QAAiB;QAEjB,2BAA2B;QAC3B,MAAM,MAAM,GAAG,CAAC,QAAkB,EAAkB,EAAE;YACpD,oEAAoE;YACpE,6GAA6G;YAC7G,MAAM,aAAa,GAAG,UAAU;iBAC7B,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,IAAA,0CAAoB,EAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;YACtF,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,eAAe,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;iBACrF,SAAS,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,CAAC,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC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CAAC;;AAhPH,sDAiPC;AA3OwB,6BAAO,GAAG,IAAI,yBAAO,EAAE,CAAC","sourcesContent":["import type { MediatorQueryOperation } from '@comunica/bus-query-operation';\nimport { ActorQueryOperation, materializeOperation } from '@comunica/bus-query-operation';\nimport type {\n IActionRdfJoin,\n IActorRdfJoinOutputInner,\n IActorRdfJoinArgs,\n} from '@comunica/bus-rdf-join';\nimport { ActorRdfJoin } from '@comunica/bus-rdf-join';\nimport type { MediatorRdfJoinEntriesSort } from '@comunica/bus-rdf-join-entries-sort';\nimport { KeysQueryOperation } from '@comunica/context-entries';\nimport type { IMediatorTypeJoinCoefficients } from '@comunica/mediatortype-join-coefficients';\nimport type { Bindings, BindingsStream, IQueryOperationResultBindings,\n MetadataBindings, IActionContext, IJoinEntryWithMetadata } from '@comunica/types';\nimport { MultiTransformIterator, TransformIterator, UnionIterator } from 'asynciterator';\nimport { Factory, Algebra } from 'sparqlalgebrajs';\n\n/**\n * A comunica Multi-way Bind RDF Join Actor.\n */\nexport class ActorRdfJoinMultiBind extends ActorRdfJoin {\n public readonly bindOrder: BindOrder;\n public readonly selectivityModifier: number;\n public readonly mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;\n public readonly mediatorQueryOperation: MediatorQueryOperation;\n\n public static readonly FACTORY = new Factory();\n\n public constructor(args: IActorRdfJoinMultiBindArgs) {\n super(args, {\n logicalType: 'inner',\n physicalName: 'bind',\n canHandleUndefs: true,\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 ): BindingsStream {\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\n .map(operation => materializeOperation(operation, bindings, { bindFilter: false }));\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: false });\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 throw new Error(`Received request for unknown bind order: ${bindOrder}`);\n }\n }\n\n /**\n * Order the given join entries using the join-entries-sort bus.\n * @param {IJoinEntryWithMetadata[]} entries An array of join entries.\n * @param context The action context.\n * @return {IJoinEntryWithMetadata[]} The sorted join entries.\n */\n public async sortJoinEntries(\n entries: IJoinEntryWithMetadata[],\n context: IActionContext,\n ): Promise<IJoinEntryWithMetadata[]> {\n // If there is a stream that can contain undefs, we don't modify the join order.\n const canContainUndefs = entries.some(entry => entry.metadata.canContainUndefs);\n if (canContainUndefs) {\n return entries;\n }\n\n // Calculate number of occurrences of each variable\n const variableOccurrences: Record<string, number> = {};\n for (const entry of entries) {\n for (const variable of entry.metadata.variables) {\n let counter = variableOccurrences[variable.value];\n if (!counter) {\n counter = 0;\n }\n variableOccurrences[variable.value] = ++counter;\n }\n }\n\n // Determine variables that occur in at least two join entries\n const multiOccurrenceVariables: string[] = [];\n for (const [ variable, count ] of Object.entries(variableOccurrences)) {\n if (count >= 2) {\n multiOccurrenceVariables.push(variable);\n }\n }\n\n // Reject if no entries have common variables\n if (multiOccurrenceVariables.length === 0) {\n throw new Error(`Bind join can only join entries with at least one common variable`);\n }\n\n // Determine entries without common variables\n // These will be placed in the back of the sorted array\n const entriesWithoutCommonVariables: IJoinEntryWithMetadata[] = [];\n for (const entry of entries) {\n let hasCommon = false;\n for (const variable of entry.metadata.variables) {\n if (multiOccurrenceVariables.includes(variable.value)) {\n hasCommon = true;\n break;\n }\n }\n if (!hasCommon) {\n entriesWithoutCommonVariables.push(entry);\n }\n }\n\n return (await this.mediatorJoinEntriesSort.mediate({ entries, context })).entries\n .sort((entryLeft, entryRight) => {\n // Sort to make sure that entries without common variables come last in the array.\n // For all other entries, the original order is kept.\n const leftWithoutCommonVariables = entriesWithoutCommonVariables.includes(entryLeft);\n const rightWithoutCommonVariables = entriesWithoutCommonVariables.includes(entryRight);\n if (leftWithoutCommonVariables === rightWithoutCommonVariables) {\n return 0;\n }\n return leftWithoutCommonVariables ?\n 1 :\n -1;\n });\n }\n\n public async getOutput(action: IActionRdfJoin): Promise<IActorRdfJoinOutputInner> {\n // Order the entries so we can pick the first one (usually the one with the lowest cardinality)\n const entriesUnsorted = await ActorRdfJoin.getEntriesWithMetadatas(action.entries);\n const entries = await this.sortJoinEntries(entriesUnsorted, action.context);\n\n this.logDebug(action.context,\n 'First entry for Bind Join: ',\n () => ({ entry: entries[0].operation, metadata: entries[0].metadata }));\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 ActorRdfJoinMultiBind.FACTORY.createJoin(operations);\n const output = ActorQueryOperation.getSafeBindings(await this.mediatorQueryOperation.mediate(\n { operation, context: subContext?.set(KeysQueryOperation.joinBindings, operationBindings) },\n ));\n return output.bindingsStream;\n },\n false,\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: entriesUnsorted.indexOf(entries[0]),\n bindOrder: this.bindOrder,\n },\n };\n }\n\n public async getJoinCoefficients(\n action: IActionRdfJoin,\n metadatas: MetadataBindings[],\n ): Promise<IMediatorTypeJoinCoefficients> {\n // Order the entries so we can pick the first one (usually the one with the lowest cardinality)\n const entries = await this.sortJoinEntries(action.entries\n .map((entry, i) => ({ ...entry, metadata: metadatas[i] })), action.context);\n metadatas = entries.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 = [ ...entries ];\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 => entry.operation.type === Algebra.types.EXTEND || entry.operation.type === Algebra.types.GROUP)) {\n throw new Error(`Actor ${this.name} can not bind on Extend and Group operations`);\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: [ entries[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, i) => sum + (element * selectivities[i]), 0);\n const receiveItemCostRemaining = remainingRequestItemTimes\n .reduce((sum, element, i) => sum + (element * selectivities[i]), 0);\n\n return {\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 };\n }\n}\n\nexport interface IActorRdfJoinMultiBindArgs extends IActorRdfJoinArgs {\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 join entries sort mediator\n */\n mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;\n /**\n * The query operation mediator\n */\n mediatorQueryOperation: MediatorQueryOperation;\n}\n\nexport type BindOrder = 'depth-first' | 'breadth-first';\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC","sourcesContent":["export * from './ActorRdfJoinMultiBind';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comunica/actor-rdf-join-inner-multi-bind",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "A multi-bind rdf-join actor",
5
5
  "lsd:module": true,
6
6
  "main": "lib/index.js",
@@ -28,16 +28,17 @@
28
28
  "files": [
29
29
  "components",
30
30
  "lib/**/*.d.ts",
31
- "lib/**/*.js"
31
+ "lib/**/*.js",
32
+ "lib/**/*.js.map"
32
33
  ],
33
34
  "dependencies": {
34
- "@comunica/bus-query-operation": "^2.4.0",
35
- "@comunica/bus-rdf-join": "^2.4.0",
36
- "@comunica/bus-rdf-join-entries-sort": "^2.4.0",
37
- "@comunica/context-entries": "^2.4.0",
38
- "@comunica/mediatortype-join-coefficients": "^2.4.0",
39
- "@comunica/types": "^2.4.0",
40
- "asynciterator": "^3.7.0",
35
+ "@comunica/bus-query-operation": "^2.5.0",
36
+ "@comunica/bus-rdf-join": "^2.5.0",
37
+ "@comunica/bus-rdf-join-entries-sort": "^2.5.0",
38
+ "@comunica/context-entries": "^2.5.0",
39
+ "@comunica/mediatortype-join-coefficients": "^2.5.0",
40
+ "@comunica/types": "^2.5.0",
41
+ "asynciterator": "^3.8.0",
41
42
  "sparqlalgebrajs": "^4.0.0"
42
43
  },
43
44
  "scripts": {
@@ -45,5 +46,5 @@
45
46
  "build:ts": "node \"../../node_modules/typescript/bin/tsc\"",
46
47
  "build:components": "componentsjs-generator"
47
48
  },
48
- "gitHead": "cb5a1560c9ab9ebaf3335888a1411a7e1654de1e"
49
+ "gitHead": "349d57f5d1e539200e980bdff96973c2e0b66caa"
49
50
  }
package/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright © 2017–now Ruben Taelman, Joachim Van Herwegen
4
- Comunica Association and Ghent University – imec, Belgium
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in
14
- all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- THE SOFTWARE.