@comunica/actor-rdf-join-inner-multi-bind 5.3.0 → 5.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.
@@ -51,6 +51,34 @@
51
51
  "default": "60",
52
52
  "comment": "The number of times the smallest cardinality should fit in the maximum cardinality."
53
53
  },
54
+ {
55
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_subQueryCost",
56
+ "range": {
57
+ "@type": "ParameterRangeUnion",
58
+ "parameterRangeElements": [
59
+ "xsd:double",
60
+ {
61
+ "@type": "ParameterRangeUndefined"
62
+ }
63
+ ]
64
+ },
65
+ "default": "100",
66
+ "comment": "The cost of planning and evaluating one bound operation, expressed in produced rows. Not applied to remote sources."
67
+ },
68
+ {
69
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_lookupCost",
70
+ "range": {
71
+ "@type": "ParameterRangeUnion",
72
+ "parameterRangeElements": [
73
+ "xsd:double",
74
+ {
75
+ "@type": "ParameterRangeUndefined"
76
+ }
77
+ ]
78
+ },
79
+ "default": "25",
80
+ "comment": "The cost of looking up a single bound pattern, in number of produced results. This is used for local sources instead of subQueryCost."
81
+ },
54
82
  {
55
83
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_mediatorJoinEntriesSort",
56
84
  "range": "cc:components/Mediator.jsonld#Mediator",
@@ -210,6 +238,16 @@
210
238
  "memberFieldName": "minMaxCardinalityRatio",
211
239
  "range": "xsd:number"
212
240
  },
241
+ {
242
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_subQueryCost",
243
+ "memberFieldName": "subQueryCost",
244
+ "range": "xsd:number"
245
+ },
246
+ {
247
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_lookupCost",
248
+ "memberFieldName": "lookupCost",
249
+ "range": "xsd:number"
250
+ },
213
251
  {
214
252
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_mediatorJoinEntriesSort",
215
253
  "memberFieldName": "mediatorJoinEntriesSort",
@@ -241,6 +279,10 @@
241
279
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_canBindWithOperation",
242
280
  "memberFieldName": "canBindWithOperation"
243
281
  },
282
+ {
283
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_filterUsesOutOfScopeVariables",
284
+ "memberFieldName": "filterUsesOutOfScopeVariables"
285
+ },
244
286
  {
245
287
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_getJoinCoefficients",
246
288
  "memberFieldName": "getJoinCoefficients"
@@ -268,6 +310,18 @@
268
310
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_minMaxCardinalityRatio"
269
311
  }
270
312
  },
