@comunica/actor-optimize-query-operation-filter-pushdown 4.4.2-alpha.49.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
File without changes
@@ -2,8 +2,8 @@ import type { IActionOptimizeQueryOperation, IActorOptimizeQueryOperationArgs, I
2
2
  import { ActorOptimizeQueryOperation } from '@comunica/bus-optimize-query-operation';
3
3
  import type { IActorTest, TestResult } from '@comunica/core';
4
4
  import type { FragmentSelectorShape, IActionContext, IQuerySourceWrapper } from '@comunica/types';
5
- import { AlgebraFactory, Algebra } from '@comunica/utils-algebra';
6
5
  import type * as RDF from '@rdfjs/types';
6
+ import { Factory, Algebra } from 'sparqlalgebrajs';
7
7
  /**
8
8
  * A comunica Filter Pushdown Optimize Query Operation Actor.
9
9
  */
@@ -37,7 +37,7 @@ export declare class ActorOptimizeQueryOperationFilterPushdown extends ActorOpti
37
37
  * @param operation An operation.
38
38
  */
39
39
  getSources(operation: Algebra.Operation): IQuerySourceWrapper[];
40
- protected getOverlappingOperations(operation: Algebra.Union | Algebra.Join, expressionVariables: RDF.Variable[]): {
40
+ protected getOverlappingOperations(operation: Algebra.Operation, expressionVariables: RDF.Variable[]): {
41
41
  fullyOverlapping: Algebra.Operation[];
42
42
  partiallyOverlapping: Algebra.Operation[];
43
43
  notOverlapping: Algebra.Operation[];
@@ -55,7 +55,7 @@ export declare class ActorOptimizeQueryOperationFilterPushdown extends ActorOpti
55
55
  * @param context The action context.
56
56
  * @return A tuple indicating if the operation was modified and the modified operation.
57
57
  */
58
- filterPushdown(expression: Algebra.Expression, expressionVariables: RDF.Variable[], operation: Algebra.Operation, factory: AlgebraFactory, context: IActionContext): [boolean, Algebra.Operation];
58
+ filterPushdown(expression: Algebra.Expression, expressionVariables: RDF.Variable[], operation: Algebra.Operation, factory: Factory, context: IActionContext): [boolean, Algebra.Operation];
59
59
  /**
60
60
  * Check if the given expression is a simple equals operation with one variable and one non-literal
61
61
  * (or literal with canonical lexical form) term that can be pushed into a pattern.
@@ -4,9 +4,9 @@ exports.ActorOptimizeQueryOperationFilterPushdown = void 0;
4
4
  const bus_optimize_query_operation_1 = require("@comunica/bus-optimize-query-operation");
5
5
  const context_entries_1 = require("@comunica/context-entries");
6
6
  const core_1 = require("@comunica/core");
7
- const utils_algebra_1 = require("@comunica/utils-algebra");
8
7
  const utils_query_operation_1 = require("@comunica/utils-query-operation");
9
8
  const rdf_terms_1 = require("rdf-terms");
9
+ const sparqlalgebrajs_1 = require("sparqlalgebrajs");
10
10
  /**
11
11
  * A comunica Filter Pushdown Optimize Query Operation Actor.
12
12
  */
@@ -19,22 +19,29 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
19
19
  }
20
20
  async run(action) {
21
21
  const dataFactory = action.context.getSafe(context_entries_1.KeysInitQuery.dataFactory);
22
- const algebraFactory = new utils_algebra_1.AlgebraFactory(dataFactory);
22
+ const algebraFactory = new sparqlalgebrajs_1.Factory(dataFactory);
23
23
  let operation = action.operation;
24
+ // eslint-disable-next-line ts/no-this-alias
25
+ const self = this;
24
26
  // Split conjunctive filters into nested filters
25
27
  if (this.splitConjunctive) {
26
- operation = utils_algebra_1.algebraUtils.mapOperation(operation, {
27
- [utils_algebra_1.Algebra.Types.FILTER]: { transform: (filterOp) => {
28
- // Split conjunctive filters into separate filters
29
- if ((0, utils_algebra_1.isKnownSubType)(filterOp.expression, utils_algebra_1.Algebra.ExpressionTypes.OPERATOR) &&
30
- filterOp.expression.operator === '&&') {
31
- this.logDebug(action.context, `Split conjunctive filter into ${filterOp.expression.args.length} nested filters`);
32
- return filterOp.expression.args
33
- .reduce((operation, expression) => algebraFactory.createFilter(operation, expression), filterOp.input);
34
- }
35
- return filterOp;
36
- } },
37
- });
28
+ operation = sparqlalgebrajs_1.Util.mapOperation(operation, {
29
+ filter(op, factory) {
30
+ // Split conjunctive filters into separate filters
31
+ if (op.expression.expressionType === sparqlalgebrajs_1.Algebra.expressionTypes.OPERATOR && op.expression.operator === '&&') {
32
+ self.logDebug(action.context, `Split conjunctive filter into ${op.expression.args.length} nested filters`);
33
+ return {
34
+ recurse: true,
35
+ result: op.expression.args
36
+ .reduce((operation, expression) => factory.createFilter(operation, expression), op.input),
37
+ };
38
+ }
39
+ return {
40
+ recurse: true,
41
+ result: op,
42
+ };
43
+ },
44
+ }, algebraFactory);
38
45
  }
39
46
  // Collect selector shapes of all operations
40
47
  const sources = this.getSources(operation);
@@ -47,41 +54,54 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
47
54
  let iterations = 0;
48
55
  while (repeat && iterations < this.maxIterations) {
49
56
  repeat = false;
50
- operation = utils_algebra_1.algebraUtils.mapOperation(operation, {
51
- [utils_algebra_1.Algebra.Types.FILTER]: { transform: (filterOp) => {
52
- // Check if the filter must be pushed down
53
- const extensionFunctions = action.context.get(context_entries_1.KeysInitQuery.extensionFunctions);
54
- const extensionFunctionsAlwaysPushdown = action.context.get(context_entries_1.KeysInitQuery.extensionFunctionsAlwaysPushdown);
55
- if (!this.shouldAttemptPushDown(filterOp, sources, sourceShapes, extensionFunctions, extensionFunctionsAlwaysPushdown)) {
56
- return filterOp;
57
- }
58
- // For all filter expressions in the operation,
59
- // we attempt to push them down as deep as possible into the algebra.
60
- const variables = (0, utils_query_operation_1.getExpressionVariables)(filterOp.expression);
61
- const [isModified, result] = this
62
- .filterPushdown(filterOp.expression, variables, filterOp.input, algebraFactory, action.context);
63
- if (isModified) {
64
- repeat = true;
65
- }
66
- return result;
67
- } },
57
+ operation = sparqlalgebrajs_1.Util.mapOperation(operation, {
58
+ filter(op, factory) {
59
+ // Check if the filter must be pushed down
60
+ const extensionFunctions = action.context.get(context_entries_1.KeysInitQuery.extensionFunctions);
61
+ const extensionFunctionsAlwaysPushdown = action.context.get(context_entries_1.KeysInitQuery.extensionFunctionsAlwaysPushdown);
62
+ if (!self
63
+ .shouldAttemptPushDown(op, sources, sourceShapes, extensionFunctions, extensionFunctionsAlwaysPushdown)) {
64
+ return {
65
+ recurse: true,
66
+ result: op,
67
+ };
68
+ }
69
+ // For all filter expressions in the operation,
70
+ // we attempt to push them down as deep as possible into the algebra.
71
+ const variables = (0, utils_query_operation_1.getExpressionVariables)(op.expression);
72
+ const [isModified, result] = self
73
+ .filterPushdown(op.expression, variables, op.input, factory, action.context);
74
+ if (isModified) {
75
+ repeat = true;
76
+ }
77
+ return {
78
+ recurse: true,
79
+ result,
80
+ };
81
+ },
68
82
  });
69
83
  iterations++;
70
84
  }
71
85
  if (iterations > 1) {
72
- this.logDebug(action.context, `Pushed down filters in ${iterations} iterations`);
86
+ self.logDebug(action.context, `Pushed down filters in ${iterations} iterations`);
73
87
  }
74
88
  // Merge nested filters into conjunctive filters
75
89
  if (this.mergeConjunctive) {
76
- operation = utils_algebra_1.algebraUtils.mapOperation(operation, {
77
- [utils_algebra_1.Algebra.Types.FILTER]: { transform: (op) => {
78
- if (op.input.type === utils_algebra_1.Algebra.Types.FILTER) {
79
- const { nestedExpressions, input } = this.getNestedFilterExpressions(op);
80
- this.logDebug(action.context, `Merge ${nestedExpressions.length} nested filters into conjunctive filter`);
81
- return algebraFactory.createFilter(input, nestedExpressions.slice(1).reduce((previous, current) => algebraFactory.createOperatorExpression('&&', [previous, current]), nestedExpressions[0]));
82
- }
83
- return op;
84
- } },
90
+ operation = sparqlalgebrajs_1.Util.mapOperation(operation, {
91
+ filter(op, factory) {
92
+ if (op.input.type === sparqlalgebrajs_1.Algebra.types.FILTER) {
93
+ const { nestedExpressions, input } = self.getNestedFilterExpressions(op);
94
+ self.logDebug(action.context, `Merge ${nestedExpressions.length} nested filters into conjunctive filter`);
95
+ return {
96
+ recurse: true,
97
+ result: factory.createFilter(input, nestedExpressions.slice(1).reduce((previous, current) => factory.createOperatorExpression('&&', [previous, current]), nestedExpressions[0])),
98
+ };
99
+ }
100
+ return {
101
+ recurse: true,
102
+ result: op,
103
+ };
104
+ },
85
105
  });
86
106
  }
87
107
  return { operation, context: action.context };
@@ -107,19 +127,16 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
107
127
  }
108
128
  // Push down if the filter is extremely selective
109
129
  const expression = operation.expression;
110
- if ((0, utils_algebra_1.isKnownSubType)(expression, utils_algebra_1.Algebra.ExpressionTypes.OPERATOR) && expression.operator === '=' &&
111
- (((0, utils_algebra_1.isKnownSubType)(expression.args[0], utils_algebra_1.Algebra.ExpressionTypes.TERM) &&
112
- expression.args[0].term.termType !== 'Variable' &&
113
- (0, utils_algebra_1.isKnownSubType)(expression.args[1], utils_algebra_1.Algebra.ExpressionTypes.TERM) &&
114
- expression.args[1].term.termType === 'Variable') ||
115
- ((0, utils_algebra_1.isKnownSubType)(expression.args[0], utils_algebra_1.Algebra.ExpressionTypes.TERM) &&
116
- expression.args[0].term.termType === 'Variable' &&
117
- (0, utils_algebra_1.isKnownSubType)(expression.args[1], utils_algebra_1.Algebra.ExpressionTypes.TERM) &&
118
- expression.args[1].term.termType !== 'Variable'))) {
130
+ if (expression.expressionType === sparqlalgebrajs_1.Algebra.expressionTypes.OPERATOR &&
131
+ expression.operator === '=' &&
132
+ ((expression.args[0].expressionType === 'term' && expression.args[0].term.termType !== 'Variable' &&
133
+ expression.args[1].expressionType === 'term' && expression.args[1].term.termType === 'Variable') ||
134
+ (expression.args[0].expressionType === 'term' && expression.args[0].term.termType === 'Variable' &&
135
+ expression.args[1].expressionType === 'term' && expression.args[1].term.termType !== 'Variable'))) {
119
136
  return true;
120
137
  }
121
138
  // Don't push down extension functions comunica support, but no source does
122
- if (extensionFunctions && (0, utils_algebra_1.isKnownSubType)(expression, utils_algebra_1.Algebra.ExpressionTypes.NAMED) &&
139
+ if (extensionFunctions && expression.expressionType === sparqlalgebrajs_1.Algebra.expressionTypes.NAMED &&
123
140
  expression.name.value in extensionFunctions &&
124
141
  // Checks if there's not a single source that supports the extension function
125
142
  !sources.some(source => (0, utils_query_operation_1.doesShapeAcceptOperation)(sourceShapes.get(source), expression))) {
@@ -147,11 +164,11 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
147
164
  }
148
165
  return false;
149
166
  };
150
- utils_algebra_1.algebraUtils.visitOperation(operation, {
151
- [utils_algebra_1.Algebra.Types.PATTERN]: { visitor: sourceAdder },
152
- [utils_algebra_1.Algebra.Types.SERVICE]: { visitor: sourceAdder },
153
- [utils_algebra_1.Algebra.Types.LINK]: { visitor: sourceAdder },
154
- [utils_algebra_1.Algebra.Types.NPS]: { visitor: sourceAdder },
167
+ sparqlalgebrajs_1.Util.recurseOperation(operation, {
168
+ [sparqlalgebrajs_1.Algebra.types.PATTERN]: sourceAdder,
169
+ [sparqlalgebrajs_1.Algebra.types.LINK]: sourceAdder,
170
+ [sparqlalgebrajs_1.Algebra.types.NPS]: sourceAdder,
171
+ [sparqlalgebrajs_1.Algebra.types.SERVICE]: sourceAdder,
155
172
  });
156
173
  return [...sources];
157
174
  }
@@ -160,7 +177,7 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
160
177
  const partiallyOverlapping = [];
161
178
  const notOverlapping = [];
162
179
  for (const input of operation.input) {
163
- const inputVariables = utils_algebra_1.algebraUtils.inScopeVariables(input);
180
+ const inputVariables = sparqlalgebrajs_1.Util.inScopeVariables(input);
164
181
  if (this.variablesSubSetOf(expressionVariables, inputVariables)) {
165
182
  fullyOverlapping.push(input);
166
183
  }
@@ -196,154 +213,183 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
196
213
  return [true, factory.createUnion([])];
197
214
  }
198
215
  // Don't push down (NOT) EXISTS
199
- if ((0, utils_algebra_1.isKnownOperation)(expression, utils_algebra_1.Algebra.Types.EXPRESSION, utils_algebra_1.Algebra.ExpressionTypes.EXISTENCE)) {
216
+ if (expression.expressionType === sparqlalgebrajs_1.Algebra.expressionTypes.EXISTENCE) {
200
217
  return [false, factory.createFilter(operation, expression)];
201
218
  }
202
- if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.EXTEND)) {
203
- // Pass if the variable is not part of the expression
204
- if (!this.variablesIntersect([operation.variable], expressionVariables)) {
205
- return [true, factory.createExtend(this.filterPushdown(expression, expressionVariables, operation.input, factory, context)[1], operation.variable, operation.expression)];
206
- }
207
- return [false, factory.createFilter(operation, expression)];
208
- }
209
- if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.FILTER)) {
210
- // Always pass
211
- const [isModified, result] = this
212
- .filterPushdown(expression, expressionVariables, operation.input, factory, context);
213
- return [isModified, factory.createFilter(result, operation.expression)];
214
- }
215
- if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.JOIN)) {
216
- // Don't push down for empty join
217
- if (operation.input.length === 0) {
219
+ switch (operation.type) {
220
+ case sparqlalgebrajs_1.Algebra.types.EXTEND:
221
+ // Pass if the variable is not part of the expression
222
+ if (!this.variablesIntersect([operation.variable], expressionVariables)) {
223
+ return [true, factory.createExtend(this.filterPushdown(expression, expressionVariables, operation.input, factory, context)[1], operation.variable, operation.expression)];
224
+ }
218
225
  return [false, factory.createFilter(operation, expression)];
226
+ case sparqlalgebrajs_1.Algebra.types.FILTER: {
227
+ // Always pass
228
+ const [isModified, result] = this
229
+ .filterPushdown(expression, expressionVariables, operation.input, factory, context);
230
+ return [isModified, factory.createFilter(result, operation.expression)];
219
231
  }
220
- // Determine overlapping operations
221
- const { fullyOverlapping, partiallyOverlapping, notOverlapping, } = this.getOverlappingOperations(operation, expressionVariables);
222
- const joins = [];
223
- let isModified = false;
224
- if (fullyOverlapping.length > 0) {
225
- isModified = true;
226
- joins.push(factory.createJoin(fullyOverlapping
227
- .map(input => this.filterPushdown(expression, expressionVariables, input, factory, context)[1])));
228
- }
229
- if (partiallyOverlapping.length > 0) {
230
- joins.push(factory.createFilter(factory.createJoin(partiallyOverlapping, false), expression));
231
- }
232
- if (notOverlapping.length > 0) {
233
- joins.push(...notOverlapping);
234
- }
235
- if (joins.length > 1) {
236
- isModified = true;
237
- }
238
- if (isModified) {
239
- this.logDebug(context, `Push down filter across join entries with ${fullyOverlapping.length} fully overlapping, ${partiallyOverlapping.length} partially overlapping, and ${notOverlapping.length} not overlapping`);
240
- }
241
- return [isModified, joins.length === 1 ? joins[0] : factory.createJoin(joins)];
242
- }
243
- if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.NOP)) {
244
- return [true, operation];
245
- }
246
- if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.PROJECT)) {
247
- // Push down if variables overlap
248
- if (this.variablesIntersect(operation.variables, expressionVariables)) {
249
- return [true, factory.createProject(this.filterPushdown(expression, expressionVariables, operation.input, factory, context)[1], operation.variables)];
250
- }
251
- // Void expression otherwise
252
- return [true, operation];
253
- }
254
- if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.UNION)) {
255
- // Determine overlapping operations
256
- const { fullyOverlapping, partiallyOverlapping, notOverlapping, } = this.getOverlappingOperations(operation, expressionVariables);
257
- const unions = [];
258
- let isModified = false;
259
- if (fullyOverlapping.length > 0) {
260
- isModified = true;
261
- unions.push(factory.createUnion(fullyOverlapping
262
- .map(input => this.filterPushdown(expression, expressionVariables, input, factory, context)[1])));
263
- }
264
- if (partiallyOverlapping.length > 0) {
265
- unions.push(factory.createFilter(factory.createUnion(partiallyOverlapping, false), expression));
266
- }
267
- if (notOverlapping.length > 0) {
268
- unions.push(...notOverlapping);
269
- }
270
- if (unions.length > 1) {
271
- isModified = true;
232
+ case sparqlalgebrajs_1.Algebra.types.JOIN: {
233
+ // Don't push down for empty join
234
+ if (operation.input.length === 0) {
235
+ return [false, factory.createFilter(operation, expression)];
236
+ }
237
+ // Determine overlapping operations
238
+ const { fullyOverlapping, partiallyOverlapping, notOverlapping, } = this.getOverlappingOperations(operation, expressionVariables);
239
+ const joins = [];
240
+ let isModified = false;
241
+ if (fullyOverlapping.length > 0) {
242
+ isModified = true;
243
+ joins.push(factory.createJoin(fullyOverlapping
244
+ .map(input => this.filterPushdown(expression, expressionVariables, input, factory, context)[1])));
245
+ }
246
+ if (partiallyOverlapping.length > 0) {
247
+ joins.push(factory.createFilter(factory.createJoin(partiallyOverlapping, false), expression));
248
+ }
249
+ if (notOverlapping.length > 0) {
250
+ joins.push(...notOverlapping);
251
+ }
252
+ if (joins.length > 1) {
253
+ isModified = true;
254
+ }
255
+ if (isModified) {
256
+ this.logDebug(context, `Push down filter across join entries with ${fullyOverlapping.length} fully overlapping, ${partiallyOverlapping.length} partially overlapping, and ${notOverlapping.length} not overlapping`);
257
+ }
258
+ return [isModified, joins.length === 1 ? joins[0] : factory.createJoin(joins)];
272
259
  }
273
- if (isModified) {
274
- this.logDebug(context, `Push down filter across union entries with ${fullyOverlapping.length} fully overlapping, ${partiallyOverlapping.length} partially overlapping, and ${notOverlapping.length} not overlapping`);
260
+ case sparqlalgebrajs_1.Algebra.types.NOP:
261
+ return [true, operation];
262
+ case sparqlalgebrajs_1.Algebra.types.PROJECT:
263
+ // Push down if variables overlap
264
+ if (this.variablesIntersect(operation.variables, expressionVariables)) {
265
+ return [true, factory.createProject(this.filterPushdown(expression, expressionVariables, operation.input, factory, context)[1], operation.variables)];
266
+ }
267
+ // Void expression otherwise
268
+ return [true, operation];
269
+ case sparqlalgebrajs_1.Algebra.types.UNION: {
270
+ // Determine overlapping operations
271
+ const { fullyOverlapping, partiallyOverlapping, notOverlapping, } = this.getOverlappingOperations(operation, expressionVariables);
272
+ const unions = [];
273
+ let isModified = false;
274
+ if (fullyOverlapping.length > 0) {
275
+ isModified = true;
276
+ unions.push(factory.createUnion(fullyOverlapping
277
+ .map(input => this.filterPushdown(expression, expressionVariables, input, factory, context)[1])));
278
+ }
279
+ if (partiallyOverlapping.length > 0) {
280
+ unions.push(factory.createFilter(factory.createUnion(partiallyOverlapping, false), expression));
281
+ }
282
+ if (notOverlapping.length > 0) {
283
+ unions.push(...notOverlapping);
284
+ }
285
+ if (unions.length > 1) {
286
+ isModified = true;
287
+ }
288
+ if (isModified) {
289
+ this.logDebug(context, `Push down filter across union entries with ${fullyOverlapping.length} fully overlapping, ${partiallyOverlapping.length} partially overlapping, and ${notOverlapping.length} not overlapping`);
290
+ }
291
+ return [isModified, unions.length === 1 ? unions[0] : factory.createUnion(unions)];
275
292
  }
276
- return [isModified, unions.length === 1 ? unions[0] : factory.createUnion(unions)];
277
- }
278
- if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.VALUES)) {
279
- // Only keep filter if it overlaps with the variables
280
- if (this.variablesIntersect(operation.variables, expressionVariables)) {
293
+ case sparqlalgebrajs_1.Algebra.types.VALUES:
294
+ // Only keep filter if it overlaps with the variables
295
+ if (this.variablesIntersect(operation.variables, expressionVariables)) {
296
+ return [false, factory.createFilter(operation, expression)];
297
+ }
298
+ return [true, operation];
299
+ case sparqlalgebrajs_1.Algebra.types.LEFT_JOIN: {
300
+ if (this.pushIntoLeftJoins) {
301
+ const rightVariables = sparqlalgebrajs_1.Util.inScopeVariables(operation.input[1]);
302
+ if (!this.variablesIntersect(expressionVariables, rightVariables)) {
303
+ // If filter *only* applies to left entry of optional, push it down into that.
304
+ this.logDebug(context, `Push down filter into left join`);
305
+ return [true, factory.createLeftJoin(this.filterPushdown(expression, expressionVariables, operation.input[0], factory, context)[1], operation.input[1], operation.expression)];
306
+ }
307
+ }
308
+ // Don't push down in all other cases
281
309
  return [false, factory.createFilter(operation, expression)];
282
310
  }
283
- return [true, operation];
284
- }
285
- if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.LEFT_JOIN)) {
286
- if (this.pushIntoLeftJoins) {
287
- const rightVariables = utils_algebra_1.algebraUtils.inScopeVariables(operation.input[1]);
288
- if (!this.variablesIntersect(expressionVariables, rightVariables)) {
289
- // If filter *only* applies to left entry of optional, push it down into that.
290
- this.logDebug(context, `Push down filter into left join`);
291
- return [true, factory.createLeftJoin(this.filterPushdown(expression, expressionVariables, operation.input[0], factory, context)[1], operation.input[1], operation.expression)];
311
+ case sparqlalgebrajs_1.Algebra.types.PATTERN: {
312
+ if (this.pushEqualityIntoPatterns) {
313
+ // Try to push simple FILTER(?s = <iri>) expressions into the pattern
314
+ const pushableResult = this.getEqualityExpressionPushableIntoPattern(expression);
315
+ if (pushableResult) {
316
+ let isModified = false;
317
+ const originalMetadata = operation.metadata;
318
+ operation = (0, rdf_terms_1.mapTermsNested)(operation, (value) => {
319
+ if (value.equals(pushableResult.variable)) {
320
+ isModified = true;
321
+ return pushableResult.term;
322
+ }
323
+ return value;
324
+ });
325
+ operation.type = sparqlalgebrajs_1.Algebra.types.PATTERN;
326
+ operation.metadata = originalMetadata;
327
+ if (isModified) {
328
+ this.logDebug(context, `Push down filter into pattern for ?${pushableResult.variable.value}`);
329
+ return [true, factory.createJoin([
330
+ operation,
331
+ factory.createValues([pushableResult.variable], [{ [`?${pushableResult.variable.value}`]: pushableResult.term }]),
332
+ ])];
333
+ }
334
+ }
292
335
  }
336
+ // Don't push down in all other cases
337
+ return [false, factory.createFilter(operation, expression)];
293
338
  }
294
- // Don't push down in all other cases
295
- return [false, factory.createFilter(operation, expression)];
296
- }
297
- if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.PATTERN)) {
298
- if (this.pushEqualityIntoPatterns) {
299
- // Try to push simple FILTER(?s = <iri>) expressions into the pattern
300
- const pushableResult = this.getEqualityExpressionPushableIntoPattern(expression);
301
- if (pushableResult) {
302
- let isModified = false;
303
- const originalMetadata = operation.metadata;
304
- operation = (0, rdf_terms_1.mapTermsNested)(operation, (value) => {
305
- if (value.equals(pushableResult.variable)) {
306
- isModified = true;
307
- return pushableResult.term;
308
- }
309
- return value;
310
- });
311
- operation.type = utils_algebra_1.Algebra.Types.PATTERN;
312
- operation.metadata = originalMetadata;
313
- if (isModified) {
314
- this.logDebug(context, `Push down filter into pattern for ?${pushableResult.variable.value}`);
339
+ case sparqlalgebrajs_1.Algebra.types.PATH: {
340
+ if (this.pushEqualityIntoPatterns) {
341
+ // Try to push simple FILTER(?s = <iri>) expressions into the path
342
+ const pushableResult = this.getEqualityExpressionPushableIntoPattern(expression);
343
+ if (pushableResult &&
344
+ (operation.subject.equals(pushableResult.variable) || operation.object.equals(pushableResult.variable))) {
345
+ this.logDebug(context, `Push down filter into path for ?${pushableResult.variable.value}`);
346
+ const originalMetadata = operation.metadata;
347
+ operation = factory.createPath(operation.subject.equals(pushableResult.variable) ? pushableResult.term : operation.subject, operation.predicate, operation.object.equals(pushableResult.variable) ? pushableResult.term : operation.object);
348
+ operation.metadata = originalMetadata;
315
349
  return [true, factory.createJoin([
316
350
  operation,
317
- factory.createValues([pushableResult.variable], [{ [pushableResult.variable.value]: pushableResult.term }]),
351
+ factory.createValues([pushableResult.variable], [{ [`?${pushableResult.variable.value}`]: pushableResult.term }]),
318
352
  ])];
319
353
  }
320
354
  }
355
+ // Don't push down in all other cases
356
+ return [false, factory.createFilter(operation, expression)];
321
357
  }
322
- // Don't push down in all other cases
323
- return [false, factory.createFilter(operation, expression)];
324
- }
325
- if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.PATH)) {
326
- if (this.pushEqualityIntoPatterns) {
327
- // Try to push simple FILTER(?s = <iri>) expressions into the path
328
- const pushableResult = this.getEqualityExpressionPushableIntoPattern(expression);
329
- if (pushableResult &&
330
- (operation.subject.equals(pushableResult.variable) || operation.object.equals(pushableResult.variable))) {
331
- this.logDebug(context, `Push down filter into path for ?${pushableResult.variable.value}`);
332
- const originalMetadata = operation.metadata;
333
- operation = factory.createPath(operation.subject.equals(pushableResult.variable) ? pushableResult.term : operation.subject, operation.predicate, operation.object.equals(pushableResult.variable) ? pushableResult.term : operation.object);
334
- operation.metadata = originalMetadata;
335
- return [true, factory.createJoin([
336
- operation,
337
- factory.createValues([pushableResult.variable], [{ [pushableResult.variable.value]: pushableResult.term }]),
338
- ])];
339
- }
340
- }
341
- // Don't push down in all other cases
342
- return [false, factory.createFilter(operation, expression)];
358
+ case sparqlalgebrajs_1.Algebra.types.MINUS:
359
+ case sparqlalgebrajs_1.Algebra.types.ALT:
360
+ case sparqlalgebrajs_1.Algebra.types.ASK:
361
+ case sparqlalgebrajs_1.Algebra.types.BGP:
362
+ case sparqlalgebrajs_1.Algebra.types.CONSTRUCT:
363
+ case sparqlalgebrajs_1.Algebra.types.DESCRIBE:
364
+ case sparqlalgebrajs_1.Algebra.types.DISTINCT:
365
+ case sparqlalgebrajs_1.Algebra.types.EXPRESSION:
366
+ case sparqlalgebrajs_1.Algebra.types.FROM:
367
+ case sparqlalgebrajs_1.Algebra.types.GRAPH:
368
+ case sparqlalgebrajs_1.Algebra.types.GROUP:
369
+ case sparqlalgebrajs_1.Algebra.types.INV:
370
+ case sparqlalgebrajs_1.Algebra.types.LINK:
371
+ case sparqlalgebrajs_1.Algebra.types.NPS:
372
+ case sparqlalgebrajs_1.Algebra.types.ONE_OR_MORE_PATH:
373
+ case sparqlalgebrajs_1.Algebra.types.ORDER_BY:
374
+ case sparqlalgebrajs_1.Algebra.types.REDUCED:
375
+ case sparqlalgebrajs_1.Algebra.types.SEQ:
376
+ case sparqlalgebrajs_1.Algebra.types.SERVICE:
377
+ case sparqlalgebrajs_1.Algebra.types.SLICE:
378
+ case sparqlalgebrajs_1.Algebra.types.ZERO_OR_MORE_PATH:
379
+ case sparqlalgebrajs_1.Algebra.types.ZERO_OR_ONE_PATH:
380
+ case sparqlalgebrajs_1.Algebra.types.COMPOSITE_UPDATE:
381
+ case sparqlalgebrajs_1.Algebra.types.DELETE_INSERT:
382
+ case sparqlalgebrajs_1.Algebra.types.LOAD:
383
+ case sparqlalgebrajs_1.Algebra.types.CLEAR:
384
+ case sparqlalgebrajs_1.Algebra.types.CREATE:
385
+ case sparqlalgebrajs_1.Algebra.types.DROP:
386
+ case sparqlalgebrajs_1.Algebra.types.ADD:
387
+ case sparqlalgebrajs_1.Algebra.types.MOVE:
388
+ case sparqlalgebrajs_1.Algebra.types.COPY:
389
+ // Operations that do not support pushing down
390
+ // Left-join and minus might be possible to support in the future.
391
+ return [false, factory.createFilter(operation, expression)];
343
392
  }
344
- // Operations that do not support pushing down
345
- // Left-join and minus might be possible to support in the future.
346
- return [false, factory.createFilter(operation, expression)];
347
393
  }
