@comunica/actor-rdf-join-inner-multi-bind 3.2.4-alpha.47.0 → 3.3.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.
@@ -11,13 +11,7 @@
11
11
  "@type": "Class",
12
12
  "requireElement": "ActorRdfJoinMultiBind",
13
13
  "extends": [
14
- {
15
- "@type": "GenericComponentExtension",
16
- "component": "cbrj:components/ActorRdfJoin.jsonld#ActorRdfJoin",
17
- "genericTypeInstances": [
18
- "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindTestSideData"
19
- ]
20
- }
14
+ "cbrj:components/ActorRdfJoin.jsonld#ActorRdfJoin"
21
15
  ],
22
16
  "comment": "A comunica Multi-way Bind RDF Join Actor.",
23
17
  "parameters": [
@@ -47,7 +41,15 @@
47
41
  },
48
42
  {
49
43
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_minMaxCardinalityRatio",
50
- "range": "xsd:double",
44
+ "range": {
45
+ "@type": "ParameterRangeUnion",
46
+ "parameterRangeElements": [
47
+ "xsd:double",
48
+ {
49
+ "@type": "ParameterRangeUndefined"
50
+ }
51
+ ]
52
+ },
51
53
  "default": "60",
52
54
  "comment": "The number of times the smallest cardinality should fit in the maximum cardinality."
53
55
  },
@@ -99,10 +101,6 @@
99
101
  {
100
102
  "@type": "ParameterRangeGenericTypeReference",
101
103
  "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
102
- },
103
- {
104
- "@type": "ParameterRangeGenericTypeReference",
105
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
106
104
  }
107
105
  ]
108
106
  },
@@ -117,10 +115,6 @@
117
115
  {
118
116
  "@type": "ParameterRangeGenericTypeReference",
119
117
  "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
120
- },
121
- {
122
- "@type": "ParameterRangeGenericTypeReference",
123
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
124
118
  }
125
119
  ]
126
120
  },
@@ -130,20 +124,6 @@
130
124
  },
131
125
  "comment": "The bus this actor subscribes to."
132
126
  },
133
- {
134
- "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_busFailMessage",
135
- "range": {
136
- "@type": "ParameterRangeUnion",
137
- "parameterRangeElements": [
138
- "xsd:string",
139
- {
140
- "@type": "ParameterRangeUndefined"
141
- }
142
- ]
143
- },
144
- "default": "RDF joining failed: none of the configured actors were able to handle the join type ${action.type}",
145
- "comment": "The message that will be configured in the bus for reporting failures. This message may be a template string that contains references to the executed `action`. For example, the following templated string is allowed: \"RDF dereferencing failed: no actors could handle ${action.handle.mediaType}\""
146
- },
147
127
  {
148
128
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_beforeActors",
149
129
  "range": {
@@ -166,10 +146,6 @@
166
146
  {
167
147
  "@type": "ParameterRangeGenericTypeReference",
168
148
  "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
169
- },
170
- {
171
- "@type": "ParameterRangeGenericTypeReference",
172
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
173
149
  }
174
150
  ]
175
151
  }
@@ -225,6 +201,13 @@
225
201
  "memberFieldName": "mediatorMergeBindingsContext",
226
202
  "range": "cc:components/Mediator.jsonld#Mediator"
227
203
  },
204
+ {
205
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_FACTORY",
206
+ "memberFieldName": "FACTORY",
207
+ "range": {
208
+ "@type": "ParameterRangeWildcard"
209
+ }
210
+ },
228
211
  {
229
212
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_constructor",
230
213
  "memberFieldName": "constructor"
@@ -304,12 +287,6 @@
304
287
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_bus"
305
288
  }
306
289
  },
