@comunica/actor-optimize-query-operation-filter-pushdown 3.0.1-alpha.43.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/LICENSE.txt +22 -0
- package/README.md +36 -0
- package/components/ActorOptimizeQueryOperationFilterPushdown.jsonld +165 -0
- package/components/components.jsonld +11 -0
- package/components/context.jsonld +35 -0
- package/lib/ActorOptimizeQueryOperationFilterPushdown.d.ts +53 -0
- package/lib/ActorOptimizeQueryOperationFilterPushdown.js +214 -0
- package/lib/ActorOptimizeQueryOperationFilterPushdown.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +18 -0
- package/lib/index.js.map +1 -0
- package/package.json +48 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2017–now Ruben Taelman, Joachim Van Herwegen
|
|
4
|
+
Comunica Association and Ghent University – imec, Belgium
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Comunica Filter Pushdown Optimize Query Operation Actor
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@comunica/actor-optimize-query-operation-filter-pushdown)
|
|
4
|
+
|
|
5
|
+
An [Optimize Query Operation](https://github.com/comunica/comunica/tree/master/packages/bus-optimize-query-operation) actor
|
|
6
|
+
that pushed down filter expressions into the query plan as deep as possible.
|
|
7
|
+
|
|
8
|
+
This module is part of the [Comunica framework](https://github.com/comunica/comunica),
|
|
9
|
+
and should only be used by [developers that want to build their own query engine](https://comunica.dev/docs/modify/).
|
|
10
|
+
|
|
11
|
+
[Click here if you just want to query with Comunica](https://comunica.dev/docs/query/).
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
$ yarn add @comunica/actor-optimize-query-operation-filter-pushdown
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Configure
|
|
20
|
+
|
|
21
|
+
After installing, this package can be added to your engine's configuration as follows:
|
|
22
|
+
```text
|
|
23
|
+
{
|
|
24
|
+
"@context": [
|
|
25
|
+
...
|
|
26
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-filter-pushdown/^1.0.0/components/context.jsonld"
|
|
27
|
+
],
|
|
28
|
+
"actors": [
|
|
29
|
+
...
|
|
30
|
+
{
|
|
31
|
+
"@id": "urn:comunica:default:optimize-query-operation/actors#filter-pushdown",
|
|
32
|
+
"@type": "ActorOptimizeQueryOperationFilterPushdown"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
```
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": [
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-filter-pushdown/^3.0.0/components/context.jsonld",
|
|
4
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-optimize-query-operation/^3.0.0/components/context.jsonld",
|
|
5
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^3.0.0/components/context.jsonld"
|
|
6
|
+
],
|
|
7
|
+
"@id": "npmd:@comunica/actor-optimize-query-operation-filter-pushdown",
|
|
8
|
+
"components": [
|
|
9
|
+
{
|
|
10
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown",
|
|
11
|
+
"@type": "Class",
|
|
12
|
+
"requireElement": "ActorOptimizeQueryOperationFilterPushdown",
|
|
13
|
+
"extends": [
|
|
14
|
+
"cboqo:components/ActorOptimizeQueryOperation.jsonld#ActorOptimizeQueryOperation"
|
|
15
|
+
],
|
|
16
|
+
"comment": "A comunica Filter Pushdown Optimize Query Operation Actor.",
|
|
17
|
+
"parameters": [
|
|
18
|
+
{
|
|
19
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown_args_name",
|
|
20
|
+
"range": "xsd:string",
|
|
21
|
+
"default": {
|
|
22
|
+
"@id": "rdf:subject"
|
|
23
|
+
},
|
|
24
|
+
"comment": "The name for this actor."
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown_args_bus",
|
|
28
|
+
"range": {
|
|
29
|
+
"@type": "ParameterRangeGenericComponent",
|
|
30
|
+
"component": "cc:components/Bus.jsonld#Bus",
|
|
31
|
+
"genericTypeInstances": [
|
|
32
|
+
{
|
|
33
|
+
"@type": "ParameterRangeGenericComponent",
|
|
34
|
+
"component": "cc:components/Actor.jsonld#Actor",
|
|
35
|
+
"genericTypeInstances": [
|
|
36
|
+
{
|
|
37
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
38
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
42
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
46
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
52
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
56
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
60
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"default": {
|
|
65
|
+
"@id": "cboqo:components/ActorOptimizeQueryOperation.jsonld#ActorOptimizeQueryOperation_default_bus",
|
|
66
|
+
"@type": "cc:components/Bus.jsonld#Bus"
|
|
67
|
+
},
|
|
68
|
+
"comment": "The bus this actor subscribes to."
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown_args_beforeActors",
|
|
72
|
+
"range": {
|
|
73
|
+
"@type": "ParameterRangeUnion",
|
|
74
|
+
"parameterRangeElements": [
|
|
75
|
+
{
|
|
76
|
+
"@type": "ParameterRangeArray",
|
|
77
|
+
"parameterRangeValue": {
|
|
78
|
+
"@type": "ParameterRangeGenericComponent",
|
|
79
|
+
"component": "cc:components/Actor.jsonld#Actor",
|
|
80
|
+
"genericTypeInstances": [
|
|
81
|
+
{
|
|
82
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
83
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
87
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
91
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"@type": "ParameterRangeUndefined"
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
"comment": "Actor that must be registered in the bus before this actor."
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
"memberFields": [
|
|
105
|
+
{
|
|
106
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown__member_constructor",
|
|
107
|
+
"memberFieldName": "constructor"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown__member_test",
|
|
111
|
+
"memberFieldName": "test"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown__member_run",
|
|
115
|
+
"memberFieldName": "run"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown__member_getExpressionVariables",
|
|
119
|
+
"memberFieldName": "getExpressionVariables"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown__member_getOverlappingOperations",
|
|
123
|
+
"memberFieldName": "getOverlappingOperations"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown__member_filterPushdown",
|
|
127
|
+
"memberFieldName": "filterPushdown"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown__member_variablesIntersect",
|
|
131
|
+
"memberFieldName": "variablesIntersect"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown__member_variablesSubSetOf",
|
|
135
|
+
"memberFieldName": "variablesSubSetOf"
|
|
136
|
+
}
|
|
137
|
+
],
|
|
138
|
+
"constructorArguments": [
|
|
139
|
+
{
|
|
140
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown_args__constructorArgument",
|
|
141
|
+
"fields": [
|
|
142
|
+
{
|
|
143
|
+
"keyRaw": "name",
|
|
144
|
+
"value": {
|
|
145
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown_args_name"
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"keyRaw": "bus",
|
|
150
|
+
"value": {
|
|
151
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown_args_bus"
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"keyRaw": "beforeActors",
|
|
156
|
+
"value": {
|
|
157
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown_args_beforeActors"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": [
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-filter-pushdown/^3.0.0/components/context.jsonld"
|
|
4
|
+
],
|
|
5
|
+
"@id": "npmd:@comunica/actor-optimize-query-operation-filter-pushdown",
|
|
6
|
+
"@type": "Module",
|
|
7
|
+
"requireName": "@comunica/actor-optimize-query-operation-filter-pushdown",
|
|
8
|
+
"import": [
|
|
9
|
+
"caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld"
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": [
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^5.0.0/components/context.jsonld",
|
|
4
|
+
{
|
|
5
|
+
"npmd": "https://linkedsoftwaredependencies.org/bundles/npm/",
|
|
6
|
+
"caoqofp": "npmd:@comunica/actor-optimize-query-operation-filter-pushdown/^3.0.0/",
|
|
7
|
+
"ActorOptimizeQueryOperationFilterPushdown": {
|
|
8
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown",
|
|
9
|
+
"@prefix": true,
|
|
10
|
+
"@context": {
|
|
11
|
+
"args_name": {
|
|
12
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown_args_name"
|
|
13
|
+
},
|
|
14
|
+
"args_bus": {
|
|
15
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown_args_bus"
|
|
16
|
+
},
|
|
17
|
+
"args_beforeActors": {
|
|
18
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown_args_beforeActors",
|
|
19
|
+
"@container": "@list"
|
|
20
|
+
},
|
|
21
|
+
"name": {
|
|
22
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown_args_name"
|
|
23
|
+
},
|
|
24
|
+
"bus": {
|
|
25
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown_args_bus"
|
|
26
|
+
},
|
|
27
|
+
"beforeActors": {
|
|
28
|
+
"@id": "caoqofp:components/ActorOptimizeQueryOperationFilterPushdown.jsonld#ActorOptimizeQueryOperationFilterPushdown_args_beforeActors",
|
|
29
|
+
"@container": "@list"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { IActionOptimizeQueryOperation, IActorOptimizeQueryOperationOutput, IActorOptimizeQueryOperationArgs } from '@comunica/bus-optimize-query-operation';
|
|
2
|
+
import { ActorOptimizeQueryOperation } from '@comunica/bus-optimize-query-operation';
|
|
3
|
+
import type { IActorTest } from '@comunica/core';
|
|
4
|
+
import type { IActionContext } from '@comunica/types';
|
|
5
|
+
import type * as RDF from '@rdfjs/types';
|
|
6
|
+
import type { Factory } from 'sparqlalgebrajs';
|
|
7
|
+
import { Algebra } from 'sparqlalgebrajs';
|
|
8
|
+
/**
|
|
9
|
+
* A comunica Filter Pushdown Optimize Query Operation Actor.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ActorOptimizeQueryOperationFilterPushdown extends ActorOptimizeQueryOperation {
|
|
12
|
+
constructor(args: IActorOptimizeQueryOperationArgs);
|
|
13
|
+
test(action: IActionOptimizeQueryOperation): Promise<IActorTest>;
|
|
14
|
+
run(action: IActionOptimizeQueryOperation): Promise<IActorOptimizeQueryOperationOutput>;
|
|
15
|
+
/**
|
|
16
|
+
* Get all variables inside the given expression.
|
|
17
|
+
* @param expression An expression.
|
|
18
|
+
* @return An array of variables, or undefined if the expression is unsupported for pushdown.
|
|
19
|
+
*/
|
|
20
|
+
getExpressionVariables(expression: Algebra.Expression): RDF.Variable[];
|
|
21
|
+
protected getOverlappingOperations(operation: Algebra.Operation, expressionVariables: RDF.Variable[]): {
|
|
22
|
+
fullyOverlapping: Algebra.Operation[];
|
|
23
|
+
partiallyOverlapping: Algebra.Operation[];
|
|
24
|
+
notOverlapping: Algebra.Operation[];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Recursively push down the given expression into the given operation if possible.
|
|
28
|
+
* Different operators have different semantics for choosing whether or not to push down,
|
|
29
|
+
* and how this pushdown is done.
|
|
30
|
+
* For every passed operator, it is checked whether or not the filter will have any effect on the operation.
|
|
31
|
+
* If not, the filter is voided.
|
|
32
|
+
* @param expression An expression to push down.
|
|
33
|
+
* @param expressionVariables The variables inside the given expression.
|
|
34
|
+
* @param operation The operation to push down into.
|
|
35
|
+
* @param factory An algebra factory.
|
|
36
|
+
* @param context The action context.
|
|
37
|
+
* @return The modified operation.
|
|
38
|
+
*/
|
|
39
|
+
filterPushdown(expression: Algebra.Expression, expressionVariables: RDF.Variable[], operation: Algebra.Operation, factory: Factory, context: IActionContext): Algebra.Operation;
|
|
40
|
+
/**
|
|
41
|
+
* Check if there is an overlap between the two given lists of variables.
|
|
42
|
+
* @param varsA A list of variables.
|
|
43
|
+
* @param varsB A list of variables.
|
|
44
|
+
*/
|
|
45
|
+
variablesIntersect(varsA: RDF.Variable[], varsB: RDF.Variable[]): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Check if all variables from the first list are included in the second list.
|
|
48
|
+
* The second list may contain other variables as well.
|
|
49
|
+
* @param varsNeedles A list of variables to search for.
|
|
50
|
+
* @param varsHaystack A list of variables to search in.
|
|
51
|
+
*/
|
|
52
|
+
variablesSubSetOf(varsNeedles: RDF.Variable[], varsHaystack: RDF.Variable[]): boolean;
|
|
53
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActorOptimizeQueryOperationFilterPushdown = void 0;
|
|
4
|
+
const bus_optimize_query_operation_1 = require("@comunica/bus-optimize-query-operation");
|
|
5
|
+
const rdf_terms_1 = require("rdf-terms");
|
|
6
|
+
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
|
|
7
|
+
/**
|
|
8
|
+
* A comunica Filter Pushdown Optimize Query Operation Actor.
|
|
9
|
+
*/
|
|
10
|
+
class ActorOptimizeQueryOperationFilterPushdown extends bus_optimize_query_operation_1.ActorOptimizeQueryOperation {
|
|
11
|
+
constructor(args) {
|
|
12
|
+
super(args);
|
|
13
|
+
}
|
|
14
|
+
async test(action) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
async run(action) {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias,consistent-this
|
|
19
|
+
const self = this;
|
|
20
|
+
const operation = sparqlalgebrajs_1.Util.mapOperation(action.operation, {
|
|
21
|
+
filter(op, factory) {
|
|
22
|
+
// For all filter expressions in the operation,
|
|
23
|
+
// we attempt to push them down as deep as possible into the algebra.
|
|
24
|
+
const variables = self.getExpressionVariables(op.expression);
|
|
25
|
+
return {
|
|
26
|
+
recurse: true,
|
|
27
|
+
result: self.filterPushdown(op.expression, variables, op.input, factory, action.context),
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
return { operation, context: action.context };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get all variables inside the given expression.
|
|
35
|
+
* @param expression An expression.
|
|
36
|
+
* @return An array of variables, or undefined if the expression is unsupported for pushdown.
|
|
37
|
+
*/
|
|
38
|
+
getExpressionVariables(expression) {
|
|
39
|
+
switch (expression.expressionType) {
|
|
40
|
+
case sparqlalgebrajs_1.Algebra.expressionTypes.AGGREGATE:
|
|
41
|
+
case sparqlalgebrajs_1.Algebra.expressionTypes.WILDCARD:
|
|
42
|
+
throw new Error(`Getting expression variables is not supported for ${expression.expressionType}`);
|
|
43
|
+
case sparqlalgebrajs_1.Algebra.expressionTypes.EXISTENCE:
|
|
44
|
+
return sparqlalgebrajs_1.Util.inScopeVariables(expression.input);
|
|
45
|
+
case sparqlalgebrajs_1.Algebra.expressionTypes.NAMED:
|
|
46
|
+
return [];
|
|
47
|
+
case sparqlalgebrajs_1.Algebra.expressionTypes.OPERATOR:
|
|
48
|
+
return (0, rdf_terms_1.uniqTerms)(expression.args.flatMap(arg => this.getExpressionVariables(arg)));
|
|
49
|
+
case sparqlalgebrajs_1.Algebra.expressionTypes.TERM:
|
|
50
|
+
if (expression.term.termType === 'Variable') {
|
|
51
|
+
return [expression.term];
|
|
52
|
+
}
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
getOverlappingOperations(operation, expressionVariables) {
|
|
57
|
+
const fullyOverlapping = [];
|
|
58
|
+
const partiallyOverlapping = [];
|
|
59
|
+
const notOverlapping = [];
|
|
60
|
+
for (const input of operation.input) {
|
|
61
|
+
const inputVariables = sparqlalgebrajs_1.Util.inScopeVariables(input);
|
|
62
|
+
if (this.variablesSubSetOf(expressionVariables, inputVariables)) {
|
|
63
|
+
fullyOverlapping.push(input);
|
|
64
|
+
}
|
|
65
|
+
else if (this.variablesIntersect(expressionVariables, inputVariables)) {
|
|
66
|
+
partiallyOverlapping.push(input);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
notOverlapping.push(input);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
fullyOverlapping,
|
|
74
|
+
partiallyOverlapping,
|
|
75
|
+
notOverlapping,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Recursively push down the given expression into the given operation if possible.
|
|
80
|
+
* Different operators have different semantics for choosing whether or not to push down,
|
|
81
|
+
* and how this pushdown is done.
|
|
82
|
+
* For every passed operator, it is checked whether or not the filter will have any effect on the operation.
|
|
83
|
+
* If not, the filter is voided.
|
|
84
|
+
* @param expression An expression to push down.
|
|
85
|
+
* @param expressionVariables The variables inside the given expression.
|
|
86
|
+
* @param operation The operation to push down into.
|
|
87
|
+
* @param factory An algebra factory.
|
|
88
|
+
* @param context The action context.
|
|
89
|
+
* @return The modified operation.
|
|
90
|
+
*/
|
|
91
|
+
filterPushdown(expression, expressionVariables, operation, factory, context) {
|
|
92
|
+
switch (operation.type) {
|
|
93
|
+
case sparqlalgebrajs_1.Algebra.types.EXTEND:
|
|
94
|
+
// Pass if the variable is not part of the expression
|
|
95
|
+
if (!this.variablesIntersect([operation.variable], expressionVariables)) {
|
|
96
|
+
return factory.createExtend(this.filterPushdown(expression, expressionVariables, operation.input, factory, context), operation.variable, operation.expression);
|
|
97
|
+
}
|
|
98
|
+
return factory.createFilter(operation, expression);
|
|
99
|
+
case sparqlalgebrajs_1.Algebra.types.FILTER:
|
|
100
|
+
// Always pass
|
|
101
|
+
return factory.createFilter(this.filterPushdown(expression, expressionVariables, operation.input, factory, context), operation.expression);
|
|
102
|
+
case sparqlalgebrajs_1.Algebra.types.JOIN: {
|
|
103
|
+
// Don't push down for empty join
|
|
104
|
+
if (operation.input.length === 0) {
|
|
105
|
+
return factory.createFilter(operation, expression);
|
|
106
|
+
}
|
|
107
|
+
// Determine overlapping operations
|
|
108
|
+
const { fullyOverlapping, partiallyOverlapping, notOverlapping, } = this.getOverlappingOperations(operation, expressionVariables);
|
|
109
|
+
const joins = [];
|
|
110
|
+
this.logDebug(context, `Push down filter across join entries with ${fullyOverlapping.length} fully overlapping, ${partiallyOverlapping.length} partially overlapping, and ${notOverlapping.length} not overlapping`);
|
|
111
|
+
if (fullyOverlapping.length > 0) {
|
|
112
|
+
joins.push(factory.createJoin(fullyOverlapping
|
|
113
|
+
.map(input => this.filterPushdown(expression, expressionVariables, input, factory, context))));
|
|
114
|
+
}
|
|
115
|
+
if (partiallyOverlapping.length > 0) {
|
|
116
|
+
joins.push(factory.createFilter(factory.createJoin(partiallyOverlapping, false), expression));
|
|
117
|
+
}
|
|
118
|
+
if (notOverlapping.length > 0) {
|
|
119
|
+
joins.push(...notOverlapping);
|
|
120
|
+
}
|
|
121
|
+
return joins.length === 1 ? joins[0] : factory.createJoin(joins);
|
|
122
|
+
}
|
|
123
|
+
case sparqlalgebrajs_1.Algebra.types.NOP:
|
|
124
|
+
return operation;
|
|
125
|
+
case sparqlalgebrajs_1.Algebra.types.PROJECT:
|
|
126
|
+
// Push down if variables overlap
|
|
127
|
+
if (this.variablesIntersect(operation.variables, expressionVariables)) {
|
|
128
|
+
return factory.createProject(this.filterPushdown(expression, expressionVariables, operation.input, factory, context), operation.variables);
|
|
129
|
+
}
|
|
130
|
+
// Void expression otherwise
|
|
131
|
+
return operation;
|
|
132
|
+
case sparqlalgebrajs_1.Algebra.types.UNION: {
|
|
133
|
+
// Determine overlapping operations
|
|
134
|
+
const { fullyOverlapping, partiallyOverlapping, notOverlapping, } = this.getOverlappingOperations(operation, expressionVariables);
|
|
135
|
+
const unions = [];
|
|
136
|
+
this.logDebug(context, `Push down filter across union entries with ${fullyOverlapping.length} fully overlapping, ${partiallyOverlapping.length} partially overlapping, and ${notOverlapping.length} not overlapping`);
|
|
137
|
+
if (fullyOverlapping.length > 0) {
|
|
138
|
+
unions.push(factory.createUnion(fullyOverlapping
|
|
139
|
+
.map(input => this.filterPushdown(expression, expressionVariables, input, factory, context))));
|
|
140
|
+
}
|
|
141
|
+
if (partiallyOverlapping.length > 0) {
|
|
142
|
+
unions.push(factory.createFilter(factory.createUnion(partiallyOverlapping, false), expression));
|
|
143
|
+
}
|
|
144
|
+
if (notOverlapping.length > 0) {
|
|
145
|
+
unions.push(...notOverlapping);
|
|
146
|
+
}
|
|
147
|
+
return unions.length === 1 ? unions[0] : factory.createUnion(unions);
|
|
148
|
+
}
|
|
149
|
+
case sparqlalgebrajs_1.Algebra.types.VALUES:
|
|
150
|
+
// Only keep filter if it overlaps with the variables
|
|
151
|
+
if (this.variablesIntersect(operation.variables, expressionVariables)) {
|
|
152
|
+
return factory.createFilter(operation, expression);
|
|
153
|
+
}
|
|
154
|
+
return operation;
|
|
155
|
+
case sparqlalgebrajs_1.Algebra.types.LEFT_JOIN:
|
|
156
|
+
case sparqlalgebrajs_1.Algebra.types.MINUS:
|
|
157
|
+
case sparqlalgebrajs_1.Algebra.types.ALT:
|
|
158
|
+
case sparqlalgebrajs_1.Algebra.types.ASK:
|
|
159
|
+
case sparqlalgebrajs_1.Algebra.types.BGP:
|
|
160
|
+
case sparqlalgebrajs_1.Algebra.types.CONSTRUCT:
|
|
161
|
+
case sparqlalgebrajs_1.Algebra.types.DESCRIBE:
|
|
162
|
+
case sparqlalgebrajs_1.Algebra.types.DISTINCT:
|
|
163
|
+
case sparqlalgebrajs_1.Algebra.types.EXPRESSION:
|
|
164
|
+
case sparqlalgebrajs_1.Algebra.types.FROM:
|
|
165
|
+
case sparqlalgebrajs_1.Algebra.types.GRAPH:
|
|
166
|
+
case sparqlalgebrajs_1.Algebra.types.GROUP:
|
|
167
|
+
case sparqlalgebrajs_1.Algebra.types.INV:
|
|
168
|
+
case sparqlalgebrajs_1.Algebra.types.LINK:
|
|
169
|
+
case sparqlalgebrajs_1.Algebra.types.NPS:
|
|
170
|
+
case sparqlalgebrajs_1.Algebra.types.ONE_OR_MORE_PATH:
|
|
171
|
+
case sparqlalgebrajs_1.Algebra.types.ORDER_BY:
|
|
172
|
+
case sparqlalgebrajs_1.Algebra.types.PATTERN:
|
|
173
|
+
case sparqlalgebrajs_1.Algebra.types.REDUCED:
|
|
174
|
+
case sparqlalgebrajs_1.Algebra.types.SEQ:
|
|
175
|
+
case sparqlalgebrajs_1.Algebra.types.SERVICE:
|
|
176
|
+
case sparqlalgebrajs_1.Algebra.types.SLICE:
|
|
177
|
+
case sparqlalgebrajs_1.Algebra.types.PATH:
|
|
178
|
+
case sparqlalgebrajs_1.Algebra.types.ZERO_OR_MORE_PATH:
|
|
179
|
+
case sparqlalgebrajs_1.Algebra.types.ZERO_OR_ONE_PATH:
|
|
180
|
+
case sparqlalgebrajs_1.Algebra.types.COMPOSITE_UPDATE:
|
|
181
|
+
case sparqlalgebrajs_1.Algebra.types.DELETE_INSERT:
|
|
182
|
+
case sparqlalgebrajs_1.Algebra.types.LOAD:
|
|
183
|
+
case sparqlalgebrajs_1.Algebra.types.CLEAR:
|
|
184
|
+
case sparqlalgebrajs_1.Algebra.types.CREATE:
|
|
185
|
+
case sparqlalgebrajs_1.Algebra.types.DROP:
|
|
186
|
+
case sparqlalgebrajs_1.Algebra.types.ADD:
|
|
187
|
+
case sparqlalgebrajs_1.Algebra.types.MOVE:
|
|
188
|
+
case sparqlalgebrajs_1.Algebra.types.COPY:
|
|
189
|
+
// Operations that do not support pushing down
|
|
190
|
+
// Left-join and minus might be possible to support in the future.
|
|
191
|
+
return factory.createFilter(operation, expression);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Check if there is an overlap between the two given lists of variables.
|
|
196
|
+
* @param varsA A list of variables.
|
|
197
|
+
* @param varsB A list of variables.
|
|
198
|
+
*/
|
|
199
|
+
variablesIntersect(varsA, varsB) {
|
|
200
|
+
return varsA.some(varA => varsB.some(varB => varA.equals(varB)));
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Check if all variables from the first list are included in the second list.
|
|
204
|
+
* The second list may contain other variables as well.
|
|
205
|
+
* @param varsNeedles A list of variables to search for.
|
|
206
|
+
* @param varsHaystack A list of variables to search in.
|
|
207
|
+
*/
|
|
208
|
+
variablesSubSetOf(varsNeedles, varsHaystack) {
|
|
209
|
+
return varsNeedles.length <= varsHaystack.length &&
|
|
210
|
+
varsNeedles.every(varA => varsHaystack.some(varB => varA.equals(varB)));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.ActorOptimizeQueryOperationFilterPushdown = ActorOptimizeQueryOperationFilterPushdown;
|
|
214
|
+
//# sourceMappingURL=ActorOptimizeQueryOperationFilterPushdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActorOptimizeQueryOperationFilterPushdown.js","sourceRoot":"","sources":["ActorOptimizeQueryOperationFilterPushdown.ts"],"names":[],"mappings":";;;AAEA,yFAAqF;AAIrF,yCAAsC;AAEtC,qDAAgD;AAEhD;;GAEG;AACH,MAAa,yCAA0C,SAAQ,0DAA2B;IACxF,YAAmB,IAAsC;QACvD,KAAK,CAAC,IAAI,CAAC,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;YACpC,KAAK,yBAAO,CAAC,KAAK,CAAC,aAAa,CAAC;YACjC,KAAK,yBAAO,CAAC,KAAK,CAAC,IAAI,CAAC;YACxB,KAAK,yBAAO,CAAC,KAAK,CAAC,KAAK,CAAC;YACzB,KAAK,yBAAO,CAAC,KAAK,CAAC,MAAM,CAAC;YAC1B,KAAK,yBAAO,CAAC,KAAK,CAAC,IAAI,CAAC;YACxB,KAAK,yBAAO,CAAC,KAAK,CAAC,GAAG,CAAC;YACvB,KAAK,yBAAO,CAAC,KAAK,CAAC,IAAI,CAAC;YACxB,KAAK,yBAAO,CAAC,KAAK,CAAC,IAAI;gBACrB,8CAA8C;gBAC9C,kEAAkE;gBAClE,OAAO,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;SACtD;IACH,CAAC;IAED;;;;OAIG;IACI,kBAAkB,CAAC,KAAqB,EAAE,KAAqB;QACpE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACnE,CAAC;IAED;;;;;OAKG;IACI,iBAAiB,CAAC,WAA2B,EAAE,YAA4B;QAChF,OAAO,WAAW,CAAC,MAAM,IAAI,YAAY,CAAC,MAAM;YAC9C,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC;CACF;AApPD,8FAoPC","sourcesContent":["import type { IActionOptimizeQueryOperation,\n IActorOptimizeQueryOperationOutput, IActorOptimizeQueryOperationArgs } from '@comunica/bus-optimize-query-operation';\nimport { ActorOptimizeQueryOperation } from '@comunica/bus-optimize-query-operation';\nimport type { IActorTest } from '@comunica/core';\nimport type { IActionContext } from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport { uniqTerms } from 'rdf-terms';\nimport type { Factory } from 'sparqlalgebrajs';\nimport { Algebra, Util } from 'sparqlalgebrajs';\n\n/**\n * A comunica Filter Pushdown Optimize Query Operation Actor.\n */\nexport class ActorOptimizeQueryOperationFilterPushdown extends ActorOptimizeQueryOperation {\n public constructor(args: IActorOptimizeQueryOperationArgs) {\n super(args);\n }\n\n public async test(action: IActionOptimizeQueryOperation): Promise<IActorTest> {\n return true;\n }\n\n public async run(action: IActionOptimizeQueryOperation): Promise<IActorOptimizeQueryOperationOutput> {\n // eslint-disable-next-line @typescript-eslint/no-this-alias,consistent-this\n const self = this;\n const operation = Util.mapOperation(action.operation, {\n filter(op: Algebra.Filter, factory: Factory) {\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 = self.getExpressionVariables(op.expression);\n return {\n recurse: true,\n result: self.filterPushdown(op.expression, variables, op.input, factory, action.context),\n };\n },\n });\n return { operation, context: action.context };\n }\n\n /**\n * Get all variables inside the given expression.\n * @param expression An expression.\n * @return An array of variables, or undefined if the expression is unsupported for pushdown.\n */\n public getExpressionVariables(expression: Algebra.Expression): RDF.Variable[] {\n switch (expression.expressionType) {\n case Algebra.expressionTypes.AGGREGATE:\n case Algebra.expressionTypes.WILDCARD:\n throw new Error(`Getting expression variables is not supported for ${expression.expressionType}`);\n case Algebra.expressionTypes.EXISTENCE:\n return Util.inScopeVariables(expression.input);\n case Algebra.expressionTypes.NAMED:\n return [];\n case Algebra.expressionTypes.OPERATOR:\n return uniqTerms(expression.args.flatMap(arg => this.getExpressionVariables(arg)!));\n case Algebra.expressionTypes.TERM:\n if (expression.term.termType === 'Variable') {\n return [ expression.term ];\n }\n return [];\n }\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 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 ): Algebra.Operation {\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 factory.createExtend(\n this.filterPushdown(expression, expressionVariables, operation.input, factory, context),\n operation.variable,\n operation.expression,\n );\n }\n return factory.createFilter(operation, expression);\n case Algebra.types.FILTER:\n // Always pass\n return factory.createFilter(\n this.filterPushdown(expression, expressionVariables, operation.input, factory, context),\n operation.expression,\n );\n case Algebra.types.JOIN: {\n // Don't push down for empty join\n if (operation.input.length === 0) {\n return 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 this.logDebug(context, `Push down filter across join entries with ${fullyOverlapping.length} fully overlapping, ${partiallyOverlapping.length} partially overlapping, and ${notOverlapping.length} not overlapping`);\n if (fullyOverlapping.length > 0) {\n joins.push(factory.createJoin(fullyOverlapping\n .map(input => this.filterPushdown(expression, expressionVariables, input, factory, context))));\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 return joins.length === 1 ? joins[0] : factory.createJoin(joins);\n }\n case Algebra.types.NOP:\n return operation;\n case Algebra.types.PROJECT:\n // Push down if variables overlap\n if (this.variablesIntersect(operation.variables, expressionVariables)) {\n return factory.createProject(\n this.filterPushdown(expression, expressionVariables, operation.input, factory, context),\n operation.variables,\n );\n }\n // Void expression otherwise\n return 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 this.logDebug(context, `Push down filter across union entries with ${fullyOverlapping.length} fully overlapping, ${partiallyOverlapping.length} partially overlapping, and ${notOverlapping.length} not overlapping`);\n if (fullyOverlapping.length > 0) {\n unions.push(factory.createUnion(fullyOverlapping\n .map(input => this.filterPushdown(expression, expressionVariables, input, factory, context))));\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 return 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 factory.createFilter(operation, expression);\n }\n return operation;\n case Algebra.types.LEFT_JOIN:\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.PATTERN:\n case Algebra.types.REDUCED:\n case Algebra.types.SEQ:\n case Algebra.types.SERVICE:\n case Algebra.types.SLICE:\n case Algebra.types.PATH:\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 factory.createFilter(operation, expression);\n }\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"]}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ActorOptimizeQueryOperationFilterPushdown';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ActorOptimizeQueryOperationFilterPushdown"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8EAA4D","sourcesContent":["export * from './ActorOptimizeQueryOperationFilterPushdown';\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@comunica/actor-optimize-query-operation-filter-pushdown",
|
|
3
|
+
"version": "3.0.1-alpha.43.0",
|
|
4
|
+
"description": "A filter-pushdown optimize-query-operation actor",
|
|
5
|
+
"lsd:module": true,
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"typings": "lib/index",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/comunica/comunica.git",
|
|
11
|
+
"directory": "packages/actor-optimize-query-operation-filter-pushdown"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"keywords": [
|
|
18
|
+
"comunica",
|
|
19
|
+
"actor",
|
|
20
|
+
"optimize-query-operation",
|
|
21
|
+
"filter-pushdown"
|
|
22
|
+
],
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/comunica/comunica/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://comunica.dev/",
|
|
28
|
+
"files": [
|
|
29
|
+
"components",
|
|
30
|
+
"lib/**/*.d.ts",
|
|
31
|
+
"lib/**/*.js",
|
|
32
|
+
"lib/**/*.js.map"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@comunica/bus-optimize-query-operation": "3.0.1-alpha.43.0",
|
|
36
|
+
"@comunica/core": "3.0.1-alpha.43.0",
|
|
37
|
+
"@comunica/types": "3.0.1-alpha.43.0",
|
|
38
|
+
"@rdfjs/types": "*",
|
|
39
|
+
"rdf-terms": "^1.11.0",
|
|
40
|
+
"sparqlalgebrajs": "^4.3.3"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "npm run build:ts && npm run build:components",
|
|
44
|
+
"build:ts": "node \"../../node_modules/typescript/bin/tsc\"",
|
|
45
|
+
"build:components": "componentsjs-generator"
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "d11e44cf07d4699f9d2c51d5851b5ed443de1997"
|
|
48
|
+
}
|