313
+ {
314
+ "keyRaw": "subQueryCost",
315
+ "value": {
316
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_subQueryCost"
317
+ }
318
+ },
319
+ {
320
+ "keyRaw": "lookupCost",
321
+ "value": {
322
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_lookupCost"
323
+ }
324
+ },
271
325
  {
272
326
  "keyRaw": "mediatorJoinEntriesSort",
273
327
  "value": {
@@ -347,6 +401,14 @@
347
401
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindArgs__member_minMaxCardinalityRatio",
348
402
  "memberFieldName": "minMaxCardinalityRatio"
349
403
  },
404
+ {
405
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindArgs__member_subQueryCost",
406
+ "memberFieldName": "subQueryCost"
407
+ },
408
+ {
409
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindArgs__member_lookupCost",
410
+ "memberFieldName": "lookupCost"
411
+ },
350
412
  {
351
413
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindArgs__member_mediatorJoinEntriesSort",
352
414
  "memberFieldName": "mediatorJoinEntriesSort"
@@ -17,6 +17,12 @@
17
17
  "args_minMaxCardinalityRatio": {
18
18
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_minMaxCardinalityRatio"
19
19
  },
20
+ "args_subQueryCost": {
21
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_subQueryCost"
22
+ },
23
+ "args_lookupCost": {
24
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_lookupCost"
25
+ },
20
26
  "args_mediatorJoinEntriesSort": {
21
27
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_mediatorJoinEntriesSort"
22
28
  },
@@ -51,6 +57,12 @@
51
57
  "minMaxCardinalityRatio": {
52
58
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_minMaxCardinalityRatio"
53
59
  },
60
+ "subQueryCost": {
61
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_subQueryCost"
62
+ },
63
+ "lookupCost": {
64
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_lookupCost"
65
+ },
54
66
  "mediatorJoinEntriesSort": {
55
67
  "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_mediatorJoinEntriesSort"
56
68
  },
@@ -8,6 +8,7 @@ import type { IMediatorTypeJoinCoefficients } from '@comunica/mediatortype-join-
8
8
  import type { Bindings, BindingsStream, IJoinEntryWithMetadata } from '@comunica/types';
9
9
  import { AlgebraFactory, Algebra } from '@comunica/utils-algebra';
10
10
  import { BindingsFactory } from '@comunica/utils-bindings-factory';
11
+ import type * as RDF from '@rdfjs/types';
11
12
  /**
12
13
  * A comunica Multi-way Bind RDF Join Actor.
13
14
  */
@@ -15,6 +16,8 @@ export declare class ActorRdfJoinMultiBind extends ActorRdfJoin<IActorRdfJoinMul
15
16
  readonly bindOrder: BindOrder;
16
17
  readonly selectivityModifier: number;
17
18
  readonly minMaxCardinalityRatio: number;
19
+ readonly subQueryCost: number;
20
+ readonly lookupCost: number;
18
21
  readonly mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;
19
22
  readonly mediatorQueryOperation: MediatorQueryOperation;
20
23
  readonly mediatorMergeBindingsContext: MediatorMergeBindingsContext;
@@ -32,7 +35,14 @@ export declare class ActorRdfJoinMultiBind extends ActorRdfJoin<IActorRdfJoinMul
32
35
  */
33
36
  static createBindStream(bindOrder: BindOrder, baseStream: BindingsStream, operations: Algebra.Operation[], operationBinder: (boundOperations: Algebra.Operation[], operationBindings: Bindings) => Promise<BindingsStream>, optional: boolean, algebraFactory: AlgebraFactory, bindingsFactory: BindingsFactory): BindingsStream;
34
37
  getOutput(action: IActionRdfJoin, sideData: IActorRdfJoinMultiBindTestSideData): Promise<IActorRdfJoinOutputInner>;
35
- canBindWithOperation(operation: Algebra.Operation): boolean;
38
+ static canBindWithOperation(operation: Algebra.Operation, boundVariables?: RDF.Variable[]): boolean;
39
+ /**
40
+ * Check if the expression of the given FILTER uses any of the given variables
41
+ * that are not in scope of the FILTER's input.
42
+ * @param filter A FILTER operation.
43
+ * @param variableNames Variable names.
44
+ */
45
+ static filterUsesOutOfScopeVariables(filter: Algebra.Filter, variableNames: string[]): boolean;
36
46
  getJoinCoefficients(action: IActionRdfJoin, sideData: IActorRdfJoinTestSideData): Promise<TestResult<IMediatorTypeJoinCoefficients, IActorRdfJoinMultiBindTestSideData>>;
37
47
  }
38
48
  export interface IActorRdfJoinMultiBindArgs extends IActorRdfJoinArgs<IActorRdfJoinMultiBindTestSideData> {
@@ -53,6 +63,20 @@ export interface IActorRdfJoinMultiBindArgs extends IActorRdfJoinArgs<IActorRdfJ
53
63
  * @default {60}
54
64
  */
55
65
  minMaxCardinalityRatio: number;
66
+ /**
67
+ * The cost of planning and evaluating one bound operation, expressed in produced rows.
68
+ * Not applied to remote sources.
69
+ * @range {double}
70
+ * @default {100}
71
+ */
72
+ subQueryCost?: number;
73
+ /**
74
+ * The cost of looking up a single bound pattern, in number of produced results.
75
+ * This is used for local sources instead of subQueryCost.
76
+ * @range {double}
77
+ * @default {25}
78
+ */
79
+ lookupCost?: number;
56
80
  /**
57
81
  * The join entries sort mediator
58
82
  */
@@ -15,6 +15,8 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
15
15
  bindOrder;
16
16
  selectivityModifier;
17
17
  minMaxCardinalityRatio;
18
+ subQueryCost;
19
+ lookupCost;
18
20
  mediatorJoinEntriesSort;
19
21
  mediatorQueryOperation;
20
22
  mediatorMergeBindingsContext;
@@ -23,11 +25,13 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
23
25
  logicalType: 'inner',
24
26
  physicalName: 'bind',
25
27
  canHandleUndefs: true,
26
- isLeaf: false,
28
+ canHandleOperationRequired: true,
27
29
  });