348
394
  /**
349
395
  * Check if the given expression is a simple equals operation with one variable and one non-literal
@@ -352,24 +398,23 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
352
398
  * @return The variable and term to fill into the pattern, or undefined.
353
399
  */
354
400
  getEqualityExpressionPushableIntoPattern(expression) {
355
- if ((0, utils_algebra_1.isKnownSubType)(expression, utils_algebra_1.Algebra.ExpressionTypes.OPERATOR) && expression.operator === '=') {
356
- const arg0 = expression.args[0];
357
- const arg1 = expression.args[1];
358
- if ((0, utils_algebra_1.isKnownSubType)(arg0, utils_algebra_1.Algebra.ExpressionTypes.TERM) && arg0.term.termType !== 'Variable' &&
359
- (arg0.term.termType !== 'Literal' || this.isLiteralWithCanonicalLexicalForm(arg0.term)) &&
360
- (0, utils_algebra_1.isKnownSubType)(arg1, utils_algebra_1.Algebra.ExpressionTypes.TERM) &&
361
- arg1.term.termType === 'Variable') {
401
+ if (expression.expressionType === sparqlalgebrajs_1.Algebra.expressionTypes.OPERATOR && expression.operator === '=') {
402
+ if (expression.args[0].expressionType === 'term' && expression.args[0].term.termType !== 'Variable' &&
403
+ (expression.args[0].term.termType !== 'Literal' ||
404
+ this.isLiteralWithCanonicalLexicalForm(expression.args[0].term)) &&
405
+ expression.args[1].expressionType === 'term' && expression.args[1].term.termType === 'Variable') {
362
406
  return {
363
- variable: arg1.term,
364
- term: arg0.term,
407
+ variable: expression.args[1].term,
408
+ term: expression.args[0].term,
365
409
  };
366
410
  }
367
- if ((0, utils_algebra_1.isKnownSubType)(arg0, utils_algebra_1.Algebra.ExpressionTypes.TERM) && arg0.term.termType === 'Variable' &&
368
- (0, utils_algebra_1.isKnownSubType)(arg1, utils_algebra_1.Algebra.ExpressionTypes.TERM) && arg1.term.termType !== 'Variable' &&
369
- (arg1.term.termType !== 'Literal' || this.isLiteralWithCanonicalLexicalForm(arg1.term))) {
411
+ if (expression.args[0].expressionType === 'term' && expression.args[0].term.termType === 'Variable' &&
412
+ expression.args[1].expressionType === 'term' && expression.args[1].term.termType !== 'Variable' &&
413
+ (expression.args[1].term.termType !== 'Literal' ||
414
+ this.isLiteralWithCanonicalLexicalForm(expression.args[1].term))) {
370
415
  return {
371
- variable: arg0.term,
372
- term: arg1.term,
416
+ variable: expression.args[0].term,
417
+ term: expression.args[1].term,
373
418
  };
374
419
  }
375
420
  }
@@ -422,8 +467,7 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
422
467
  * @param expression An expression.
423
468
  */
424
469
  isExpressionFalse(expression) {
425
- const casted = expression;
426
- return (casted.term && casted.term.termType === 'Literal' && casted.term.value === 'false');
470
+ return (expression.term && expression.term.termType === 'Literal' && expression.term.value === 'false');
427
471
  }
428
472
  /**
429
473
  * Get all directly nested filter expressions.
@@ -431,7 +475,7 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
431
475
  * @param op A filter expression.
432
476
  */
433
477
  getNestedFilterExpressions(op) {
434
- if ((0, utils_algebra_1.isKnownOperation)(op.input, utils_algebra_1.Algebra.Types.FILTER)) {
478
+ if (op.input.type === sparqlalgebrajs_1.Algebra.types.FILTER) {
435
479
  const childData = this.getNestedFilterExpressions(op.input);
436
480
  return { nestedExpressions: [op.expression, ...childData.nestedExpressions], input: childData.input };
437
481
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ActorOptimizeQueryOperationFilterPushdown.js","sourceRoot":"","sources":["ActorOptimizeQueryOperationFilterPushdown.ts"],"names":[],"mappings":";;;AAKA,yFAAqF;AACrF,+DAA0D;AAE1D,yCAA8C;AAE9C,2DAMiC;AACjC,2EAAuH;AAEvH,yCAA2C;AAE3C;;GAEG;AACH,MAAa,yCAA0C,SAAQ,0DAA2B;IAQxF,YAAmB,IAAoD;QACrE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,CAAC,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED;;;OAGG;IACI,iBAAiB,CAAC,UAA8B;QACrD,MAAM,MAAM,GAA0D,UAAU,CAAC;QACjF,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC;IAC9F,CAAC;IAED;;;;OAIG;IACI,0BAA0B,CAC/B,EAAkB;QAElB,IAAI,IAAA,gCAAgB,EAAC,EAAE,CAAC,KAAK,EAAE,uBAAO,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;YACrD,MAAM,SAAS,GAAG,IAAI,CAAC,0BAA0B,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;YAC5D,OAAO,EAAE,iBAAiB,EAAE,CAAE,EAAE,CAAC,UAAU,EAAE,GAAG,SAAS,CAAC,iBAAiB,CAAE,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC;QAC1G,CAAC;QACD,OAAO,EAAE,iBAAiB,EAAE,CAAE,EAAE,CAAC,UAAU,CAAE,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC;IACnE,CAAC;CACF;AAvhBD,8FAuhBC","sourcesContent":["import type {\n IActionOptimizeQueryOperation,\n IActorOptimizeQueryOperationArgs,\n IActorOptimizeQueryOperationOutput,\n} from '@comunica/bus-optimize-query-operation';\nimport { ActorOptimizeQueryOperation } from '@comunica/bus-optimize-query-operation';\nimport { KeysInitQuery } from '@comunica/context-entries';\nimport type { IActorTest, TestResult } from '@comunica/core';\nimport { passTestVoid } from '@comunica/core';\nimport type { ComunicaDataFactory, FragmentSelectorShape, IActionContext, IQuerySourceWrapper } from '@comunica/types';\nimport {\n AlgebraFactory,\n Algebra,\n algebraUtils,\n isKnownOperation,\n isKnownSubType,\n} from '@comunica/utils-algebra';\nimport { doesShapeAcceptOperation, getExpressionVariables, getOperationSource } from '@comunica/utils-query-operation';\nimport type * as RDF from '@rdfjs/types';\nimport { mapTermsNested } from 'rdf-terms';\n\n/**\n * A comunica Filter Pushdown Optimize Query Operation Actor.\n */\nexport class ActorOptimizeQueryOperationFilterPushdown extends ActorOptimizeQueryOperation {\n private readonly aggressivePushdown: boolean;\n private readonly maxIterations: number;\n private readonly splitConjunctive: boolean;\n private readonly mergeConjunctive: boolean;\n private readonly pushIntoLeftJoins: boolean;\n private readonly pushEqualityIntoPatterns: boolean;\n\n public constructor(args: IActorOptimizeQueryOperationFilterPushdownArgs) {\n super(args);\n }\n\n public async test(_action: IActionOptimizeQueryOperation): Promise<TestResult<IActorTest>> {\n return passTestVoid();\n }\n\n public async run(action: IActionOptimizeQueryOperation): Promise<IActorOptimizeQueryOperationOutput> {\n const dataFactory: ComunicaDataFactory = action.context.getSafe(KeysInitQuery.dataFactory);\n const algebraFactory = new AlgebraFactory(dataFactory);\n let operation: Algebra.Operation = action.operation;\n\n // Split conjunctive filters into nested filters\n if (this.splitConjunctive) {\n operation = algebraUtils.mapOperation(operation, {\n [Algebra.Types.FILTER]: { transform: (filterOp) => {\n // Split conjunctive filters into separate filters\n if (isKnownSubType(filterOp.expression, Algebra.ExpressionTypes.OPERATOR) &&\n filterOp.expression.operator === '&&') {\n this.logDebug(action.context, `Split conjunctive filter into ${filterOp.expression.args.length} nested filters`);\n return filterOp.expression.args\n .reduce((operation, expression) => algebraFactory.createFilter(operation, expression), filterOp.input);\n }\n return filterOp;\n } },\n });\n }\n\n // Collect selector shapes of all operations\n const sources = this.getSources(operation);\n // eslint-disable-next-line ts/no-unnecessary-type-assertion\n const sourceShapes = new Map(<[IQuerySourceWrapper, FragmentSelectorShape][]> await Promise.all(sources\n .map(async source => [ source, await source.source.getSelectorShape(action.context) ])));\n\n // Push down all filters\n // We loop until no more filters can be pushed down.\n let repeat = true;\n let iterations = 0;\n while (repeat && iterations < this.maxIterations) {\n repeat = false;\n operation = algebraUtils.mapOperation(operation, {\n [Algebra.Types.FILTER]: { transform: (filterOp) => {\n // Check if the filter must be pushed down\n const extensionFunctions = action.context.get(KeysInitQuery.extensionFunctions);\n const extensionFunctionsAlwaysPushdown = action.context.get(KeysInitQuery.extensionFunctionsAlwaysPushdown);\n if (!this.shouldAttemptPushDown(\n filterOp,\n sources,\n sourceShapes,\n extensionFunctions,\n extensionFunctionsAlwaysPushdown,\n )) {\n return filterOp;\n }\n\n // For all filter expressions in the operation,\n // we attempt to push them down as deep as possible into the algebra.\n const variables = getExpressionVariables(filterOp.expression);\n const [ isModified, result ] = this\n .filterPushdown(filterOp.expression, variables, filterOp.input, algebraFactory, action.context);\n if (isModified) {\n repeat = true;\n }\n return result;\n } },\n });\n iterations++;\n }\n\n if (iterations > 1) {\n this.logDebug(action.context, `Pushed down filters in ${iterations} iterations`);\n }\n\n // Merge nested filters into conjunctive filters\n if (this.mergeConjunctive) {\n operation = algebraUtils.mapOperation(operation, {\n [Algebra.Types.FILTER]: { transform: (op) => {\n if (op.input.type === Algebra.Types.FILTER) {\n const { nestedExpressions, input } = this.getNestedFilterExpressions(op);\n this.logDebug(action.context, `Merge ${nestedExpressions.length} nested filters into conjunctive filter`);\n return algebraFactory.createFilter(\n input,\n nestedExpressions.slice(1).reduce((previous, current) =>\n algebraFactory.createOperatorExpression('&&', [ previous, current ]), nestedExpressions[0]),\n );\n }\n return op;\n } },\n });\n }\n\n return { operation, context: action.context };\n }\n\n /**\n * Check if the given filter operation must be attempted to push down, based on the following criteria:\n * - Always push down if aggressive mode is enabled\n * - Push down if the filter is extremely selective\n * - Don't push down extension functions comunica support, but a source does not\n * - Push down if federated and at least one accepts the filter\n * @param operation The filter operation\n * @param sources The query sources in the operation\n * @param sourceShapes A mapping of sources to selector shapes.\n * @param extensionFunctions The extension functions comunica supports.\n * @param extensionFunctionsAlwaysPushdown If extension functions must always be pushed down to sources that support\n * expressions, even if those sources to not explicitly declare support for\n * these extension functions.\n */\n public shouldAttemptPushDown(\n operation: Algebra.Filter,\n sources: IQuerySourceWrapper[],\n sourceShapes: Map<IQuerySourceWrapper, FragmentSelectorShape>,\n extensionFunctions?: Record<string, any>,\n extensionFunctionsAlwaysPushdown?: boolean,\n ): boolean {\n // Always push down if aggressive mode is enabled\n if (this.aggressivePushdown) {\n return true;\n }\n\n // Push down if the filter is extremely selective\n const expression = operation.expression;\n if (isKnownSubType(expression, Algebra.ExpressionTypes.OPERATOR) && expression.operator === '=' &&\n ((isKnownSubType(expression.args[0], Algebra.ExpressionTypes.TERM) &&\n expression.args[0].term.termType !== 'Variable' &&\n isKnownSubType(expression.args[1], Algebra.ExpressionTypes.TERM) &&\n expression.args[1].term.termType === 'Variable') ||\n (isKnownSubType(expression.args[0], Algebra.ExpressionTypes.TERM) &&\n expression.args[0].term.termType === 'Variable' &&\n isKnownSubType(expression.args[1], Algebra.ExpressionTypes.TERM) &&\n expression.args[1].term.termType !== 'Variable'))) {\n return true;\n }\n\n // Don't push down extension functions comunica support, but no source does\n if (extensionFunctions && isKnownSubType(expression, Algebra.ExpressionTypes.NAMED) &&\n expression.name.value in extensionFunctions &&\n // Checks if there's not a single source that supports the extension function\n !sources.some(source =>\n doesShapeAcceptOperation(sourceShapes.get(source)!, expression))\n ) {\n return false;\n }\n\n // Push down if federated and at least one accepts the filter\n if (sources.some(source => doesShapeAcceptOperation(sourceShapes.get(source)!, operation, {\n wildcardAcceptAllExtensionFunctions: extensionFunctionsAlwaysPushdown,\n }))) {\n return true;\n }\n\n // Don't push down in all other cases\n return false;\n }\n\n /**\n * Collected all sources that are defined within the given operation of children recursively.\n * @param operation An operation.\n */\n public getSources(operation: Algebra.Operation): IQuerySourceWrapper[] {\n const sources = new Set<IQuerySourceWrapper>();\n const sourceAdder = (subOperation: Algebra.Operation): boolean => {\n const src = getOperationSource(subOperation);\n if (src) {\n sources.add(src);\n }\n return false;\n };\n algebraUtils.visitOperation(operation, {\n [Algebra.Types.PATTERN]: { visitor: sourceAdder },\n [Algebra.Types.SERVICE]: { visitor: sourceAdder },\n [Algebra.Types.LINK]: { visitor: sourceAdder },\n [Algebra.Types.NPS]: { visitor: sourceAdder },\n });\n return [ ...sources ];\n }\n\n protected getOverlappingOperations(\n operation: Algebra.Union | Algebra.Join,\n expressionVariables: RDF.Variable[],\n ): {\n fullyOverlapping: Algebra.Operation[];\n partiallyOverlapping: Algebra.Operation[];\n notOverlapping: Algebra.Operation[];\n } {\n const fullyOverlapping: Algebra.Operation[] = [];\n const partiallyOverlapping: Algebra.Operation[] = [];\n const notOverlapping: Algebra.Operation[] = [];\n for (const input of operation.input) {\n const inputVariables = algebraUtils.inScopeVariables(input);\n if (this.variablesSubSetOf(expressionVariables, inputVariables)) {\n fullyOverlapping.push(input);\n } else if (this.variablesIntersect(expressionVariables, inputVariables)) {\n partiallyOverlapping.push(input);\n } else {\n notOverlapping.push(input);\n }\n }\n\n return {\n fullyOverlapping,\n partiallyOverlapping,\n notOverlapping,\n };\n }\n\n /**\n * Recursively push down the given expression into the given operation if possible.\n * Different operators have different semantics for choosing whether or not to push down,\n * and how this pushdown is done.\n * For every passed operator, it is checked whether or not the filter will have any effect on the operation.\n * If not, the filter is voided.\n * @param expression An expression to push down.\n * @param expressionVariables The variables inside the given expression.\n * @param operation The operation to push down into.\n * @param factory An algebra factory.\n * @param context The action context.\n * @return A tuple indicating if the operation was modified and the modified operation.\n */\n public filterPushdown(\n expression: Algebra.Expression,\n expressionVariables: RDF.Variable[],\n operation: Algebra.Operation,\n factory: AlgebraFactory,\n context: IActionContext,\n ): [ boolean, Algebra.Operation ] {\n // Void false expressions\n if (this.isExpressionFalse(expression)) {\n return [ true, factory.createUnion([]) ];\n }\n\n // Don't push down (NOT) EXISTS\n if (isKnownOperation(expression, Algebra.Types.EXPRESSION, Algebra.ExpressionTypes.EXISTENCE)) {\n return [ false, factory.createFilter(operation, expression) ];\n }\n\n if (isKnownOperation(operation, Algebra.Types.EXTEND)) {\n // Pass if the variable is not part of the expression\n if (!this.variablesIntersect([ operation.variable ], expressionVariables)) {\n return [ true, factory.createExtend(\n this.filterPushdown(expression, expressionVariables, operation.input, factory, context)[1],\n operation.variable,\n operation.expression,\n ) ];\n }\n return [ false, factory.createFilter(operation, expression) ];\n }\n if (isKnownOperation(operation, Algebra.Types.FILTER)) {\n // Always pass\n const [ isModified, result ] = this\n .filterPushdown(expression, expressionVariables, operation.input, factory, context);\n return [ isModified, factory.createFilter(result, operation.expression) ];\n }\n if (isKnownOperation(operation, Algebra.Types.JOIN)) {\n // Don't push down for empty join\n if (operation.input.length === 0) {\n return [ false, factory.createFilter(operation, expression) ];\n }\n\n // Determine overlapping operations\n const {\n fullyOverlapping,\n partiallyOverlapping,\n notOverlapping,\n } = this.getOverlappingOperations(operation, expressionVariables);\n\n const joins: Algebra.Operation[] = [];\n let isModified = false;\n if (fullyOverlapping.length > 0) {\n isModified = true;\n joins.push(factory.createJoin(fullyOverlapping\n .map(input => this.filterPushdown(expression, expressionVariables, input, factory, context)[1])));\n }\n if (partiallyOverlapping.length > 0) {\n joins.push(factory.createFilter(factory.createJoin(partiallyOverlapping, false), expression));\n }\n if (notOverlapping.length > 0) {\n joins.push(...notOverlapping);\n }\n\n if (joins.length > 1) {\n isModified = true;\n }\n\n if (isModified) {\n this.logDebug(context, `Push down filter across join entries with ${fullyOverlapping.length} fully overlapping, ${partiallyOverlapping.length} partially overlapping, and ${notOverlapping.length} not overlapping`);\n }\n\n return [ isModified, joins.length === 1 ? joins[0] : factory.createJoin(joins) ];\n }\n if (isKnownOperation(operation, Algebra.Types.NOP)) {\n return [ true, operation ];\n }\n if (isKnownOperation(operation, Algebra.Types.PROJECT)) {\n // Push down if variables overlap\n if (this.variablesIntersect(operation.variables, expressionVariables)) {\n return [ true, factory.createProject(\n this.filterPushdown(expression, expressionVariables, operation.input, factory, context)[1],\n operation.variables,\n ) ];\n }\n // Void expression otherwise\n return [ true, operation ];\n }\n if (isKnownOperation(operation, Algebra.Types.UNION)) {\n // Determine overlapping operations\n const {\n fullyOverlapping,\n partiallyOverlapping,\n notOverlapping,\n } = this.getOverlappingOperations(operation, expressionVariables);\n\n const unions: Algebra.Operation[] = [];\n let isModified = false;\n if (fullyOverlapping.length > 0) {\n isModified = true;\n unions.push(factory.createUnion(fullyOverlapping\n .map(input => this.filterPushdown(expression, expressionVariables, input, factory, context)[1])));\n }\n if (partiallyOverlapping.length > 0) {\n unions.push(factory.createFilter(factory.createUnion(partiallyOverlapping, false), expression));\n }\n if (notOverlapping.length > 0) {\n unions.push(...notOverlapping);\n }\n\n if (unions.length > 1) {\n isModified = true;\n }\n\n if (isModified) {\n this.logDebug(context, `Push down filter across union entries with ${fullyOverlapping.length} fully overlapping, ${partiallyOverlapping.length} partially overlapping, and ${notOverlapping.length} not overlapping`);\n }\n\n return [ isModified, unions.length === 1 ? unions[0] : factory.createUnion(unions) ];\n }\n if (isKnownOperation(operation, Algebra.Types.VALUES)) {\n // Only keep filter if it overlaps with the variables\n if (this.variablesIntersect(operation.variables, expressionVariables)) {\n return [ false, factory.createFilter(operation, expression) ];\n }\n return [ true, operation ];\n }\n if (isKnownOperation(operation, Algebra.Types.LEFT_JOIN)) {\n if (this.pushIntoLeftJoins) {\n const rightVariables = algebraUtils.inScopeVariables(operation.input[1]);\n if (!this.variablesIntersect(expressionVariables, rightVariables)) {\n // If filter *only* applies to left entry of optional, push it down into that.\n this.logDebug(context, `Push down filter into left join`);\n return [ true, factory.createLeftJoin(\n this.filterPushdown(expression, expressionVariables, operation.input[0], factory, context)[1],\n operation.input[1],\n operation.expression,\n ) ];\n }\n }\n\n // Don't push down in all other cases\n return [ false, factory.createFilter(operation, expression) ];\n }\n if (isKnownOperation(operation, Algebra.Types.PATTERN)) {\n if (this.pushEqualityIntoPatterns) {\n // Try to push simple FILTER(?s = <iri>) expressions into the pattern\n const pushableResult = this.getEqualityExpressionPushableIntoPattern(expression);\n if (pushableResult) {\n let isModified = false;\n const originalMetadata = operation.metadata;\n operation = mapTermsNested(operation, (value) => {\n if (value.equals(pushableResult.variable)) {\n isModified = true;\n return pushableResult.term;\n }\n return value;\n });\n operation.type = Algebra.Types.PATTERN;\n operation.metadata = originalMetadata;\n if (isModified) {\n this.logDebug(context, `Push down filter into pattern for ?${pushableResult.variable.value}`);\n return [ true, factory.createJoin([\n operation,\n factory.createValues(\n [ pushableResult.variable ],\n [{ [pushableResult.variable.value]: <RDF.NamedNode | RDF.Literal> pushableResult.term }],\n ),\n ]) ];\n }\n }\n }\n\n // Don't push down in all other cases\n return [ false, factory.createFilter(operation, expression) ];\n }\n if (isKnownOperation(operation, Algebra.Types.PATH)) {\n if (this.pushEqualityIntoPatterns) {\n // Try to push simple FILTER(?s = <iri>) expressions into the path\n const pushableResult = this.getEqualityExpressionPushableIntoPattern(expression);\n if (pushableResult &&\n (operation.subject.equals(pushableResult.variable) || operation.object.equals(pushableResult.variable))) {\n this.logDebug(context, `Push down filter into path for ?${pushableResult.variable.value}`);\n const originalMetadata = operation.metadata;\n operation = factory.createPath(\n operation.subject.equals(pushableResult.variable) ? pushableResult.term : operation.subject,\n operation.predicate,\n operation.object.equals(pushableResult.variable) ? pushableResult.term : operation.object,\n );\n operation.metadata = originalMetadata;\n return [ true, factory.createJoin([\n operation,\n factory.createValues(\n [ pushableResult.variable ],\n [{ [pushableResult.variable.value]: <RDF.NamedNode | RDF.Literal> pushableResult.term }],\n ),\n ]) ];\n }\n }\n\n // Don't push down in all other cases\n return [ false, factory.createFilter(operation, expression) ];\n }\n\n // Operations that do not support pushing down\n // Left-join and minus might be possible to support in the future.\n return [ false, factory.createFilter(operation, expression) ];\n }\n\n /**\n * Check if the given expression is a simple equals operation with one variable and one non-literal\n * (or literal with canonical lexical form) term that can be pushed into a pattern.\n * @param expression The current expression.\n * @return The variable and term to fill into the pattern, or undefined.\n */\n public getEqualityExpressionPushableIntoPattern(\n expression: Algebra.Expression,\n ): { variable: RDF.Variable; term: RDF.Term } | undefined {\n if (isKnownSubType(expression, Algebra.ExpressionTypes.OPERATOR) && expression.operator === '=') {\n const arg0 = expression.args[0];\n const arg1 = expression.args[1];\n if (isKnownSubType(arg0, Algebra.ExpressionTypes.TERM) && arg0.term.termType !== 'Variable' &&\n (arg0.term.termType !== 'Literal' || this.isLiteralWithCanonicalLexicalForm(arg0.term)) &&\n isKnownSubType(arg1, Algebra.ExpressionTypes.TERM) &&\n arg1.term.termType === 'Variable') {\n return {\n variable: arg1.term,\n term: arg0.term,\n };\n }\n if (isKnownSubType(arg0, Algebra.ExpressionTypes.TERM) && arg0.term.termType === 'Variable' &&\n isKnownSubType(arg1, Algebra.ExpressionTypes.TERM) && arg1.term.termType !== 'Variable' &&\n (arg1.term.termType !== 'Literal' || this.isLiteralWithCanonicalLexicalForm(arg1.term))) {\n return {\n variable: arg0.term,\n term: arg1.term,\n };\n }\n }\n }\n\n /**\n * Check if the given term is a literal with datatype that where all values\n * can only have one possible lexical representation.\n * In other words, no variants of values exist that should be considered equal.\n * For example: \"01\"^xsd:number and \"1\"^xsd:number will return false.\n * @param term An RDF term.\n * @protected\n */\n protected isLiteralWithCanonicalLexicalForm(term: RDF.Literal): boolean {\n switch (term.datatype.value) {\n case 'http://www.w3.org/2001/XMLSchema#string':\n case 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString':\n case 'http://www.w3.org/2001/XMLSchema#normalizedString':\n case 'http://www.w3.org/2001/XMLSchema#anyURI':\n case 'http://www.w3.org/2001/XMLSchema#base64Binary':\n case 'http://www.w3.org/2001/XMLSchema#language':\n case 'http://www.w3.org/2001/XMLSchema#Name':\n case 'http://www.w3.org/2001/XMLSchema#NCName':\n case 'http://www.w3.org/2001/XMLSchema#NMTOKEN':\n case 'http://www.w3.org/2001/XMLSchema#token':\n case 'http://www.w3.org/2001/XMLSchema#hexBinary':\n return true;\n }\n return false;\n }\n\n /**\n * Check if there is an overlap between the two given lists of variables.\n * @param varsA A list of variables.\n * @param varsB A list of variables.\n */\n public variablesIntersect(varsA: RDF.Variable[], varsB: RDF.Variable[]): boolean {\n return varsA.some(varA => varsB.some(varB => varA.equals(varB)));\n }\n\n /**\n * Check if all variables from the first list are included in the second list.\n * The second list may contain other variables as well.\n * @param varsNeedles A list of variables to search for.\n * @param varsHaystack A list of variables to search in.\n */\n public variablesSubSetOf(varsNeedles: RDF.Variable[], varsHaystack: RDF.Variable[]): boolean {\n return varsNeedles.length <= varsHaystack.length &&\n varsNeedles.every(varA => varsHaystack.some(varB => varA.equals(varB)));\n }\n\n /**\n * Check if an expression is simply 'false'.\n * @param expression An expression.\n */\n public isExpressionFalse(expression: Algebra.Expression): boolean {\n const casted = <Extract<Algebra.KnownExpression, { term?: unknown }>> expression;\n return (casted.term && casted.term.termType === 'Literal' && casted.term.value === 'false');\n }\n\n /**\n * Get all directly nested filter expressions.\n * As soon as a non-filter is found, it is returned as the input field.\n * @param op A filter expression.\n */\n public getNestedFilterExpressions(\n op: Algebra.Filter,\n ): { nestedExpressions: Algebra.Expression[]; input: Algebra.Operation } {\n if (isKnownOperation(op.input, Algebra.Types.FILTER)) {\n const childData = this.getNestedFilterExpressions(op.input);\n return { nestedExpressions: [ op.expression, ...childData.nestedExpressions ], input: childData.input };\n }\n return { nestedExpressions: [ op.expression ], input: op.input };\n }\n}\n\nexport interface IActorOptimizeQueryOperationFilterPushdownArgs extends IActorOptimizeQueryOperationArgs {\n /**\n * If filters should be pushed down as deep as possible.\n * If false, filters will only be pushed down if the source(s) accept them,\n * or if the filter is very selective.\n * @range {boolean}\n * @default {false}\n */\n aggressivePushdown: boolean;\n /**\n * The maximum number of full iterations across the query can be done for attempting to push down filters.\n * @default {10}\n */\n maxIterations: number;\n /**\n * If conjunctive filters should be split into nested filters before applying filter pushdown.\n * This can enable pushing down deeper.\n * @range {boolean}\n * @default {true}\n */\n splitConjunctive: boolean;\n /**\n * If nested filters should be merged into conjunctive filters after applying filter pushdown.\n * @range {boolean}\n * @default {true}\n */\n mergeConjunctive: boolean;\n /**\n * If filters should be pushed into left-joins.\n * @range {boolean}\n * @default {true}\n */\n pushIntoLeftJoins: boolean;\n /**\n * If simple equality filters should be pushed into patterns and paths.\n * This only applies to equality filters with terms that are not literals that have no canonical lexical form.\n * @range {boolean}\n * @default {true}\n */\n pushEqualityIntoPatterns: boolean;\n}\n"]}
1
+ {"version":3,"file":"ActorOptimizeQueryOperationFilterPushdown.js","sourceRoot":"","sources":["ActorOptimizeQueryOperationFilterPushdown.ts"],"names":[],"mappings":";;;AAKA,yFAAqF;AACrF,+DAA0D;AAE1D,yCAA8C;AAO9C,2EAIyC;AAEzC,yCAA2C;AAC3C,qDAAyD;AAEzD;;GAEG;AACH,MAAa,yCAA0C,SAAQ,0DAA2B;IAQxF,YAAmB,IAAoD;QACrE,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,OAAsC;QACtD,OAAO,IAAA,mBAAY,GAAE,CAAC;IACxB,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,MAAqC;QACpD,MAAM,WAAW,GAAwB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,+BAAa,CAAC,WAAW,CAAC,CAAC;QAC3F,MAAM,cAAc,GAAG,IAAI,yBAAO,CAAC,WAAW,CAAC,CAAC;QAChD,IAAI,SAAS,GAAsB,MAAM,CAAC,SAAS,CAAC;QAEpD,4CAA4C;QAC5C,MAAM,IAAI,GAAG,IAAI,CAAC;QAElB,gDAAgD;QAChD,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC1B,SAAS,GAAG,sBAAI,CAAC,YAAY,CAAC,SAAS,EAAE;gBACvC,MAAM,CAAC,EAAkB,EAAE,OAAgB;oBACzC,kDAAkD;oBAClD,IAAI,EAAE,CAAC,UAAU,CAAC,cAAc,KAAK,yBAAO,CAAC,eAAe,CAAC,QAAQ,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;wBACzG,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AAE,CAAE,EAAE,CAAC,UAAU,CAAE,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC;IACnE,CAAC;CACF;AA7jBD,8FA6jBC","sourcesContent":["import type {\n IActionOptimizeQueryOperation,\n IActorOptimizeQueryOperationArgs,\n IActorOptimizeQueryOperationOutput,\n} from '@comunica/bus-optimize-query-operation';\nimport { ActorOptimizeQueryOperation } from '@comunica/bus-optimize-query-operation';\nimport { KeysInitQuery } from '@comunica/context-entries';\nimport type { IActorTest, TestResult } from '@comunica/core';\nimport { passTestVoid } from '@comunica/core';\nimport type {\n ComunicaDataFactory,\n FragmentSelectorShape,\n IActionContext,\n IQuerySourceWrapper,\n} from '@comunica/types';\nimport {\n doesShapeAcceptOperation,\n getExpressionVariables,\n getOperationSource,\n} from '@comunica/utils-query-operation';\nimport type * as RDF from '@rdfjs/types';\nimport { mapTermsNested } from 'rdf-terms';\nimport { Factory, Algebra, Util } from 'sparqlalgebrajs';\n\n/**\n * A comunica Filter Pushdown Optimize Query Operation Actor.\n */\nexport class ActorOptimizeQueryOperationFilterPushdown extends ActorOptimizeQueryOperation {\n private readonly aggressivePushdown: boolean;\n private readonly maxIterations: number;\n private readonly splitConjunctive: boolean;\n private readonly mergeConjunctive: boolean;\n private readonly pushIntoLeftJoins: boolean;\n private readonly pushEqualityIntoPatterns: boolean;\n\n public constructor(args: IActorOptimizeQueryOperationFilterPushdownArgs) {\n super(args);\n }\n\n public async test(_action: IActionOptimizeQueryOperation): Promise<TestResult<IActorTest>> {\n return passTestVoid();\n }\n\n public async run(action: IActionOptimizeQueryOperation): Promise<IActorOptimizeQueryOperationOutput> {\n const dataFactory: ComunicaDataFactory = action.context.getSafe(KeysInitQuery.dataFactory);\n const algebraFactory = new Factory(dataFactory);\n let operation: Algebra.Operation = action.operation;\n\n // eslint-disable-next-line ts/no-this-alias\n const self = this;\n\n // Split conjunctive filters into nested filters\n if (this.splitConjunctive) {\n operation = Util.mapOperation(operation, {\n filter(op: Algebra.Filter, factory: Factory) {\n // Split conjunctive filters into separate filters\n if (op.expression.expressionType === Algebra.expressionTypes.OPERATOR && op.expression.operator === '&&') {\n self.logDebug(action.context, `Split conjunctive filter into ${op.expression.args.length} nested filters`);\n return {\n recurse: true,\n result: op.expression.args\n .reduce((operation, expression) => factory.createFilter(operation, expression), op.input),\n };\n }\n return {\n recurse: true,\n result: op,\n };\n },\n }, algebraFactory);\n }\n\n // Collect selector shapes of all operations\n const sources = this.getSources(operation);\n // eslint-disable-next-line ts/no-unnecessary-type-assertion\n const sourceShapes = new Map(<[IQuerySourceWrapper, FragmentSelectorShape][]> await Promise.all(sources\n .map(async source => [ source, await source.source.getSelectorShape(action.context) ])));\n\n // Push down all filters\n // We loop until no more filters can be pushed down.\n let repeat = true;\n let iterations = 0;\n while (repeat && iterations < this.maxIterations) {\n repeat = false;\n operation = Util.mapOperation(operation, {\n filter(op: Algebra.Filter, factory: Factory) {\n // Check if the filter must be pushed down\n const extensionFunctions = action.context.get(KeysInitQuery.extensionFunctions);\n const extensionFunctionsAlwaysPushdown = action.context.get(KeysInitQuery.extensionFunctionsAlwaysPushdown);\n if (!self\n .shouldAttemptPushDown(op, sources, sourceShapes, extensionFunctions, extensionFunctionsAlwaysPushdown)) {\n return {\n recurse: true,\n result: op,\n };\n }\n\n // For all filter expressions in the operation,\n // we attempt to push them down as deep as possible into the algebra.\n const variables = getExpressionVariables(op.expression);\n const [ isModified, result ] = self\n .filterPushdown(op.expression, variables, op.input, factory, action.context);\n if (isModified) {\n repeat = true;\n }\n return {\n recurse: true,\n result,\n };\n },\n });\n iterations++;\n }\n\n if (iterations > 1) {\n self.logDebug(action.context, `Pushed down filters in ${iterations} iterations`);\n }\n\n // Merge nested filters into conjunctive filters\n if (this.mergeConjunctive) {\n operation = Util.mapOperation(operation, {\n filter(op: Algebra.Filter, factory: Factory) {\n if (op.input.type === Algebra.types.FILTER) {\n const { nestedExpressions, input } = self.getNestedFilterExpressions(op);\n self.logDebug(action.context, `Merge ${nestedExpressions.length} nested filters into conjunctive filter`);\n return {\n recurse: true,\n result: factory.createFilter(\n input,\n nestedExpressions.slice(1).reduce((previous, current) =>\n factory.createOperatorExpression('&&', [ previous, current ]), nestedExpressions[0]),\n ),\n };\n }\n return {\n recurse: true,\n result: op,\n };\n },\n });\n }\n\n return { operation, context: action.context };\n }\n\n /**\n * Check if the given filter operation must be attempted to push down, based on the following criteria:\n * - Always push down if aggressive mode is enabled\n * - Push down if the filter is extremely selective\n * - Don't push down extension functions comunica support, but a source does not\n * - Push down if federated and at least one accepts the filter\n * @param operation The filter operation\n * @param sources The query sources in the operation\n * @param sourceShapes A mapping of sources to selector shapes.\n * @param extensionFunctions The extension functions comunica supports.\n * @param extensionFunctionsAlwaysPushdown If extension functions must always be pushed down to sources that support\n * expressions, even if those sources to not explicitly declare support for\n * these extension functions.\n */\n public shouldAttemptPushDown(\n operation: Algebra.Filter,\n sources: IQuerySourceWrapper[],\n sourceShapes: Map<IQuerySourceWrapper, FragmentSelectorShape>,\n extensionFunctions?: Record<string, any>,\n extensionFunctionsAlwaysPushdown?: boolean,\n ): boolean {\n // Always push down if aggressive mode is enabled\n if (this.aggressivePushdown) {\n return true;\n }\n\n // Push down if the filter is extremely selective\n const expression = operation.expression;\n if (expression.expressionType === Algebra.expressionTypes.OPERATOR &&\n expression.operator === '=' &&\n ((expression.args[0].expressionType === 'term' && expression.args[0].term.termType !== 'Variable' &&\n expression.args[1].expressionType === 'term' && expression.args[1].term.termType === 'Variable') ||\n (expression.args[0].expressionType === 'term' && expression.args[0].term.termType === 'Variable' &&\n expression.args[1].expressionType === 'term' && expression.args[1].term.termType !== 'Variable'))) {\n return true;\n }\n\n // Don't push down extension functions comunica support, but no source does\n if (extensionFunctions && expression.expressionType === Algebra.expressionTypes.NAMED &&\n expression.name.value in extensionFunctions &&\n // Checks if there's not a single source that supports the extension function\n !sources.some(source =>\n doesShapeAcceptOperation(sourceShapes.get(source)!, expression))\n ) {\n return false;\n }\n\n // Push down if federated and at least one accepts the filter\n if (sources.some(source => doesShapeAcceptOperation(sourceShapes.get(source)!, operation, {\n wildcardAcceptAllExtensionFunctions: extensionFunctionsAlwaysPushdown,\n }))) {\n return true;\n }\n\n // Don't push down in all other cases\n return false;\n }\n\n /**\n * Collected all sources that are defined within the given operation of children recursively.\n * @param operation An operation.\n */\n public getSources(operation: Algebra.Operation): IQuerySourceWrapper[] {\n const sources = new Set<IQuerySourceWrapper>();\n const sourceAdder = (subOperation: Algebra.Operation): boolean => {\n const src = getOperationSource(subOperation);\n if (src) {\n sources.add(src);\n }\n return false;\n };\n Util.recurseOperation(operation, {\n [Algebra.types.PATTERN]: sourceAdder,\n [Algebra.types.LINK]: sourceAdder,\n [Algebra.types.NPS]: sourceAdder,\n [Algebra.types.SERVICE]: sourceAdder,\n });\n return [ ...sources ];\n }\n\n protected getOverlappingOperations(\n operation: Algebra.Operation,\n expressionVariables: RDF.Variable[],\n ): {\n fullyOverlapping: Algebra.Operation[];\n partiallyOverlapping: Algebra.Operation[];\n notOverlapping: Algebra.Operation[];\n } {\n const fullyOverlapping: Algebra.Operation[] = [];\n const partiallyOverlapping: Algebra.Operation[] = [];\n const notOverlapping: Algebra.Operation[] = [];\n for (const input of operation.input) {\n const inputVariables = Util.inScopeVariables(input);\n if (this.variablesSubSetOf(expressionVariables, inputVariables)) {\n fullyOverlapping.push(input);\n } else if (this.variablesIntersect(expressionVariables, inputVariables)) {\n partiallyOverlapping.push(input);\n } else {\n notOverlapping.push(input);\n }\n }\n\n return {\n fullyOverlapping,\n partiallyOverlapping,\n notOverlapping,\n };\n }\n\n /**\n * Recursively push down the given expression into the given operation if possible.\n * Different operators have different semantics for choosing whether or not to push down,\n * and how this pushdown is done.\n * For every passed operator, it is checked whether or not the filter will have any effect on the operation.\n * If not, the filter is voided.\n * @param expression An expression to push down.\n * @param expressionVariables The variables inside the given expression.\n * @param operation The operation to push down into.\n * @param factory An algebra factory.\n * @param context The action context.\n * @return A tuple indicating if the operation was modified and the modified operation.\n */\n public filterPushdown(\n expression: Algebra.Expression,\n expressionVariables: RDF.Variable[],\n operation: Algebra.Operation,\n factory: Factory,\n context: IActionContext,\n ): [ boolean, Algebra.Operation ] {\n // Void false expressions\n if (this.isExpressionFalse(expression)) {\n return [ true, factory.createUnion([]) ];\n }\n\n // Don't push down (NOT) EXISTS\n if (expression.expressionType === Algebra.expressionTypes.EXISTENCE) {\n return [ false, factory.createFilter(operation, expression) ];\n }\n\n switch (operation.type) {\n case Algebra.types.EXTEND:\n // Pass if the variable is not part of the expression\n if (!this.variablesIntersect([ operation.variable ], expressionVariables)) {\n return [ true, factory.createExtend(\n this.filterPushdown(expression, expressionVariables, operation.input, factory, context)[1],\n operation.variable,\n operation.expression,\n ) ];\n }\n return [ false, factory.createFilter(operation, expression) ];\n case Algebra.types.FILTER: {\n // Always pass\n const [ isModified, result ] = this\n .filterPushdown(expression, expressionVariables, operation.input, factory, context);\n return [ isModified, factory.createFilter(result, operation.expression) ];\n }\n case Algebra.types.JOIN: {\n // Don't push down for empty join\n if (operation.input.length === 0) {\n return [ false, factory.createFilter(operation, expression) ];\n }\n\n // Determine overlapping operations\n const {\n fullyOverlapping,\n partiallyOverlapping,\n notOverlapping,\n } = this.getOverlappingOperations(operation, expressionVariables);\n\n const joins: Algebra.Operation[] = [];\n let isModified = false;\n if (fullyOverlapping.length > 0) {\n isModified = true;\n joins.push(factory.createJoin(fullyOverlapping\n .map(input => this.filterPushdown(expression, expressionVariables, input, factory, context)[1])));\n }\n if (partiallyOverlapping.length > 0) {\n joins.push(factory.createFilter(factory.createJoin(partiallyOverlapping, false), expression));\n }\n if (notOverlapping.length > 0) {\n joins.push(...notOverlapping);\n }\n\n if (joins.length > 1) {\n isModified = true;\n }\n\n if (isModified) {\n this.logDebug(context, `Push down filter across join entries with ${fullyOverlapping.length} fully overlapping, ${partiallyOverlapping.length} partially overlapping, and ${notOverlapping.length} not overlapping`);\n }\n\n return [ isModified, joins.length === 1 ? joins[0] : factory.createJoin(joins) ];\n }\n case Algebra.types.NOP:\n return [ true, operation ];\n case Algebra.types.PROJECT:\n // Push down if variables overlap\n if (this.variablesIntersect(operation.variables, expressionVariables)) {\n return [ true, factory.createProject(\n this.filterPushdown(expression, expressionVariables, operation.input, factory, context)[1],\n operation.variables,\n ) ];\n }\n // Void expression otherwise\n return [ true, operation ];\n case Algebra.types.UNION: {\n // Determine overlapping operations\n const {\n fullyOverlapping,\n partiallyOverlapping,\n notOverlapping,\n } = this.getOverlappingOperations(operation, expressionVariables);\n\n const unions: Algebra.Operation[] = [];\n let isModified = false;\n if (fullyOverlapping.length > 0) {\n isModified = true;\n unions.push(factory.createUnion(fullyOverlapping\n .map(input => this.filterPushdown(expression, expressionVariables, input, factory, context)[1])));\n }\n if (partiallyOverlapping.length > 0) {\n unions.push(factory.createFilter(factory.createUnion(partiallyOverlapping, false), expression));\n }\n if (notOverlapping.length > 0) {\n unions.push(...notOverlapping);\n }\n\n if (unions.length > 1) {\n isModified = true;\n }\n\n if (isModified) {\n this.logDebug(context, `Push down filter across union entries with ${fullyOverlapping.length} fully overlapping, ${partiallyOverlapping.length} partially overlapping, and ${notOverlapping.length} not overlapping`);\n }\n\n return [ isModified, unions.length === 1 ? unions[0] : factory.createUnion(unions) ];\n }\n case Algebra.types.VALUES:\n // Only keep filter if it overlaps with the variables\n if (this.variablesIntersect(operation.variables, expressionVariables)) {\n return [ false, factory.createFilter(operation, expression) ];\n }\n return [ true, operation ];\n case Algebra.types.LEFT_JOIN: {\n if (this.pushIntoLeftJoins) {\n const rightVariables = Util.inScopeVariables(operation.input[1]);\n if (!this.variablesIntersect(expressionVariables, rightVariables)) {\n // If filter *only* applies to left entry of optional, push it down into that.\n this.logDebug(context, `Push down filter into left join`);\n return [ true, factory.createLeftJoin(\n this.filterPushdown(expression, expressionVariables, operation.input[0], factory, context)[1],\n operation.input[1],\n operation.expression,\n ) ];\n }\n }\n\n // Don't push down in all other cases\n return [ false, factory.createFilter(operation, expression) ];\n }\n case Algebra.types.PATTERN: {\n if (this.pushEqualityIntoPatterns) {\n // Try to push simple FILTER(?s = <iri>) expressions into the pattern\n const pushableResult = this.getEqualityExpressionPushableIntoPattern(expression);\n if (pushableResult) {\n let isModified = false;\n const originalMetadata = operation.metadata;\n operation = mapTermsNested(operation, (value) => {\n if (value.equals(pushableResult.variable)) {\n isModified = true;\n return pushableResult.term;\n }\n return value;\n });\n operation.type = Algebra.types.PATTERN;\n operation.metadata = originalMetadata;\n if (isModified) {\n this.logDebug(context, `Push down filter into pattern for ?${pushableResult.variable.value}`);\n return [ true, factory.createJoin([\n operation,\n factory.createValues(\n [ pushableResult.variable ],\n [{ [`?${pushableResult.variable.value}`]: <RDF.NamedNode | RDF.Literal> pushableResult.term }],\n ),\n ]) ];\n }\n }\n }\n\n // Don't push down in all other cases\n return [ false, factory.createFilter(operation, expression) ];\n }\n case Algebra.types.PATH: {\n if (this.pushEqualityIntoPatterns) {\n // Try to push simple FILTER(?s = <iri>) expressions into the path\n const pushableResult = this.getEqualityExpressionPushableIntoPattern(expression);\n if (pushableResult &&\n (operation.subject.equals(pushableResult.variable) || operation.object.equals(pushableResult.variable))) {\n this.logDebug(context, `Push down filter into path for ?${pushableResult.variable.value}`);\n const originalMetadata = operation.metadata;\n operation = factory.createPath(\n operation.subject.equals(pushableResult.variable) ? pushableResult.term : operation.subject,\n operation.predicate,\n operation.object.equals(pushableResult.variable) ? pushableResult.term : operation.object,\n );\n operation.metadata = originalMetadata;\n return [ true, factory.createJoin([\n operation,\n factory.createValues(\n [ pushableResult.variable ],\n [{ [`?${pushableResult.variable.value}`]: <RDF.NamedNode | RDF.Literal> pushableResult.term }],\n ),\n ]) ];\n }\n }\n\n // Don't push down in all other cases\n return [ false, factory.createFilter(operation, expression) ];\n }\n case Algebra.types.MINUS:\n case Algebra.types.ALT:\n case Algebra.types.ASK:\n case Algebra.types.BGP:\n case Algebra.types.CONSTRUCT:\n case Algebra.types.DESCRIBE:\n case Algebra.types.DISTINCT:\n case Algebra.types.EXPRESSION:\n case Algebra.types.FROM:\n case Algebra.types.GRAPH:\n case Algebra.types.GROUP:\n case Algebra.types.INV:\n case Algebra.types.LINK:\n case Algebra.types.NPS:\n case Algebra.types.ONE_OR_MORE_PATH:\n case Algebra.types.ORDER_BY:\n case Algebra.types.REDUCED:\n case Algebra.types.SEQ:\n case Algebra.types.SERVICE:\n case Algebra.types.SLICE:\n case Algebra.types.ZERO_OR_MORE_PATH:\n case Algebra.types.ZERO_OR_ONE_PATH:\n case Algebra.types.COMPOSITE_UPDATE:\n case Algebra.types.DELETE_INSERT:\n case Algebra.types.LOAD:\n case Algebra.types.CLEAR:\n case Algebra.types.CREATE:\n case Algebra.types.DROP:\n case Algebra.types.ADD:\n case Algebra.types.MOVE:\n case Algebra.types.COPY:\n // Operations that do not support pushing down\n // Left-join and minus might be possible to support in the future.\n return [ false, factory.createFilter(operation, expression) ];\n }\n }\n\n /**\n * Check if the given expression is a simple equals operation with one variable and one non-literal\n * (or literal with canonical lexical form) term that can be pushed into a pattern.\n * @param expression The current expression.\n * @return The variable and term to fill into the pattern, or undefined.\n */\n public getEqualityExpressionPushableIntoPattern(\n expression: Algebra.Expression,\n ): { variable: RDF.Variable; term: RDF.Term } | undefined {\n if (expression.expressionType === Algebra.expressionTypes.OPERATOR && expression.operator === '=') {\n if (expression.args[0].expressionType === 'term' && expression.args[0].term.termType !== 'Variable' &&\n (expression.args[0].term.termType !== 'Literal' ||\n this.isLiteralWithCanonicalLexicalForm(expression.args[0].term)) &&\n expression.args[1].expressionType === 'term' && expression.args[1].term.termType === 'Variable') {\n return {\n variable: expression.args[1].term,\n term: expression.args[0].term,\n };\n }\n if (expression.args[0].expressionType === 'term' && expression.args[0].term.termType === 'Variable' &&\n expression.args[1].expressionType === 'term' && expression.args[1].term.termType !== 'Variable' &&\n (expression.args[1].term.termType !== 'Literal' ||\n this.isLiteralWithCanonicalLexicalForm(expression.args[1].term))) {\n return {\n variable: expression.args[0].term,\n term: expression.args[1].term,\n };\n }\n }\n }\n\n /**\n * Check if the given term is a literal with datatype that where all values\n * can only have one possible lexical representation.\n * In other words, no variants of values exist that should be considered equal.\n * For example: \"01\"^xsd:number and \"1\"^xsd:number will return false.\n * @param term An RDF term.\n * @protected\n */\n protected isLiteralWithCanonicalLexicalForm(term: RDF.Literal): boolean {\n switch (term.datatype.value) {\n case 'http://www.w3.org/2001/XMLSchema#string':\n case 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString':\n case 'http://www.w3.org/2001/XMLSchema#normalizedString':\n case 'http://www.w3.org/2001/XMLSchema#anyURI':\n case 'http://www.w3.org/2001/XMLSchema#base64Binary':\n case 'http://www.w3.org/2001/XMLSchema#language':\n case 'http://www.w3.org/2001/XMLSchema#Name':\n case 'http://www.w3.org/2001/XMLSchema#NCName':\n case 'http://www.w3.org/2001/XMLSchema#NMTOKEN':\n case 'http://www.w3.org/2001/XMLSchema#token':\n case 'http://www.w3.org/2001/XMLSchema#hexBinary':\n return true;\n }\n return false;\n }\n\n /**\n * Check if there is an overlap between the two given lists of variables.\n * @param varsA A list of variables.\n * @param varsB A list of variables.\n */\n public variablesIntersect(varsA: RDF.Variable[], varsB: RDF.Variable[]): boolean {\n return varsA.some(varA => varsB.some(varB => varA.equals(varB)));\n }\n\n /**\n * Check if all variables from the first list are included in the second list.\n * The second list may contain other variables as well.\n * @param varsNeedles A list of variables to search for.\n * @param varsHaystack A list of variables to search in.\n */\n public variablesSubSetOf(varsNeedles: RDF.Variable[], varsHaystack: RDF.Variable[]): boolean {\n return varsNeedles.length <= varsHaystack.length &&\n varsNeedles.every(varA => varsHaystack.some(varB => varA.equals(varB)));\n }\n\n /**\n * Check if an expression is simply 'false'.\n * @param expression An expression.\n */\n public isExpressionFalse(expression: Algebra.Expression): boolean {\n return (expression.term && expression.term.termType === 'Literal' && expression.term.value === 'false');\n }\n\n /**\n * Get all directly nested filter expressions.\n * As soon as a non-filter is found, it is returned as the input field.\n * @param op A filter expression.\n */\n public getNestedFilterExpressions(\n op: Algebra.Filter,\n ): { nestedExpressions: Algebra.Expression[]; input: Algebra.Operation } {\n if (op.input.type === Algebra.types.FILTER) {\n const childData = this.getNestedFilterExpressions(op.input);\n return { nestedExpressions: [ op.expression, ...childData.nestedExpressions ], input: childData.input };\n }\n return { nestedExpressions: [ op.expression ], input: op.input };\n }\n}\n\nexport interface IActorOptimizeQueryOperationFilterPushdownArgs extends IActorOptimizeQueryOperationArgs {\n /**\n * If filters should be pushed down as deep as possible.\n * If false, filters will only be pushed down if the source(s) accept them,\n * or if the filter is very selective.\n * @range {boolean}\n * @default {false}\n */\n aggressivePushdown: boolean;\n /**\n * The maximum number of full iterations across the query can be done for attempting to push down filters.\n * @default {10}\n */\n maxIterations: number;\n /**\n * If conjunctive filters should be split into nested filters before applying filter pushdown.\n * This can enable pushing down deeper.\n * @range {boolean}\n * @default {true}\n */\n splitConjunctive: boolean;\n /**\n * If nested filters should be merged into conjunctive filters after applying filter pushdown.\n * @range {boolean}\n * @default {true}\n */\n mergeConjunctive: boolean;\n /**\n * If filters should be pushed into left-joins.\n * @range {boolean}\n * @default {true}\n */\n pushIntoLeftJoins: boolean;\n /**\n * If simple equality filters should be pushed into patterns and paths.\n * This only applies to equality filters with terms that are not literals that have no canonical lexical form.\n * @range {boolean}\n * @default {true}\n */\n pushEqualityIntoPatterns: boolean;\n}\n"]}
package/lib/index.d.ts CHANGED
File without changes
package/lib/index.js CHANGED
File without changes
package/lib/index.js.map CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comunica/actor-optimize-query-operation-filter-pushdown",
3
- "version": "4.4.2-alpha.49.0",
3
+ "version": "4.5.0",
4
4
  "description": "A filter-pushdown optimize-query-operation actor",
5
5
  "lsd:module": true,
6
6
  "license": "MIT",
@@ -41,14 +41,14 @@
41
41
  "build:components": "componentsjs-generator"
42
42
  },
43
43
  "dependencies": {
44
- "@comunica/bus-optimize-query-operation": "4.4.2-alpha.49.0",
45
- "@comunica/context-entries": "4.4.2-alpha.49.0",
46
- "@comunica/core": "4.4.2-alpha.49.0",
47
- "@comunica/types": "4.4.2-alpha.49.0",
48
- "@comunica/utils-algebra": "4.4.2-alpha.49.0",
49
- "@comunica/utils-query-operation": "4.4.2-alpha.49.0",
44
+ "@comunica/bus-optimize-query-operation": "^4.5.0",
45
+ "@comunica/context-entries": "^4.5.0",
46
+ "@comunica/core": "^4.5.0",
47
+ "@comunica/types": "^4.5.0",
48
+ "@comunica/utils-query-operation": "^4.5.0",
50
49
  "@rdfjs/types": "*",
51
- "rdf-terms": "^2.0.0"
50
+ "rdf-terms": "^1.11.0",
51
+ "sparqlalgebrajs": "^5.0.2"
52
52
  },
53
- "gitHead": "ef6f96cfd8faf7c37955bb7e0fe9f6fc6a994bdf"
53
+ "gitHead": "2bcd98c387a021fc5c08d375793c205ca3d1bf0d"
54
54
  }