307
- {
308
- "keyRaw": "busFailMessage",
309
- "value": {
310
- "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_busFailMessage"
311
- }
312
- },
313
290
  {
314
291
  "keyRaw": "beforeActors",
315
292
  "value": {
@@ -325,13 +302,7 @@
325
302
  "@type": "AbstractClass",
326
303
  "requireElement": "IActorRdfJoinMultiBindArgs",
327
304
  "extends": [
328
- {
329
- "@type": "GenericComponentExtension",
330
- "component": "cbrj:components/ActorRdfJoin.jsonld#IActorRdfJoinArgs",
331
- "genericTypeInstances": [
332
- "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindTestSideData"
333
- ]
334
- }
305
+ "cbrj:components/ActorRdfJoin.jsonld#IActorRdfJoinArgs"
335
306
  ],
336
307
  "parameters": [],
337
308
  "memberFields": [
@@ -361,26 +332,6 @@
361
332
  }
362
333
  ],
363
334
  "constructorArguments": []
364
- },
365
- {
366
- "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindTestSideData",
367
- "@type": "AbstractClass",
368
- "requireElement": "IActorRdfJoinMultiBindTestSideData",
369
- "extends": [
370
- "cbrj:components/ActorRdfJoin.jsonld#IActorRdfJoinTestSideData"
371
- ],
372
- "parameters": [],
373
- "memberFields": [
374
- {
375
- "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindTestSideData__member_entriesUnsorted",
376
- "memberFieldName": "entriesUnsorted"
377
- },
378
- {
379
- "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindTestSideData__member_entriesSorted",
380
- "memberFieldName": "entriesSorted"
381
- }
382
- ],
383
- "constructorArguments": []
384
335
  }
385
336
  ]
386
337
  }
@@ -35,9 +35,6 @@
35
35
  "args_bus": {
36
36
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_bus"
37
37
  },
38
- "args_busFailMessage": {
39
- "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_busFailMessage"
40
- },
41
38
  "args_beforeActors": {
42
39
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_beforeActors",
43
40
  "@container": "@list"
@@ -69,9 +66,6 @@
69
66
  "bus": {
70
67
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_bus"
71
68
  },
72
- "busFailMessage": {
73
- "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_busFailMessage"
74
- },
75
69
  "beforeActors": {
76
70
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_beforeActors",
77
71
  "@container": "@list"
@@ -82,11 +76,6 @@
82
76
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindArgs",
83
77
  "@prefix": true,
84
78
  "@context": {}
85
- },
86
- "IActorRdfJoinMultiBindTestSideData": {
87
- "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindTestSideData",
88
- "@prefix": true,
89
- "@context": {}
90
79
  }
91
80
  }
92
81
  ]
@@ -1,23 +1,23 @@
1
+ import { BindingsFactory } from '@comunica/bindings-factory';
1
2
  import type { MediatorMergeBindingsContext } from '@comunica/bus-merge-bindings-context';
2
3
  import type { MediatorQueryOperation } from '@comunica/bus-query-operation';
3
- import type { IActionRdfJoin, IActorRdfJoinOutputInner, IActorRdfJoinArgs, IActorRdfJoinTestSideData } from '@comunica/bus-rdf-join';
4
+ import type { IActionRdfJoin, IActorRdfJoinOutputInner, IActorRdfJoinArgs } from '@comunica/bus-rdf-join';
4
5
  import { ActorRdfJoin } from '@comunica/bus-rdf-join';
5
6
  import type { MediatorRdfJoinEntriesSort } from '@comunica/bus-rdf-join-entries-sort';
6
- import type { TestResult } from '@comunica/core';
7
7
  import type { IMediatorTypeJoinCoefficients } from '@comunica/mediatortype-join-coefficients';
8
- import type { Bindings, BindingsStream, IJoinEntryWithMetadata } from '@comunica/types';
9
- import { BindingsFactory } from '@comunica/utils-bindings-factory';
8
+ import type { Bindings, BindingsStream, MetadataBindings } from '@comunica/types';
10
9
  import { Factory, Algebra } from 'sparqlalgebrajs';