28
30
  this.bindOrder = args.bindOrder;
29
31
  this.selectivityModifier = args.selectivityModifier;
30
32
  this.minMaxCardinalityRatio = args.minMaxCardinalityRatio;
33
+ this.subQueryCost = args.subQueryCost ?? 100;
34
+ this.lookupCost = args.lookupCost ?? 25;
31
35
  this.mediatorJoinEntriesSort = args.mediatorJoinEntriesSort;
32
36
  this.mediatorQueryOperation = args.mediatorQueryOperation;
33
37
  this.mediatorMergeBindingsContext = args.mediatorMergeBindingsContext;
@@ -92,7 +96,7 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
92
96
  const remainingEntries = [...entries];
93
97
  remainingEntries.splice(0, 1);
94
98
  // Bind the remaining patterns for each binding in the stream
95
- const subContext = action.context
99
+ const subContext = (0, utils_query_operation_1.groupRepeatedSubOperations)(action.context, 'bindings', this.name)
96
100
  .set(context_entries_1.KeysQueryOperation.joinLeftMetadata, entries[0].metadata)
97
101
  .set(context_entries_1.KeysQueryOperation.joinRightMetadatas, remainingEntries.map(entry => entry.metadata));
98
102
  const bindingsStream = ActorRdfJoinMultiBind.createBindStream(this.bindOrder, smallestStream.bindingsStream, remainingEntries.map(entry => entry.operation), async (operations, operationBindings) => {
@@ -112,26 +116,103 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
112
116
  },
113
117
  physicalPlanMetadata: {
114
118
  bindIndex: sideData.entriesUnsorted.indexOf(entries[0]),
115
- bindOperation: entries[0].operation,
116
- bindOperationCardinality: entries[0].metadata.cardinality,
117
119
  bindOrder: this.bindOrder,
118
120
  },
119
121
  };
120
122
  }
