@comunica/actor-optimize-query-operation-filter-pushdown 4.5.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/ActorOptimizeQueryOperationFilterPushdown.jsonld +15 -15
- package/components/components.jsonld +1 -1
- package/components/context.jsonld +1 -1
- package/lib/ActorOptimizeQueryOperationFilterPushdown.d.ts +3 -3
- package/lib/ActorOptimizeQueryOperationFilterPushdown.js +222 -251
- package/lib/ActorOptimizeQueryOperationFilterPushdown.js.map +1 -1
- package/lib/index.d.ts +0 -0
- package/lib/index.js +0 -0
- package/lib/index.js.map +0 -0
- package/package.json +9 -9
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-filter-pushdown/^
|
|
4
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-optimize-query-operation/^
|
|
5
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-filter-pushdown/^5.0.0/components/context.jsonld",
|
|
4
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-optimize-query-operation/^5.0.0/components/context.jsonld",
|
|
5
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^5.0.0/components/context.jsonld"
|
|
6
6
|
],
|
|
7
7
|
"@id": "npmd:@comunica/actor-optimize-query-operation-filter-pushdown",
|
|
8
8
|
"components": [
|
|
@@ -71,37 +71,37 @@
|
|
|
71
71
|
"genericTypeInstances": [
|
|
72
72
|
{
|
|
73
73
|
"@type": "ParameterRangeGenericTypeReference",
|
|
74
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
74
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
75
75
|
},
|
|
76
76
|
{
|
|
77
77
|
"@type": "ParameterRangeGenericTypeReference",
|
|
78
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
78
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
79
79
|
},
|
|
80
80
|
{
|
|
81
81
|
"@type": "ParameterRangeGenericTypeReference",
|
|
82
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
82
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
83
83
|
},
|
|
84
84
|
{
|
|
85
85
|
"@type": "ParameterRangeGenericTypeReference",
|
|
86
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
86
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
87
87
|
}
|
|
88
88
|
]
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
91
|
"@type": "ParameterRangeGenericTypeReference",
|
|
92
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
92
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
93
93
|
},
|
|
94
94
|
{
|
|
95
95
|
"@type": "ParameterRangeGenericTypeReference",
|
|
96
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
96
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
97
97
|
},
|
|
98
98
|
{
|
|
99
99
|
"@type": "ParameterRangeGenericTypeReference",
|
|
100
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
100
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
101
101
|
},
|
|
102
102
|
{
|
|
103
103
|
"@type": "ParameterRangeGenericTypeReference",
|
|
104
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
104
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
105
105
|
}
|
|
106
106
|
]
|
|
107
107
|
},
|
|
@@ -138,19 +138,19 @@
|
|
|
138
138
|
"genericTypeInstances": [
|
|
139
139
|
{
|
|
140
140
|
"@type": "ParameterRangeGenericTypeReference",
|
|
141
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
141
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
142
142
|
},
|
|
143
143
|
{
|
|
144
144
|
"@type": "ParameterRangeGenericTypeReference",
|
|
145
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
145
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
146
146
|
},
|
|
147
147
|
{
|
|
148
148
|
"@type": "ParameterRangeGenericTypeReference",
|
|
149
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
149
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
150
150
|
},
|
|
151
151
|
{
|
|
152
152
|
"@type": "ParameterRangeGenericTypeReference",
|
|
153
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
153
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
154
154
|
}
|
|
155
155
|
]
|
|
156
156
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-filter-pushdown/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-filter-pushdown/^5.0.0/components/context.jsonld"
|
|
4
4
|
],
|
|
5
5
|
"@id": "npmd:@comunica/actor-optimize-query-operation-filter-pushdown",
|
|
6
6
|
"@type": "Module",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^6.0.0/components/context.jsonld",
|
|
4
4
|
{
|
|
5
5
|
"npmd": "https://linkedsoftwaredependencies.org/bundles/npm/",
|
|
6
|
-
"caoqofp": "npmd:@comunica/actor-optimize-query-operation-filter-pushdown/^
|
|
6
|
+
"caoqofp": "npmd:@comunica/actor-optimize-query-operation-filter-pushdown/^5.0.0/",
|
|
7
7
|
"ActorOptimizeQueryOperationFilterPushdown": {
|
|
8
8
|
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown",
|
|
9
9
|
"@prefix": true,
|
|
@@ -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';
|
|
5
6
|
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.
|
|
40
|
+
protected getOverlappingOperations(operation: Algebra.Union | Algebra.Join, 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:
|
|
58
|
+
filterPushdown(expression: Algebra.Expression, expressionVariables: RDF.Variable[], operation: Algebra.Operation, factory: AlgebraFactory, 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,104 +4,99 @@ 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");
|
|
7
8
|
const utils_query_operation_1 = require("@comunica/utils-query-operation");
|
|
8
9
|
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
|
*/
|
|
13
13
|
class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_operation_1.ActorOptimizeQueryOperation {
|
|
14
|
+
aggressivePushdown;
|
|
15
|
+
maxIterations;
|
|
16
|
+
splitConjunctive;
|
|
17
|
+
mergeConjunctive;
|
|
18
|
+
pushIntoLeftJoins;
|
|
19
|
+
pushEqualityIntoPatterns;
|
|
14
20
|
constructor(args) {
|
|
15
21
|
super(args);
|
|
22
|
+
this.aggressivePushdown = args.aggressivePushdown;
|
|
23
|
+
this.maxIterations = args.maxIterations;
|
|
24
|
+
this.splitConjunctive = args.splitConjunctive;
|
|
25
|
+
this.mergeConjunctive = args.mergeConjunctive;
|
|
26
|
+
this.pushIntoLeftJoins = args.pushIntoLeftJoins;
|
|
27
|
+
this.pushEqualityIntoPatterns = args.pushEqualityIntoPatterns;
|
|
16
28
|
}
|
|
17
29
|
async test(_action) {
|
|
18
30
|
return (0, core_1.passTestVoid)();
|
|
19
31
|
}
|
|
20
32
|
async run(action) {
|
|
21
33
|
const dataFactory = action.context.getSafe(context_entries_1.KeysInitQuery.dataFactory);
|
|
22
|
-
const algebraFactory = new
|
|
34
|
+
const algebraFactory = new utils_algebra_1.AlgebraFactory(dataFactory);
|
|
23
35
|
let operation = action.operation;
|
|
24
|
-
// eslint-disable-next-line ts/no-this-alias
|
|
25
|
-
const self = this;
|
|
26
36
|
// Split conjunctive filters into nested filters
|
|
27
37
|
if (this.splitConjunctive) {
|
|
28
|
-
operation =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
recurse: true,
|
|
41
|
-
result: op,
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
}, algebraFactory);
|
|
38
|
+
operation = utils_algebra_1.algebraUtils.mapOperation(operation, {
|
|
39
|
+
[utils_algebra_1.Algebra.Types.FILTER]: { transform: (filterOp) => {
|
|
40
|
+
// Split conjunctive filters into separate filters
|
|
41
|
+
if ((0, utils_algebra_1.isKnownSubType)(filterOp.expression, utils_algebra_1.Algebra.ExpressionTypes.OPERATOR) &&
|
|
42
|
+
filterOp.expression.operator === '&&') {
|
|
43
|
+
this.logDebug(action.context, `Split conjunctive filter into ${filterOp.expression.args.length} nested filters`);
|
|
44
|
+
return filterOp.expression.args
|
|
45
|
+
.reduce((operation, expression) => algebraFactory.createFilter(operation, expression), filterOp.input);
|
|
46
|
+
}
|
|
47
|
+
return filterOp;
|
|
48
|
+
} },
|
|
49
|
+
});
|
|
45
50
|
}
|
|
46
51
|
// Collect selector shapes of all operations
|
|
47
52
|
const sources = this.getSources(operation);
|
|
48
53
|
// eslint-disable-next-line ts/no-unnecessary-type-assertion
|
|
49
54
|
const sourceShapes = new Map(await Promise.all(sources
|
|
50
|
-
.map(async (source) => [
|
|
55
|
+
.map(async (source) => [
|
|
56
|
+
source,
|
|
57
|
+
await source.source.getSelectorShape(source.context ? action.context.merge(source.context) : action.context),
|
|
58
|
+
])));
|
|
51
59
|
// Push down all filters
|
|
52
60
|
// We loop until no more filters can be pushed down.
|
|
53
61
|
let repeat = true;
|
|
54
62
|
let iterations = 0;
|
|
55
63
|
while (repeat && iterations < this.maxIterations) {
|
|
56
64
|
repeat = false;
|
|
57
|
-
operation =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
repeat = true;
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
recurse: true,
|
|
79
|
-
result,
|
|
80
|
-
};
|
|
81
|
-
},
|
|
65
|
+
operation = utils_algebra_1.algebraUtils.mapOperation(operation, {
|
|
66
|
+
[utils_algebra_1.Algebra.Types.FILTER]: { transform: (filterOp) => {
|
|
67
|
+
// Check if the filter must be pushed down
|
|
68
|
+
const extensionFunctions = action.context.get(context_entries_1.KeysInitQuery.extensionFunctions);
|
|
69
|
+
const extensionFunctionsAlwaysPushdown = action.context.get(context_entries_1.KeysInitQuery.extensionFunctionsAlwaysPushdown);
|
|
70
|
+
if (!this.shouldAttemptPushDown(filterOp, sources, sourceShapes, extensionFunctions, extensionFunctionsAlwaysPushdown)) {
|
|
71
|
+
return filterOp;
|
|
72
|
+
}
|
|
73
|
+
// For all filter expressions in the operation,
|
|
74
|
+
// we attempt to push them down as deep as possible into the algebra.
|
|
75
|
+
const variables = (0, utils_query_operation_1.getExpressionVariables)(filterOp.expression);
|
|
76
|
+
const [isModified, result] = this
|
|
77
|
+
.filterPushdown(filterOp.expression, variables, filterOp.input, algebraFactory, action.context);
|
|
78
|
+
if (isModified) {
|
|
79
|
+
repeat = true;
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
} },
|
|
82
83
|
});
|
|
83
84
|
iterations++;
|
|
84
85
|
}
|
|
85
86
|
if (iterations > 1) {
|
|
86
|
-
|
|
87
|
+
this.logDebug(action.context, `Pushed down filters in ${iterations} iterations`);
|
|
87
88
|
}
|
|
88
89
|
// Merge nested filters into conjunctive filters
|
|
89
90
|
if (this.mergeConjunctive) {
|
|
90
|
-
operation =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
return {
|
|
101
|
-
recurse: true,
|
|
102
|
-
result: op,
|
|
103
|
-
};
|
|
104
|
-
},
|
|
91
|
+
operation = utils_algebra_1.algebraUtils.mapOperation(operation, {
|
|
92
|
+
[utils_algebra_1.Algebra.Types.FILTER]: { transform: (op) => {
|
|
93
|
+
if (op.input.type === utils_algebra_1.Algebra.Types.FILTER) {
|
|
94
|
+
const { nestedExpressions, input } = this.getNestedFilterExpressions(op);
|
|
95
|
+
this.logDebug(action.context, `Merge ${nestedExpressions.length} nested filters into conjunctive filter`);
|
|
96
|
+
return algebraFactory.createFilter(input, nestedExpressions.slice(1).reduce((previous, current) => algebraFactory.createOperatorExpression('&&', [previous, current]), nestedExpressions[0]));
|
|
97
|
+
}
|
|
98
|
+
return op;
|
|
99
|
+
} },
|
|
105
100
|
});
|
|
106
101
|
}
|
|
107
102
|
return { operation, context: action.context };
|
|
@@ -127,16 +122,19 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
|
|
|
127
122
|
}
|
|
128
123
|
// Push down if the filter is extremely selective
|
|
129
124
|
const expression = operation.expression;
|
|
130
|
-
if (expression
|
|
131
|
-
expression.
|
|
132
|
-
|
|
133
|
-
expression.args[1]
|
|
134
|
-
|
|
135
|
-
|
|
125
|
+
if ((0, utils_algebra_1.isKnownSubType)(expression, utils_algebra_1.Algebra.ExpressionTypes.OPERATOR) && expression.operator === '=' &&
|
|
126
|
+
(((0, utils_algebra_1.isKnownSubType)(expression.args[0], utils_algebra_1.Algebra.ExpressionTypes.TERM) &&
|
|
127
|
+
expression.args[0].term.termType !== 'Variable' &&
|
|
128
|
+
(0, utils_algebra_1.isKnownSubType)(expression.args[1], utils_algebra_1.Algebra.ExpressionTypes.TERM) &&
|
|
129
|
+
expression.args[1].term.termType === 'Variable') ||
|
|
130
|
+
((0, utils_algebra_1.isKnownSubType)(expression.args[0], utils_algebra_1.Algebra.ExpressionTypes.TERM) &&
|
|
131
|
+
expression.args[0].term.termType === 'Variable' &&
|
|
132
|
+
(0, utils_algebra_1.isKnownSubType)(expression.args[1], utils_algebra_1.Algebra.ExpressionTypes.TERM) &&
|
|
133
|
+
expression.args[1].term.termType !== 'Variable'))) {
|
|
136
134
|
return true;
|
|
137
135
|
}
|
|
138
136
|
// Don't push down extension functions comunica support, but no source does
|
|
139
|
-
if (extensionFunctions && expression
|
|
137
|
+
if (extensionFunctions && (0, utils_algebra_1.isKnownSubType)(expression, utils_algebra_1.Algebra.ExpressionTypes.NAMED) &&
|
|
140
138
|
expression.name.value in extensionFunctions &&
|
|
141
139
|
// Checks if there's not a single source that supports the extension function
|
|
142
140
|
!sources.some(source => (0, utils_query_operation_1.doesShapeAcceptOperation)(sourceShapes.get(source), expression))) {
|
|
@@ -164,11 +162,11 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
|
|
|
164
162
|
}
|
|
165
163
|
return false;
|
|
166
164
|
};
|
|
167
|
-
|
|
168
|
-
[
|
|
169
|
-
[
|
|
170
|
-
[
|
|
171
|
-
[
|
|
165
|
+
utils_algebra_1.algebraUtils.visitOperation(operation, {
|
|
166
|
+
[utils_algebra_1.Algebra.Types.PATTERN]: { visitor: sourceAdder },
|
|
167
|
+
[utils_algebra_1.Algebra.Types.SERVICE]: { visitor: sourceAdder },
|
|
168
|
+
[utils_algebra_1.Algebra.Types.LINK]: { visitor: sourceAdder },
|
|
169
|
+
[utils_algebra_1.Algebra.Types.NPS]: { visitor: sourceAdder },
|
|
172
170
|
});
|
|
173
171
|
return [...sources];
|
|
174
172
|
}
|
|
@@ -177,7 +175,7 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
|
|
|
177
175
|
const partiallyOverlapping = [];
|
|
178
176
|
const notOverlapping = [];
|
|
179
177
|
for (const input of operation.input) {
|
|
180
|
-
const inputVariables =
|
|
178
|
+
const inputVariables = utils_algebra_1.algebraUtils.inScopeVariables(input);
|
|
181
179
|
if (this.variablesSubSetOf(expressionVariables, inputVariables)) {
|
|
182
180
|
fullyOverlapping.push(input);
|
|
183
181
|
}
|
|
@@ -213,183 +211,154 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
|
|
|
213
211
|
return [true, factory.createUnion([])];
|
|
214
212
|
}
|
|
215
213
|
// Don't push down (NOT) EXISTS
|
|
216
|
-
if (expression.
|
|
214
|
+
if ((0, utils_algebra_1.isKnownOperation)(expression, utils_algebra_1.Algebra.Types.EXPRESSION, utils_algebra_1.Algebra.ExpressionTypes.EXISTENCE)) {
|
|
217
215
|
return [false, factory.createFilter(operation, expression)];
|
|
218
216
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
217
|
+
if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.EXTEND)) {
|
|
218
|
+
// Pass if the variable is not part of the expression
|
|
219
|
+
if (!this.variablesIntersect([operation.variable], expressionVariables)) {
|
|
220
|
+
return [true, factory.createExtend(this.filterPushdown(expression, expressionVariables, operation.input, factory, context)[1], operation.variable, operation.expression)];
|
|
221
|
+
}
|
|
222
|
+
return [false, factory.createFilter(operation, expression)];
|
|
223
|
+
}
|
|
224
|
+
if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.FILTER)) {
|
|
225
|
+
// Always pass
|
|
226
|
+
const [isModified, result] = this
|
|
227
|
+
.filterPushdown(expression, expressionVariables, operation.input, factory, context);
|
|
228
|
+
return [isModified, factory.createFilter(result, operation.expression)];
|
|
229
|
+
}
|
|
230
|
+
if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.JOIN)) {
|
|
231
|
+
// Don't push down for empty join
|
|
232
|
+
if (operation.input.length === 0) {
|
|
225
233
|
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)];
|
|
231
234
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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)];
|
|
235
|
+
// Determine overlapping operations
|
|
236
|
+
const { fullyOverlapping, partiallyOverlapping, notOverlapping, } = this.getOverlappingOperations(operation, expressionVariables);
|
|
237
|
+
const joins = [];
|
|
238
|
+
let isModified = false;
|
|
239
|
+
if (fullyOverlapping.length > 0) {
|
|
240
|
+
isModified = true;
|
|
241
|
+
joins.push(factory.createJoin(fullyOverlapping
|
|
242
|
+
.map(input => this.filterPushdown(expression, expressionVariables, input, factory, context)[1])));
|
|
259
243
|
}
|
|
260
|
-
|
|
261
|
-
|
|
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)];
|
|
244
|
+
if (partiallyOverlapping.length > 0) {
|
|
245
|
+
joins.push(factory.createFilter(factory.createJoin(partiallyOverlapping, false), expression));
|
|
292
246
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
247
|
+
if (notOverlapping.length > 0) {
|
|
248
|
+
joins.push(...notOverlapping);
|
|
249
|
+
}
|
|
250
|
+
if (joins.length > 1) {
|
|
251
|
+
isModified = true;
|
|
252
|
+
}
|
|
253
|
+
if (isModified) {
|
|
254
|
+
this.logDebug(context, `Push down filter across join entries with ${fullyOverlapping.length} fully overlapping, ${partiallyOverlapping.length} partially overlapping, and ${notOverlapping.length} not overlapping`);
|
|
255
|
+
}
|
|
256
|
+
return [isModified, joins.length === 1 ? joins[0] : factory.createJoin(joins)];
|
|
257
|
+
}
|
|
258
|
+
if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.NOP)) {
|
|
259
|
+
return [true, operation];
|
|
260
|
+
}
|
|
261
|
+
if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.PROJECT)) {
|
|
262
|
+
// Push down if variables overlap
|
|
263
|
+
if (this.variablesIntersect(operation.variables, expressionVariables)) {
|
|
264
|
+
return [true, factory.createProject(this.filterPushdown(expression, expressionVariables, operation.input, factory, context)[1], operation.variables)];
|
|
265
|
+
}
|
|
266
|
+
// Void expression otherwise
|
|
267
|
+
return [true, operation];
|
|
268
|
+
}
|
|
269
|
+
if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_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)];
|
|
292
|
+
}
|
|
293
|
+
if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.VALUES)) {
|
|
294
|
+
// Only keep filter if it overlaps with the variables
|
|
295
|
+
if (this.variablesIntersect(operation.variables, expressionVariables)) {
|
|
309
296
|
return [false, factory.createFilter(operation, expression)];
|
|
310
297
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
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
|
-
}
|
|
298
|
+
return [true, operation];
|
|
299
|
+
}
|
|
300
|
+
if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.LEFT_JOIN)) {
|
|
301
|
+
if (this.pushIntoLeftJoins) {
|
|
302
|
+
const rightVariables = utils_algebra_1.algebraUtils.inScopeVariables(operation.input[1]);
|
|
303
|
+
if (!this.variablesIntersect(expressionVariables, rightVariables)) {
|
|
304
|
+
// If filter *only* applies to left entry of optional, push it down into that.
|
|
305
|
+
this.logDebug(context, `Push down filter into left join`);
|
|
306
|
+
return [true, factory.createLeftJoin(this.filterPushdown(expression, expressionVariables, operation.input[0], factory, context)[1], operation.input[1], operation.expression)];
|
|
335
307
|
}
|
|
336
|
-
// Don't push down in all other cases
|
|
337
|
-
return [false, factory.createFilter(operation, expression)];
|
|
338
308
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
309
|
+
// Don't push down in all other cases
|
|
310
|
+
return [false, factory.createFilter(operation, expression)];
|
|
311
|
+
}
|
|
312
|
+
if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.PATTERN)) {
|
|
313
|
+
if (this.pushEqualityIntoPatterns) {
|
|
314
|
+
// Try to push simple FILTER(?s = <iri>) expressions into the pattern
|
|
315
|
+
const pushableResult = this.getEqualityExpressionPushableIntoPattern(expression);
|
|
316
|
+
if (pushableResult) {
|
|
317
|
+
let isModified = false;
|
|
318
|
+
const originalMetadata = operation.metadata;
|
|
319
|
+
operation = (0, rdf_terms_1.mapTermsNested)(operation, (value) => {
|
|
320
|
+
if (value.equals(pushableResult.variable)) {
|
|
321
|
+
isModified = true;
|
|
322
|
+
return pushableResult.term;
|
|
323
|
+
}
|
|
324
|
+
return value;
|
|
325
|
+
});
|
|
326
|
+
operation.type = utils_algebra_1.Algebra.Types.PATTERN;
|
|
327
|
+
operation.metadata = originalMetadata;
|
|
328
|
+
if (isModified) {
|
|
329
|
+
this.logDebug(context, `Push down filter into pattern for ?${pushableResult.variable.value}`);
|
|
349
330
|
return [true, factory.createJoin([
|
|
350
331
|
operation,
|
|
351
|
-
factory.createValues([pushableResult.variable], [{ [
|
|
332
|
+
factory.createValues([pushableResult.variable], [{ [pushableResult.variable.value]: pushableResult.term }]),
|
|
352
333
|
])];
|
|
353
334
|
}
|
|
354
335
|
}
|
|
355
|
-
// Don't push down in all other cases
|
|
356
|
-
return [false, factory.createFilter(operation, expression)];
|
|
357
336
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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)];
|
|
337
|
+
// Don't push down in all other cases
|
|
338
|
+
return [false, factory.createFilter(operation, expression)];
|
|
339
|
+
}
|
|
340
|
+
if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.PATH)) {
|
|
341
|
+
if (this.pushEqualityIntoPatterns) {
|
|
342
|
+
// Try to push simple FILTER(?s = <iri>) expressions into the path
|
|
343
|
+
const pushableResult = this.getEqualityExpressionPushableIntoPattern(expression);
|
|
344
|
+
if (pushableResult &&
|
|
345
|
+
(operation.subject.equals(pushableResult.variable) || operation.object.equals(pushableResult.variable))) {
|
|
346
|
+
this.logDebug(context, `Push down filter into path for ?${pushableResult.variable.value}`);
|
|
347
|
+
const originalMetadata = operation.metadata;
|
|
348
|
+
operation = factory.createPath(operation.subject.equals(pushableResult.variable) ? pushableResult.term : operation.subject, operation.predicate, operation.object.equals(pushableResult.variable) ? pushableResult.term : operation.object);
|
|
349
|
+
operation.metadata = originalMetadata;
|
|
350
|
+
return [true, factory.createJoin([
|
|
351
|
+
operation,
|
|
352
|
+
factory.createValues([pushableResult.variable], [{ [pushableResult.variable.value]: pushableResult.term }]),
|
|
353
|
+
])];
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
// Don't push down in all other cases
|
|
357
|
+
return [false, factory.createFilter(operation, expression)];
|
|
392
358
|
}
|
|
359
|
+
// Operations that do not support pushing down
|
|
360
|
+
// Left-join and minus might be possible to support in the future.
|
|
361
|
+
return [false, factory.createFilter(operation, expression)];
|
|
393
362
|
}
|
|
394
363
|
/**
|
|
395
364
|
* Check if the given expression is a simple equals operation with one variable and one non-literal
|
|
@@ -398,23 +367,24 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
|
|
|
398
367
|
* @return The variable and term to fill into the pattern, or undefined.
|
|
399
368
|
*/
|
|
400
369
|
getEqualityExpressionPushableIntoPattern(expression) {
|
|
401
|
-
if (expression
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
370
|
+
if ((0, utils_algebra_1.isKnownSubType)(expression, utils_algebra_1.Algebra.ExpressionTypes.OPERATOR) && expression.operator === '=') {
|
|
371
|
+
const arg0 = expression.args[0];
|
|
372
|
+
const arg1 = expression.args[1];
|
|
373
|
+
if ((0, utils_algebra_1.isKnownSubType)(arg0, utils_algebra_1.Algebra.ExpressionTypes.TERM) && arg0.term.termType !== 'Variable' &&
|
|
374
|
+
(arg0.term.termType !== 'Literal' || this.isLiteralWithCanonicalLexicalForm(arg0.term)) &&
|
|
375
|
+
(0, utils_algebra_1.isKnownSubType)(arg1, utils_algebra_1.Algebra.ExpressionTypes.TERM) &&
|
|
376
|
+
arg1.term.termType === 'Variable') {
|
|
406
377
|
return {
|
|
407
|
-
variable:
|
|
408
|
-
term:
|
|
378
|
+
variable: arg1.term,
|
|
379
|
+
term: arg0.term,
|
|
409
380
|
};
|
|
410
381
|
}
|
|
411
|
-
if (
|
|
412
|
-
|
|
413
|
-
(
|
|
414
|
-
this.isLiteralWithCanonicalLexicalForm(expression.args[1].term))) {
|
|
382
|
+
if ((0, utils_algebra_1.isKnownSubType)(arg0, utils_algebra_1.Algebra.ExpressionTypes.TERM) && arg0.term.termType === 'Variable' &&
|
|
383
|
+
(0, utils_algebra_1.isKnownSubType)(arg1, utils_algebra_1.Algebra.ExpressionTypes.TERM) && arg1.term.termType !== 'Variable' &&
|
|
384
|
+
(arg1.term.termType !== 'Literal' || this.isLiteralWithCanonicalLexicalForm(arg1.term))) {
|
|
415
385
|
return {
|
|
416
|
-
variable:
|
|
417
|
-
term:
|
|
386
|
+
variable: arg0.term,
|
|
387
|
+
term: arg1.term,
|
|
418
388
|
};
|
|
419
389
|
}
|
|
420
390
|
}
|
|
@@ -467,7 +437,8 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
|
|
|
467
437
|
* @param expression An expression.
|
|
468
438
|
*/
|
|
469
439
|
isExpressionFalse(expression) {
|
|
470
|
-
|
|
440
|
+
const casted = expression;
|
|
441
|
+
return (casted.term && casted.term.termType === 'Literal' && casted.term.value === 'false');
|
|
471
442
|
}
|
|
472
443
|
/**
|
|
473
444
|
* Get all directly nested filter expressions.
|
|
@@ -475,7 +446,7 @@ class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_opera
|
|
|
475
446
|
* @param op A filter expression.
|
|
476
447
|
*/
|
|
477
448
|
getNestedFilterExpressions(op) {
|
|
478
|
-
if (op.input
|
|
449
|
+
if ((0, utils_algebra_1.isKnownOperation)(op.input, utils_algebra_1.Algebra.Types.FILTER)) {
|
|
479
450
|
const childData = this.getNestedFilterExpressions(op.input);
|
|
480
451
|
return { nestedExpressions: [op.expression, ...childData.nestedExpressions], input: childData.input };
|
|
481
452
|
}
|
|
@@ -1 +1 @@
|
|
|
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,CAA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,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;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"]}
|
|
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;IACvE,kBAAkB,CAAU;IAC5B,a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,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;AAhiBD,8FAgiBC","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 this.aggressivePushdown = args.aggressivePushdown;\n this.maxIterations = args.maxIterations;\n this.splitConjunctive = args.splitConjunctive;\n this.mergeConjunctive = args.mergeConjunctive;\n this.pushIntoLeftJoins = args.pushIntoLeftJoins;\n this.pushEqualityIntoPatterns = args.pushEqualityIntoPatterns;\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 => [\n source,\n await source.source.getSelectorShape(source.context ? action.context.merge(source.context) : action.context),\n ])));\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"]}
|
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": "
|
|
3
|
+
"version": "5.0.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": "^
|
|
45
|
-
"@comunica/context-entries": "^
|
|
46
|
-
"@comunica/core": "^
|
|
47
|
-
"@comunica/types": "^
|
|
48
|
-
"@comunica/utils-
|
|
44
|
+
"@comunica/bus-optimize-query-operation": "^5.0.0",
|
|
45
|
+
"@comunica/context-entries": "^5.0.0",
|
|
46
|
+
"@comunica/core": "^5.0.0",
|
|
47
|
+
"@comunica/types": "^5.0.0",
|
|
48
|
+
"@comunica/utils-algebra": "^5.0.0",
|
|
49
|
+
"@comunica/utils-query-operation": "^5.0.0",
|
|
49
50
|
"@rdfjs/types": "*",
|
|
50
|
-
"rdf-terms": "^
|
|
51
|
-
"sparqlalgebrajs": "^5.0.2"
|
|
51
|
+
"rdf-terms": "^2.0.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "0b1756fdb9bef014133432489627c1bd71779bd0"
|
|
54
54
|
}
|