11
10
  /**
12
11
  * A comunica Multi-way Bind RDF Join Actor.
13
12
  */
14
- export declare class ActorRdfJoinMultiBind extends ActorRdfJoin<IActorRdfJoinMultiBindTestSideData> {
13
+ export declare class ActorRdfJoinMultiBind extends ActorRdfJoin {
15
14
  readonly bindOrder: BindOrder;
16
15
  readonly selectivityModifier: number;
17
16
  readonly minMaxCardinalityRatio: number;
18
17
  readonly mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;
19
18
  readonly mediatorQueryOperation: MediatorQueryOperation;
20
19
  readonly mediatorMergeBindingsContext: MediatorMergeBindingsContext;
20
+ static readonly FACTORY: Factory;
21
21
  constructor(args: IActorRdfJoinMultiBindArgs);
22
22
  /**
23
23
  * Create a new bindings stream that takes every binding of the base stream
@@ -30,12 +30,12 @@ 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: Factory, bindingsFactory: BindingsFactory): BindingsStream;
34
- getOutput(action: IActionRdfJoin, sideData: IActorRdfJoinMultiBindTestSideData): Promise<IActorRdfJoinOutputInner>;
33
+ static createBindStream(bindOrder: BindOrder, baseStream: BindingsStream, operations: Algebra.Operation[], operationBinder: (boundOperations: Algebra.Operation[], operationBindings: Bindings) => Promise<BindingsStream>, optional: boolean, bindingsFactory: BindingsFactory): BindingsStream;
34
+ getOutput(action: IActionRdfJoin): Promise<IActorRdfJoinOutputInner>;
35
35
  canBindWithOperation(operation: Algebra.Operation): boolean;
36
- getJoinCoefficients(action: IActionRdfJoin, sideData: IActorRdfJoinTestSideData): Promise<TestResult<IMediatorTypeJoinCoefficients, IActorRdfJoinMultiBindTestSideData>>;
36
+ getJoinCoefficients(action: IActionRdfJoin, metadatas: MetadataBindings[]): Promise<IMediatorTypeJoinCoefficients>;
37
37
  }
38
- export interface IActorRdfJoinMultiBindArgs extends IActorRdfJoinArgs<IActorRdfJoinMultiBindTestSideData> {
38
+ export interface IActorRdfJoinMultiBindArgs extends IActorRdfJoinArgs {
39
39
  /**
40
40
  * The order in which elements should be bound
41
41
  * @default {depth-first}
@@ -52,7 +52,7 @@ export interface IActorRdfJoinMultiBindArgs extends IActorRdfJoinArgs<IActorRdfJ
52
52
  * @range {double}
53
53
  * @default {60}
54
54
  */
55
- minMaxCardinalityRatio: number;
55
+ minMaxCardinalityRatio?: number;
56
56
  /**
57
57
  * The join entries sort mediator
58
58
  */
@@ -67,7 +67,3 @@ export interface IActorRdfJoinMultiBindArgs extends IActorRdfJoinArgs<IActorRdfJ
67
67
  mediatorMergeBindingsContext: MediatorMergeBindingsContext;
68
68
  }
69
69
  export type BindOrder = 'depth-first' | 'breadth-first';
70
- export interface IActorRdfJoinMultiBindTestSideData extends IActorRdfJoinTestSideData {
71
- entriesUnsorted: IJoinEntryWithMetadata[];
72
- entriesSorted: IJoinEntryWithMetadata[];
73
- }
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ActorRdfJoinMultiBind = void 0;
4
+ const bindings_factory_1 = require("@comunica/bindings-factory");
5
+ const bus_query_operation_1 = require("@comunica/bus-query-operation");
4
6
  const bus_rdf_join_1 = require("@comunica/bus-rdf-join");
5
7
  const context_entries_1 = require("@comunica/context-entries");
6
- const core_1 = require("@comunica/core");
7
- const utils_bindings_factory_1 = require("@comunica/utils-bindings-factory");
8
- const utils_query_operation_1 = require("@comunica/utils-query-operation");
9
8
  const asynciterator_1 = require("asynciterator");
10
9
  const sparqlalgebrajs_1 = require("sparqlalgebrajs");
11
10
  /**
@@ -13,6 +12,10 @@ const sparqlalgebrajs_1 = require("sparqlalgebrajs");
13
12
  */
14
13
  class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
15
14
  constructor(args) {
15
+ // TODO: remove this fallback in the next major update
16
+ if (args.minMaxCardinalityRatio === undefined) {
17
+ args.minMaxCardinalityRatio = 60;
18
+ }
16
19
  super(args, {
17
20
  logicalType: 'inner',
18
21
  physicalName: 'bind',
@@ -31,14 +34,15 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
31
34
  * @param optional If the original bindings should be emitted when the resulting bindings stream is empty.
32
35
  * @return {BindingsStream}
33
36
  */
34
- static createBindStream(bindOrder, baseStream, operations, operationBinder, optional, algebraFactory, bindingsFactory) {
37
+ static createBindStream(bindOrder, baseStream, operations, operationBinder, optional, bindingsFactory) {
35
38
  // Enable auto-start on sub-bindings during depth-first binding for best performance.
36
39
  const autoStartSubBindings = bindOrder === 'depth-first';
37
40
  // Create bindings function
38
41
  const binder = (bindings) => {
39
42
  // We don't bind the filter because filters are always handled last,
40
43
  // and we need to avoid binding filters of sub-queries, which are to be handled first. (see spec test bind10)
41
- const subOperations = operations.map(operation => (0, utils_query_operation_1.materializeOperation)(operation, bindings, algebraFactory, bindingsFactory, { bindFilter: true }));
44
+ const subOperations = operations
45
+ .map(operation => (0, bus_query_operation_1.materializeOperation)(operation, bindings, bindingsFactory, { bindFilter: true }));
42
46
  const bindingsMerger = (subBindings) => subBindings.merge(bindings);
43
47
  return new asynciterator_1.TransformIterator(async () => (await operationBinder(subOperations, bindings))
44
48
  .transform({ map: bindingsMerger }), { maxBufferSize: 128, autoStart: autoStartSubBindings });
@@ -57,11 +61,11 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
57
61
  throw new Error(`Received request for unknown bind order: ${bindOrder}`);
58
62
  }
59
63
  }
60
- async getOutput(action, sideData) {
61
- const dataFactory = action.context.getSafe(context_entries_1.KeysInitQuery.dataFactory);
62
- const algebraFactory = new sparqlalgebrajs_1.Factory(dataFactory);
63
- const bindingsFactory = await utils_bindings_factory_1.BindingsFactory.create(this.mediatorMergeBindingsContext, action.context, dataFactory);
64
- const entries = sideData.entriesSorted;
64
+ async getOutput(action) {
65
+ const bindingsFactory = await bindings_factory_1.BindingsFactory.create(this.mediatorMergeBindingsContext, action.context);
66
+ // Order the entries so we can pick the first one (usually the one with the lowest cardinality)
67
+ const entriesUnsorted = await bus_rdf_join_1.ActorRdfJoin.getEntriesWithMetadatas(action.entries);
68
+ const entries = await bus_rdf_join_1.ActorRdfJoin.sortJoinEntries(this.mediatorJoinEntriesSort, entriesUnsorted, action.context);
65
69
  this.logDebug(action.context, 'First entry for Bind Join: ', () => ({ entry: entries[0].operation, metadata: entries[0].metadata }));
66
70
  // Close the non-smallest streams
67
71
  for (const [i, element] of entries.entries()) {
@@ -81,10 +85,10 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
81
85
  // Send the materialized patterns to the mediator for recursive join evaluation.
82
86
  const operation = operations.length === 1 ?
83
87
  operations[0] :
84
- algebraFactory.createJoin(operations);
85
- const output = (0, utils_query_operation_1.getSafeBindings)(await this.mediatorQueryOperation.mediate({ operation, context: subContext?.set(context_entries_1.KeysQueryOperation.joinBindings, operationBindings) }));
88
+ ActorRdfJoinMultiBind.FACTORY.createJoin(operations);
89
+ const output = bus_query_operation_1.ActorQueryOperation.getSafeBindings(await this.mediatorQueryOperation.mediate({ operation, context: subContext?.set(context_entries_1.KeysQueryOperation.joinBindings, operationBindings) }));
86
90
  return output.bindingsStream;
87
- }, false, algebraFactory, bindingsFactory);
91
+ }, false, bindingsFactory);
88
92
  return {
89
93
  result: {
90
94
  type: 'bindings',
@@ -92,7 +96,7 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
92
96
  metadata: () => this.constructResultMetadata(entries, entries.map(entry => entry.metadata), action.context),
93
97
  },
94
98
  physicalPlanMetadata: {
95
- bindIndex: sideData.entriesUnsorted.indexOf(entries[0]),
99
+ bindIndex: entriesUnsorted.indexOf(entries[0]),
96
100
  bindOperation: entries[0].operation,
97
101
  bindOperationCardinality: entries[0].metadata.cardinality,
98
102
  bindOrder: this.bindOrder,
@@ -113,22 +117,15 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
113
117
  });
114
118
  return valid;
115
119
  }
116
- async getJoinCoefficients(action, sideData) {
117
- let { metadatas } = sideData;
120
+ async getJoinCoefficients(action, metadatas) {
118
121
  // Order the entries so we can pick the first one (usually the one with the lowest cardinality)
119
- const entriesUnsorted = action.entries
120
- .map((entry, i) => ({ ...entry, metadata: metadatas[i] }));
121
- const entriesTest = await bus_rdf_join_1.ActorRdfJoin
122
- .sortJoinEntries(this.mediatorJoinEntriesSort, entriesUnsorted, action.context);
123
- if (entriesTest.isFailed()) {
124
- return entriesTest;
125
- }
126
- const entriesSorted = entriesTest.get();
127
- metadatas = entriesSorted.map(entry => entry.metadata);
122
+ const entries = await bus_rdf_join_1.ActorRdfJoin.sortJoinEntries(this.mediatorJoinEntriesSort, action.entries
123
+ .map((entry, i) => ({ ...entry, metadata: metadatas[i] })), action.context);
124
+ metadatas = entries.map(entry => entry.metadata);
128
125
  const requestInitialTimes = bus_rdf_join_1.ActorRdfJoin.getRequestInitialTimes(metadatas);
129
126
  const requestItemTimes = bus_rdf_join_1.ActorRdfJoin.getRequestItemTimes(metadatas);
130
127
  // Determine first stream and remaining ones
131
- const remainingEntries = [...entriesSorted];
128
+ const remainingEntries = [...entries];
132
129
  const remainingRequestInitialTimes = [...requestInitialTimes];
133
130
  const remainingRequestItemTimes = [...requestItemTimes];
134
131
  remainingEntries.splice(0, 1);
@@ -137,22 +134,22 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
137
134
  // Reject binding on some operation types
138
135
  if (remainingEntries
139
136
  .some(entry => !this.canBindWithOperation(entry.operation))) {
140
- return (0, core_1.failTest)(`Actor ${this.name} can not bind on Extend and Group operations`);
137
+ throw new Error(`Actor ${this.name} can not bind on Extend and Group operations`);
141
138
  }
142
139
  // Reject binding on modified operations, since using the output directly would be significantly more efficient.
143
140
  if (remainingEntries.some(entry => entry.operationModified)) {
144
- return (0, core_1.failTest)(`Actor ${this.name} can not be used over remaining entries with modified operations`);
141
+ throw new Error(`Actor ${this.name} can not be used over remaining entries with modified operations`);
145
142
  }
146
143
  // Only run this actor if the smallest stream is significantly smaller than the largest stream.
147
144
  // We must use Math.max, because the last metadata is not necessarily the biggest, but it's the least preferred.
148
145
  if (metadatas[0].cardinality.value * this.minMaxCardinalityRatio >
149
146
  Math.max(...metadatas.map(metadata => metadata.cardinality.value))) {
150
- return (0, core_1.failTest)(`Actor ${this.name} can only run if the smallest stream is much smaller than largest stream`);
147
+ throw new Error(`Actor ${this.name} can only run if the smallest stream is much smaller than largest stream`);
151
148
  }
152
149
  // Determine selectivities of smallest entry with all other entries
153
150
  const selectivities = await Promise.all(remainingEntries
154
151
  .map(async (entry) => (await this.mediatorJoinSelectivity.mediate({
155
- entries: [entriesSorted[0], entry],
152
+ entries: [entries[0], entry],
156
153
  context: action.context,
157
154
  })).selectivity * this.selectivityModifier));
158
155
  // Determine coefficients for remaining entries
@@ -163,7 +160,7 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
163
160
  .reduce((sum, element) => sum + element, 0);
164
161
  const receiveItemCostRemaining = remainingRequestItemTimes
165
162
  .reduce((sum, element) => sum + element, 0);
166
- return (0, core_1.passTestWithSideData)({
163
+ return {
167
164
  iterations: metadatas[0].cardinality.value * cardinalityRemaining,
168
165
  persistedItems: 0,
169
166
  blockingItems: 0,
@@ -171,8 +168,9 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
171
168
  metadatas[0].cardinality.value * (requestItemTimes[0] +
172
169
  receiveInitialCostRemaining +
173
170
  cardinalityRemaining * receiveItemCostRemaining),
174
- }, { ...sideData, entriesUnsorted, entriesSorted });
171
+ };
175
172
  }
176
173
  }
177
174
  exports.ActorRdfJoinMultiBind = ActorRdfJoinMultiBind;
175
+ ActorRdfJoinMultiBind.FACTORY = new sparqlalgebrajs_1.Factory();
178
176
  //# sourceMappingURL=ActorRdfJoinMultiBind.js.map
@@ -1 +1 @@
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,o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GAAG,wBAAwB,CAChD;SACJ,EAAE,EAAE,GAAG,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC,CAAC;IACtD,CAAC;CACF;AAvOD,sDAuOC","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 () => ({ entry: entries[0].operation, metadata: entries[0].metadata }),\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 algebraFactory.createJoin(operations);\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 (metadatas[0].cardinality.value * this.minMaxCardinalityRatio >\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":";;;AAAA,iEAA6D;AAG7D,uEAA0F;AAM1F,yDAAsD;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YACL,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,GAAG,oBAAoB;YACjE,cAAc,EAAE,CAAC;YACjB,aAAa,EAAE,CAAC;YAChB,WAAW,EAAE,mBAAmB,CAAC,CAAC,CAAC;gBACjC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,GAAG,CAC/B,gBAAgB,CAAC,CAAC,CAAC;oBACnB,2BAA2B;oBAC3B,oBAAoB,GAAG,wBAAwB,CAChD;SACJ,CAAC;IACJ,CAAC;;AAvNH,sDAwNC;AAhNwB,6BAAO,GAAG,IAAI,yBAAO,EAAE,CAAC","sourcesContent":["import { BindingsFactory } from '@comunica/bindings-factory';\nimport type { MediatorMergeBindingsContext } from '@comunica/bus-merge-bindings-context';\nimport 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, MetadataBindings } from '@comunica/types';\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 {\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 static readonly FACTORY = new Factory();\n\n public constructor(args: IActorRdfJoinMultiBindArgs) {\n // TODO: remove this fallback in the next major update\n if (args.minMaxCardinalityRatio === undefined) {\n args.minMaxCardinalityRatio = 60;\n }\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 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\n .map(operation => materializeOperation(operation, bindings, bindingsFactory, { bindFilter: true }));\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(action: IActionRdfJoin): Promise<IActorRdfJoinOutputInner> {\n const bindingsFactory = await BindingsFactory.create(this.mediatorMergeBindingsContext, action.context);\n\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 ActorRdfJoin.sortJoinEntries(this.mediatorJoinEntriesSort, entriesUnsorted, action.context);\n\n this.logDebug(\n action.context,\n 'First entry for Bind Join: ',\n () => ({ entry: entries[0].operation, metadata: entries[0].metadata }),\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 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 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: 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 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 ActorRdfJoin.sortJoinEntries(this.mediatorJoinEntriesSort, 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 => !this.canBindWithOperation(entry.operation))) {\n throw new Error(`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 throw new Error(`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 (metadatas[0].cardinality.value * this.minMaxCardinalityRatio >\n Math.max(...metadatas.map(metadata => metadata.cardinality.value))) {\n throw new Error(`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: [ 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) => sum + element, 0);\n const receiveItemCostRemaining = remainingRequestItemTimes\n .reduce((sum, element) => sum + element, 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 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"]}
package/package.json CHANGED
@@ -1,13 +1,9 @@
1
1
  {
2
2
  "name": "@comunica/actor-rdf-join-inner-multi-bind",
3
- "version": "3.2.4-alpha.47.0",
3
+ "version": "3.3.0",
4
4
  "description": "A multi-bind rdf-join actor",
5
5
  "lsd:module": true,
6
6
  "license": "MIT",
7
- "funding": {
8
- "type": "opencollective",
9
- "url": "https://opencollective.com/comunica-association"
10
- },
11
7
  "homepage": "https://comunica.dev/",
12
8
  "repository": {
13
9
  "type": "git",
@@ -41,18 +37,16 @@
41
37
  "build:components": "componentsjs-generator"
42
38
  },
43
39
  "dependencies": {
44
- "@comunica/bus-merge-bindings-context": "3.2.4-alpha.47.0",
45
- "@comunica/bus-query-operation": "3.2.4-alpha.47.0",
46
- "@comunica/bus-rdf-join": "3.2.4-alpha.47.0",
47
- "@comunica/bus-rdf-join-entries-sort": "3.2.4-alpha.47.0",
48
- "@comunica/context-entries": "3.2.4-alpha.47.0",
49
- "@comunica/core": "3.2.4-alpha.47.0",
50
- "@comunica/mediatortype-join-coefficients": "3.2.4-alpha.47.0",
51
- "@comunica/types": "3.2.4-alpha.47.0",
52
- "@comunica/utils-bindings-factory": "3.2.4-alpha.47.0",
53
- "@comunica/utils-query-operation": "3.2.4-alpha.47.0",
40
+ "@comunica/bindings-factory": "^3.3.0",
41
+ "@comunica/bus-merge-bindings-context": "^3.3.0",
42
+ "@comunica/bus-query-operation": "^3.3.0",
43
+ "@comunica/bus-rdf-join": "^3.3.0",
44
+ "@comunica/bus-rdf-join-entries-sort": "^3.3.0",
45
+ "@comunica/context-entries": "^3.3.0",
46
+ "@comunica/mediatortype-join-coefficients": "^3.3.0",
47
+ "@comunica/types": "^3.3.0",
54
48
  "asynciterator": "^3.9.0",
55
- "sparqlalgebrajs": "^4.3.8"
49
+ "sparqlalgebrajs": "^4.3.7"
56
50
  },
57
- "gitHead": "85bd4c5cf07dfc293ebbc3a1416b70e2db8bfc48"
51
+ "gitHead": "02bde397d206f1f5a523643a6a604c89e792e2f9"
58
52
  }