121
- canBindWithOperation(operation) {
123
+ static canBindWithOperation(operation, boundVariables) {
122
124
  let valid = true;
125
+ const boundVarNames = boundVariables ? boundVariables.map(v => v.value) : [];
126
+ const skipHandler = {
127
+ preVisitor: () => {
128
+ valid = false;
129
+ return { shortcut: true };
130
+ },
131
+ };
123
132
  utils_algebra_1.algebraUtils.visitOperation(operation, {
124
- [utils_algebra_1.Algebra.Types.EXTEND]: { preVisitor: () => {
125
- valid = false;
126
- return { shortcut: true };
127
- } },
128
- [utils_algebra_1.Algebra.Types.GROUP]: { preVisitor: () => {
129
- valid = false;
130
- return { shortcut: true };
131
- } },
133
+ [utils_algebra_1.Algebra.Types.EXTEND]: skipHandler,
134
+ [utils_algebra_1.Algebra.Types.GROUP]: skipHandler,
135
+ [utils_algebra_1.Algebra.Types.LEFT_JOIN]: {
136
+ preVisitor: (op) => {
137
+ // Default: valid
138
+ if (!boundVariables) {
139
+ return { shortcut: false };
140
+ }
141
+ const leftOp = op.input[0];
142
+ const rightOp = op.input[1];
143
+ const leftVars = new Set((0, utils_algebra_1.inScopeVariables)(leftOp).map(v => v.value));
144
+ const rightVars = (0, utils_algebra_1.inScopeVariables)(rightOp).map(v => v.value);
145
+ const conflict = rightVars.some(v => !leftVars.has(v) && boundVarNames.includes(v));
146
+ if (conflict) {
147
+ valid = false;
148
+ return { shortcut: true };
149
+ }
150
+ return { shortcut: false };
151
+ },
152
+ },
153
+ [utils_algebra_1.Algebra.Types.MINUS]: {
154
+ preVisitor: (op) => {
155
+ // Default: valid
156
+ if (!boundVariables) {
157
+ return { shortcut: false };
158
+ }
159
+ const rightOp = op.input[1];
160
+ const rightVars = (0, utils_algebra_1.inScopeVariables)(rightOp).map(v => v.value);
161
+ const conflict = rightVars.some(v => boundVarNames.includes(v));
162
+ if (conflict) {
163
+ valid = false;
164
+ return { shortcut: true };
165
+ }
166
+ return { shortcut: false };
167
+ },
168
+ },
169
+ [utils_algebra_1.Algebra.Types.FILTER]: {
170
+ preVisitor: (op) => {
171
+ // A FILTER that is a direct child of LEFT_JOIN may always use bound variables.
172
+ if (op.metadata?.isHoistedLeftJoinFilter) {
173
+ return { shortcut: false };
174
+ }
175
+ // Other FILTERs are only bound when they are evaluated by a source and variables are in scope.
176
+ if (!boundVariables || !(0, utils_query_operation_1.getOperationSource)(op) ||
177
+ ActorRdfJoinMultiBind.filterUsesOutOfScopeVariables(op, boundVarNames)) {
178
+ valid = false;
179
+ return { shortcut: true };
180
+ }
181
+ return { shortcut: false };
182
+ },
183
+ },
184
+ [utils_algebra_1.Algebra.Types.EXPRESSION]: {
185
+ preVisitor: (op) => {
186
+ // Don't descend into the sub-pattern of a FILTER (NOT) EXISTS:
187
+ // it is evaluated as its own independent query
188
+ if (op.subType === utils_algebra_1.Algebra.ExpressionTypes.EXISTENCE) {
189
+ return { continue: false };
190
+ }
191
+ return { shortcut: false };
192
+ },
193
+ },
132
194
  });
133
195
  return valid;
134
196
  }
197
+ /**
198
+ * Check if the expression of the given FILTER uses any of the given variables
199
+ * that are not in scope of the FILTER's input.
200
+ * @param filter A FILTER operation.
201
+ * @param variableNames Variable names.
202
+ */
203
+ static filterUsesOutOfScopeVariables(filter, variableNames) {
204
+ let expressionVariables;
205
+ try {
206
+ expressionVariables = (0, utils_query_operation_1.getExpressionVariables)(filter.expression);
207
+ }
208
+ catch {
209
+ // Unknown expression types are considered unsafe
210
+ return true;
211
+ }
212
+ const inputVariableNames = new Set((0, utils_algebra_1.inScopeVariables)(filter.input).map(variable => variable.value));
213
+ return expressionVariables
214
+ .some(variable => variableNames.includes(variable.value) && !inputVariableNames.has(variable.value));
215
+ }
135
216
  async getJoinCoefficients(action, sideData) {
136
217
  let { metadatas } = sideData;
137
218
  // Order the entries so we can pick the first one (usually the one with the lowest cardinality)
@@ -143,6 +224,16 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
143
224
  return entriesTest;
144
225
  }
145
226
  const entriesSorted = entriesTest.get();
227
+ // Find the first entry that does not require operation pushdown.
228
+ const bindableIndex = entriesSorted
229
+ .findIndex(entry => !bus_rdf_join_1.ActorRdfJoin.isOperationRequired(entry, entry.metadata));
230
+ if (bindableIndex < 0) {
231
+ return (0, core_1.failTest)(`Actor ${this.name} requires at least one entry of which the operation does not need to be pushed down`);
232
+ }
233
+ // This case could occur for variable SERVICE targets, which need to be bound later.
234
+ if (bindableIndex > 0) {
235
+ entriesSorted.unshift(...entriesSorted.splice(bindableIndex, 1));
236
+ }
146
237
  metadatas = entriesSorted.map(entry => entry.metadata);
147
238
  const requestInitialTimes = bus_rdf_join_1.ActorRdfJoin.getRequestInitialTimes(metadatas);
148
239
  const requestItemTimes = bus_rdf_join_1.ActorRdfJoin.getRequestItemTimes(metadatas);
@@ -154,9 +245,10 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
154
245
  remainingRequestInitialTimes.splice(0, 1);
155
246
  remainingRequestItemTimes.splice(0, 1);
156
247
  // Reject binding on some operation types
248
+ const boundVariables = metadatas[0].variables.map(variable => variable.variable);
157
249
  if (remainingEntries
158
- .some(entry => !this.canBindWithOperation(entry.operation))) {
159
- return (0, core_1.failTest)(`Actor ${this.name} can not bind on Extend and Group operations`);
250
+ .some(entry => !ActorRdfJoinMultiBind.canBindWithOperation(entry.operation, boundVariables))) {
251
+ return (0, core_1.failTest)(`Actor ${this.name} can not bind on Extend, Group, or conflicting LeftJoin/Minus/Filter operations`);
160
252
  }
161
253
  // Reject binding on modified operations, since using the output directly would be significantly more efficient.
162
254
  if (remainingEntries.some(entry => entry.operationModified)) {
@@ -176,20 +268,40 @@ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
176
268
  entries: [entriesSorted[0], entry],
177
269
  context: action.context,
178
270
  })).selectivity * this.selectivityModifier));
179
- // Determine coefficients for remaining entries
271
+ // Bindings each remaining entry adds per binding of the first: their pairwise join capped by the
272
+ // variables they share, spread over the first entry's cardinality, so at most one. Entries sharing no
273
+ // variable have no such cap and keep using the join selectivity.
274
+ const cardinalityFirst = metadatas[0].cardinality.value;
275
+ let entriesWithoutSharedVariable = 0;
180
276
  const cardinalityRemaining = remainingEntries
181
- .map((entry, i) => entry.metadata.cardinality.value * selectivities[i])
277
+ .map((entry, i) => {
278
+ const joined = bus_rdf_join_1.ActorRdfJoin.getSharedVariableJoinCardinality([metadatas[0], entry.metadata]);
279
+ if (joined === undefined) {
280
+ entriesWithoutSharedVariable++;
281
+ return entry.metadata.cardinality.value * selectivities[i];
282
+ }
283
+ return joined / cardinalityFirst;
284
+ })
182
285
  .reduce((sum, element) => sum + element, 0);
183
286
  const receiveInitialCostRemaining = remainingRequestInitialTimes
184
287
  .reduce((sum, element) => sum + element, 0);
185
288
  const receiveItemCostRemaining = remainingRequestItemTimes
186
289
  .reduce((sum, element) => sum + element, 0);
290
+ // Each binding re-plans and re-runs every remaining operation.
291
+ // This does not apply to remote sources, where this cost is already incorporated into requestTime.
292
+ let subPlanCost = 0;
293
+ if (!isRemoteAccess) {
294
+ subPlanCost = entriesWithoutSharedVariable === 0 &&
295
+ remainingEntries.every(entry => entry.operation.type === utils_algebra_1.Algebra.Types.PATTERN) ?
296
+ this.lookupCost * remainingEntries.length :
297
+ this.subQueryCost * remainingEntries.length * (1 + entriesWithoutSharedVariable);
298
+ }
187
299
  return (0, core_1.passTestWithSideData)({
188
- iterations: metadatas[0].cardinality.value * cardinalityRemaining,
300
+ iterations: cardinalityFirst * (cardinalityRemaining + subPlanCost),
189
301
  persistedItems: 0,
190
302
  blockingItems: 0,
191
303
  requestTime: requestInitialTimes[0] +
192
- metadatas[0].cardinality.value * (requestItemTimes[0] +
304
+ cardinalityFirst * (requestItemTimes[0] +
193
305
  receiveInitialCostRemaining +
194
306
  cardinalityRemaining * receiveItemCostRemaining),
195
307
  }, { ...sideData, entriesUnsorted, entriesSorted });
@@ -1 +1 @@
1
- {"version":3,"file":"ActorRdfJoinMultiBind.js","sourceRoot":"","sources":["ActorRdfJoinMultiBind.ts"],"names":[],"mappings":";;;AAQA,yDAAsD;AAEtD,+DAA8E;AAE9E,yCAAgE;AAShE,2DAAgF;AAChF,6EAAmE;AACnE,2EAAwF;AACxF,iDAAyF;AAEzF;;GAEG;AACH,MAAa,qBAAsB,SAAQ,2BAAgD;IACzE,SAAS,CAAY;IACrB,mBAAmB,CAAS;IAC5B,sBAAsB,CAAS;IAC/B,uBAAuB,CAA6B;IACpD,sBAAsB,CAAyB;IAC/C,4BAA4B,CAA+B;IAE3E,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;QACH,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,mBAAmB,CAAC;QACpD,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC,sBAAsB,CAAC;QAC1D,IAAI,CAAC,uBAAuB,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OAAO;SACxB,CAAC,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAE/C,+CAA+C;QAC/C,MAAM,oBAAoB,GAAG,gBAAgB;aAC1C,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;aACtE,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,GAAG,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC;QAC9C,MAAM,2BAA2B,GAAG,4BAA4B;aAC7D,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,GAAG,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC;QAC9C,MAAM,wBAAwB,GAAG,yBAAyB;aACvD,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,GAAG,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC;QAE9C,OAAO,IAAA,2BAAoB,EAAC;YAC1B,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,EAAE,EAAE,GAAG,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC,CAAC;IACtD,CAAC;CACF;AAtPD,sDAsPC","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 this.bindOrder = args.bindOrder;\n this.selectivityModifier = args.selectivityModifier;\n this.minMaxCardinalityRatio = args.minMaxCardinalityRatio;\n this.mediatorJoinEntriesSort = args.mediatorJoinEntriesSort;\n this.mediatorQueryOperation = args.mediatorQueryOperation;\n this.mediatorMergeBindingsContext = args.mediatorMergeBindingsContext;\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,2DAAkG;AAClG,6EAAmE;AACnE,2EAMyC;AAEzC,iDAAyF;AAEzF;;GAEG;AACH,MAAa,qBAAsB,SAAQ,2BAAgD;IACzE,SAAS,CAAY;IACrB,mBAAmB,CAAS;IAC5B,sBAAsB,CAAS;IAC/B,YAAY,CAAS;IACrB,UAAU,CAAS;IACnB,uBAAuB,CAA6B;IACpD,sBAAsB,CAAyB;IAC/C,4BAA4B,CAA+B;IAE3E,YAAmB,IAAgC;QACjD,KAAK,CAAC,IAAI,EAAE;YACV,WAAW,EAAE,OAAO;YACpB,YAAY,EAAE,MAAM;YACpB,eAAe,EAAE,IAAI;YACrB,0BAA0B,EAAE,IAAI;SACjC,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,mBAAmB,CAAC;QACpD,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC,sBAAsB,CAAC;QAC1D,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,IAAI,GAAG,CAAC;QAC7C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC;QACxC,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC,uBAAuB,CAAC;QAC5D,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC,sBAAsB,CAAC;QAC1D,IAAI,CAAC,4BAA4B,GAAG,IAAI,CAAC,4BAA4B,CAAC;IACxE,CAAC;IAED;;;;;;;;;;OAUG;IACI,MAAM,CAAC,gBA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9C,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,KAAK,uBAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;gBACjF,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;gBAC3C,IAAI,CAAC,YAAY,GAAG,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,4BAA4B,CAAC,CAAC;QACrF,CAAC;QAED,OAAO,IAAA,2BAAoB,EAAC;YAC1B,UAAU,EAAE,gBAAgB,GAAG,CAAC,oBAAoB,GAAG,WAAW,CAAC;YACnE,cAAc,EAAE,CAAC;YACjB,aAAa,EAAE,CAAC;YAChB,WAAW,EAAE,mBAAmB,CAAC,CAAC,CAAC;gBACjC,gBAAgB,GAAG,CACjB,gBAAgB,CAAC,CAAC,CAAC;oBACnB,2BAA2B;oBAC3B,oBAAoB,GAAG,wBAAwB,CAChD;SACJ,EAAE,EAAE,GAAG,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC,CAAC;IACtD,CAAC;CACF;AAhXD,sDAgXC","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, inScopeVariables } from '@comunica/utils-algebra';\nimport { BindingsFactory } from '@comunica/utils-bindings-factory';\nimport {\n getExpressionVariables,\n getOperationSource,\n getSafeBindings,\n groupRepeatedSubOperations,\n materializeOperation,\n} from '@comunica/utils-query-operation';\nimport type * as RDF from '@rdfjs/types';\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 subQueryCost: number;\n public readonly lookupCost: 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 canHandleOperationRequired: true,\n });\n this.bindOrder = args.bindOrder;\n this.selectivityModifier = args.selectivityModifier;\n this.minMaxCardinalityRatio = args.minMaxCardinalityRatio;\n this.subQueryCost = args.subQueryCost ?? 100;\n this.lookupCost = args.lookupCost ?? 25;\n this.mediatorJoinEntriesSort = args.mediatorJoinEntriesSort;\n this.mediatorQueryOperation = args.mediatorQueryOperation;\n this.mediatorMergeBindingsContext = args.mediatorMergeBindingsContext;\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 = groupRepeatedSubOperations(action.context, 'bindings', this.name)\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 bindOrder: this.bindOrder,\n },\n };\n }\n\n public static canBindWithOperation(operation: Algebra.Operation, boundVariables?: RDF.Variable[]): boolean {\n let valid = true;\n const boundVarNames = boundVariables ? boundVariables.map(v => v.value) : [];\n\n const skipHandler = {\n preVisitor: () => {\n valid = false;\n return { shortcut: true };\n },\n };\n\n algebraUtils.visitOperation(operation, {\n [Algebra.Types.EXTEND]: skipHandler,\n [Algebra.Types.GROUP]: skipHandler,\n [Algebra.Types.LEFT_JOIN]: {\n preVisitor: (op: Algebra.LeftJoin) => {\n // Default: valid\n if (!boundVariables) {\n return { shortcut: false };\n }\n\n const leftOp = op.input[0];\n const rightOp = op.input[1];\n\n const leftVars = new Set(inScopeVariables(leftOp).map(v => v.value));\n const rightVars = inScopeVariables(rightOp).map(v => v.value);\n\n const conflict = rightVars.some(v => !leftVars.has(v) && boundVarNames.includes(v));\n if (conflict) {\n valid = false;\n return { shortcut: true };\n }\n return { shortcut: false };\n },\n },\n [Algebra.Types.MINUS]: {\n preVisitor: (op: Algebra.Minus) => {\n // Default: valid\n if (!boundVariables) {\n return { shortcut: false };\n }\n\n const rightOp = op.input[1];\n const rightVars = inScopeVariables(rightOp).map(v => v.value);\n\n const conflict = rightVars.some(v => boundVarNames.includes(v));\n if (conflict) {\n valid = false;\n return { shortcut: true };\n }\n return { shortcut: false };\n },\n },\n [Algebra.Types.FILTER]: {\n preVisitor: (op: Algebra.Filter) => {\n // A FILTER that is a direct child of LEFT_JOIN may always use bound variables.\n if (op.metadata?.isHoistedLeftJoinFilter) {\n return { shortcut: false };\n }\n // Other FILTERs are only bound when they are evaluated by a source and variables are in scope.\n if (!boundVariables || !getOperationSource(op) ||\n ActorRdfJoinMultiBind.filterUsesOutOfScopeVariables(op, boundVarNames)) {\n valid = false;\n return { shortcut: true };\n }\n return { shortcut: false };\n },\n },\n [Algebra.Types.EXPRESSION]: {\n preVisitor: (op: Algebra.Expression) => {\n // Don't descend into the sub-pattern of a FILTER (NOT) EXISTS:\n // it is evaluated as its own independent query\n if (op.subType === Algebra.ExpressionTypes.EXISTENCE) {\n return { continue: false };\n }\n return { shortcut: false };\n },\n },\n });\n\n return valid;\n }\n\n /**\n * Check if the expression of the given FILTER uses any of the given variables\n * that are not in scope of the FILTER's input.\n * @param filter A FILTER operation.\n * @param variableNames Variable names.\n */\n public static filterUsesOutOfScopeVariables(filter: Algebra.Filter, variableNames: string[]): boolean {\n let expressionVariables: RDF.Variable[];\n try {\n expressionVariables = getExpressionVariables(filter.expression);\n } catch {\n // Unknown expression types are considered unsafe\n return true;\n }\n const inputVariableNames = new Set(inScopeVariables(filter.input).map(variable => variable.value));\n return expressionVariables\n .some(variable => variableNames.includes(variable.value) && !inputVariableNames.has(variable.value));\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\n // Find the first entry that does not require operation pushdown.\n const bindableIndex = entriesSorted\n .findIndex(entry => !ActorRdfJoin.isOperationRequired(entry, entry.metadata));\n if (bindableIndex < 0) {\n return failTest(`Actor ${this.name} requires at least one entry of which the operation does not need to be pushed down`);\n }\n // This case could occur for variable SERVICE targets, which need to be bound later.\n if (bindableIndex > 0) {\n entriesSorted.unshift(...entriesSorted.splice(bindableIndex, 1));\n }\n\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 const boundVariables = metadatas[0].variables.map(variable => variable.variable);\n if (remainingEntries\n .some(entry => !ActorRdfJoinMultiBind.canBindWithOperation(entry.operation, boundVariables))) {\n return failTest(`Actor ${this.name} can not bind on Extend, Group, or conflicting LeftJoin/Minus/Filter 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 // Bindings each remaining entry adds per binding of the first: their pairwise join capped by the\n // variables they share, spread over the first entry's cardinality, so at most one. Entries sharing no\n // variable have no such cap and keep using the join selectivity.\n const cardinalityFirst = metadatas[0].cardinality.value;\n let entriesWithoutSharedVariable = 0;\n const cardinalityRemaining = remainingEntries\n .map((entry, i) => {\n const joined = ActorRdfJoin.getSharedVariableJoinCardinality([ metadatas[0], entry.metadata ]);\n if (joined === undefined) {\n entriesWithoutSharedVariable++;\n return entry.metadata.cardinality.value * selectivities[i];\n }\n return joined / cardinalityFirst;\n })\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 // Each binding re-plans and re-runs every remaining operation.\n // This does not apply to remote sources, where this cost is already incorporated into requestTime.\n let subPlanCost = 0;\n if (!isRemoteAccess) {\n subPlanCost = entriesWithoutSharedVariable === 0 &&\n remainingEntries.every(entry => entry.operation.type === Algebra.Types.PATTERN) ?\n this.lookupCost * remainingEntries.length :\n this.subQueryCost * remainingEntries.length * (1 + entriesWithoutSharedVariable);\n }\n\n return passTestWithSideData({\n iterations: cardinalityFirst * (cardinalityRemaining + subPlanCost),\n persistedItems: 0,\n blockingItems: 0,\n requestTime: requestInitialTimes[0] +\n cardinalityFirst * (\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 // TODO: in next major, make mandatory.\n /**\n * The cost of planning and evaluating one bound operation, expressed in produced rows.\n * Not applied to remote sources.\n * @range {double}\n * @default {100}\n */\n subQueryCost?: number;\n // TODO: in next major, make mandatory.\n /**\n * The cost of looking up a single bound pattern, in number of produced results.\n * This is used for local sources instead of subQueryCost.\n * @range {double}\n * @default {25}\n */\n lookupCost?: 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comunica/actor-rdf-join-inner-multi-bind",
3
- "version": "5.3.0",
3
+ "version": "5.5.0",
4
4
  "description": "A multi-bind rdf-join actor",
5
5
  "lsd:module": true,
6
6
  "license": "MIT",
@@ -41,18 +41,19 @@
41
41
  "build:components": "componentsjs-generator"
42
42
  },
43
43
  "dependencies": {
44
- "@comunica/bus-merge-bindings-context": "^5.3.0",
45
- "@comunica/bus-query-operation": "^5.3.0",
46
- "@comunica/bus-rdf-join": "^5.3.0",
47
- "@comunica/bus-rdf-join-entries-sort": "^5.3.0",
48
- "@comunica/context-entries": "^5.3.0",
49
- "@comunica/core": "^5.3.0",
50
- "@comunica/mediatortype-join-coefficients": "^5.3.0",
51
- "@comunica/types": "^5.3.0",
52
- "@comunica/utils-algebra": "^5.3.0",
53
- "@comunica/utils-bindings-factory": "^5.3.0",
54
- "@comunica/utils-query-operation": "^5.3.0",
44
+ "@comunica/bus-merge-bindings-context": "^5.5.0",
45
+ "@comunica/bus-query-operation": "^5.5.0",
46
+ "@comunica/bus-rdf-join": "^5.5.0",
47
+ "@comunica/bus-rdf-join-entries-sort": "^5.5.0",
48
+ "@comunica/context-entries": "^5.5.0",
49
+ "@comunica/core": "^5.5.0",
50
+ "@comunica/mediatortype-join-coefficients": "^5.5.0",
51
+ "@comunica/types": "^5.5.0",
52
+ "@comunica/utils-algebra": "^5.5.0",
53
+ "@comunica/utils-bindings-factory": "^5.5.0",
54
+ "@comunica/utils-query-operation": "^5.5.0",
55
+ "@rdfjs/types": "*",
55
56
  "asynciterator": "^3.10.0"
56
57
  },
57
- "gitHead": "8a9d8e4a706d64268e1e222b4c561caa47798f72"
58
+ "gitHead": "3a258e018a9c5f0b03f531b30ee1cdc659b5b7c9"
58
59
  }