@comunica/actor-optimize-query-operation-leftjoin-expression-pushdown 4.4.2-alpha.49.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,8 +4,8 @@ exports.ActorOptimizeQueryOperationLeftjoinExpressionPushdown = void 0;
|
|
|
4
4
|
const bus_optimize_query_operation_1 = require("@comunica/bus-optimize-query-operation");
|
|
5
5
|
const context_entries_1 = require("@comunica/context-entries");
|
|
6
6
|
const core_1 = require("@comunica/core");
|
|
7
|
-
const utils_algebra_1 = require("@comunica/utils-algebra");
|
|
8
7
|
const utils_query_operation_1 = require("@comunica/utils-query-operation");
|
|
8
|
+
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
|
|
9
9
|
/**
|
|
10
10
|
* A comunica LeftJoin Expression Pushdown Optimize Query Operation Actor.
|
|
11
11
|
*/
|
|
@@ -18,34 +18,40 @@ class ActorOptimizeQueryOperationLeftjoinExpressionPushdown extends bus_optimize
|
|
|
18
18
|
}
|
|
19
19
|
async run(action) {
|
|
20
20
|
const dataFactory = action.context.getSafe(context_entries_1.KeysInitQuery.dataFactory);
|
|
21
|
-
const algebraFactory = new
|
|
21
|
+
const algebraFactory = new sparqlalgebrajs_1.Factory(dataFactory);
|
|
22
22
|
let operation = action.operation;
|
|
23
23
|
// eslint-disable-next-line ts/no-this-alias
|
|
24
24
|
const self = this;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
if (!intersectLeft && intersectRight) {
|
|
41
|
-
self.logDebug(action.context, `Pushed down optional expression to right-hand operator`);
|
|
42
|
-
return algebraFactory.createLeftJoin(op.input[0], algebraFactory.createFilter(op.input[1], op.expression));
|
|
43
|
-
}
|
|
25
|
+
operation = sparqlalgebrajs_1.Util.mapOperation(operation, {
|
|
26
|
+
leftjoin(op, factory) {
|
|
27
|
+
// Try to push the expression to either the left or right if it exclusively overlaps with just one of them.
|
|
28
|
+
if (op.expression) {
|
|
29
|
+
const variablesExpression = (0, utils_query_operation_1.getExpressionVariables)(op.expression);
|
|
30
|
+
const variablesLeft = sparqlalgebrajs_1.Util.inScopeVariables(op.input[0]);
|
|
31
|
+
const variablesRight = sparqlalgebrajs_1.Util.inScopeVariables(op.input[1]);
|
|
32
|
+
const intersectLeft = self.variablesIntersect(variablesExpression, variablesLeft);
|
|
33
|
+
const intersectRight = self.variablesIntersect(variablesExpression, variablesRight);
|
|
34
|
+
if (intersectLeft && !intersectRight) {
|
|
35
|
+
self.logDebug(action.context, `Pushed down optional expression to left-hand operator`);
|
|
36
|
+
return {
|
|
37
|
+
recurse: true,
|
|
38
|
+
result: factory.createLeftJoin(factory.createFilter(op.input[0], op.expression), op.input[1]),
|
|
39
|
+
};
|
|
44
40
|
}
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
if (!intersectLeft && intersectRight) {
|
|
42
|
+
self.logDebug(action.context, `Pushed down optional expression to right-hand operator`);
|
|
43
|
+
return {
|
|
44
|
+
recurse: true,
|
|
45
|
+
result: factory.createLeftJoin(op.input[0], factory.createFilter(op.input[1], op.expression)),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
recurse: true,
|
|
51
|
+
result: op,
|
|
52
|
+
};
|
|
47
53
|
},
|
|
48
|
-
});
|
|
54
|
+
}, algebraFactory);
|
|
49
55
|
return { operation, context: action.context };
|
|
50
56
|
}
|
|
51
57
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorOptimizeQueryOperationLeftjoinExpressionPushdown.js","sourceRoot":"","sources":["ActorOptimizeQueryOperationLeftjoinExpressionPushdown.ts"],"names":[],"mappings":";;;AAKA,yFAAqF;AACrF,+DAA0D;AAE1D,yCAA8C;AAE9C,
|
|
1
|
+
{"version":3,"file":"ActorOptimizeQueryOperationLeftjoinExpressionPushdown.js","sourceRoot":"","sources":["ActorOptimizeQueryOperationLeftjoinExpressionPushdown.ts"],"names":[],"mappings":";;;AAKA,yFAAqF;AACrF,+DAA0D;AAE1D,yCAA8C;AAE9C,2EAAyE;AAGzE,qDAAgD;AAEhD;;GAEG;AACH,MAAa,qDAAsD,SAAQ,0DAA2B;IACpG,YAAmB,IAAsC;QACvD,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;QAClB,SAAS,GAAG,sBAAI,CAAC,YAAY,CAAC,SAAS,EAAE;YACvC,QAAQ,CAAC,EAAoB,EAAE,OAAgB;gBAC7C,2GAA2G;gBAC3G,IAAI,EAAE,CAAC,UAAU,EAAE,CAAC;oBAClB,MAAM,mBAAmB,GAAG,IAAA,8CAAsB,EAAC,EAAE,CAAC,UAAU,CAAC,CAAC;oBAClE,MAAM,aAAa,GAAG,sBAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;oBACzD,MAAM,cAAc,GAAG,sBAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC1D,MAAM,aAAa,GAAG,IAAI,CAAC,kBAAkB,CAAC,mBAAm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C,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACnE,CAAC;CACF;AAjED,sHAiEC","sourcesContent":["import type {\n IActionOptimizeQueryOperation,\n IActorOptimizeQueryOperationOutput,\n IActorOptimizeQueryOperationArgs,\n} from '@comunica/bus-optimize-query-operation';\nimport { ActorOptimizeQueryOperation } from '@comunica/bus-optimize-query-operation';\nimport { KeysInitQuery } from '@comunica/context-entries';\nimport type { TestResult, IActorTest } from '@comunica/core';\nimport { passTestVoid } from '@comunica/core';\nimport type { ComunicaDataFactory } from '@comunica/types';\nimport { getExpressionVariables } from '@comunica/utils-query-operation';\nimport type * as RDF from '@rdfjs/types';\nimport type { Algebra } from 'sparqlalgebrajs';\nimport { Factory, Util } from 'sparqlalgebrajs';\n\n/**\n * A comunica LeftJoin Expression Pushdown Optimize Query Operation Actor.\n */\nexport class ActorOptimizeQueryOperationLeftjoinExpressionPushdown extends ActorOptimizeQueryOperation {\n public constructor(args: IActorOptimizeQueryOperationArgs) {\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 operation = Util.mapOperation(operation, {\n leftjoin(op: Algebra.LeftJoin, factory: Factory) {\n // Try to push the expression to either the left or right if it exclusively overlaps with just one of them.\n if (op.expression) {\n const variablesExpression = getExpressionVariables(op.expression);\n const variablesLeft = Util.inScopeVariables(op.input[0]);\n const variablesRight = Util.inScopeVariables(op.input[1]);\n const intersectLeft = self.variablesIntersect(variablesExpression, variablesLeft);\n const intersectRight = self.variablesIntersect(variablesExpression, variablesRight);\n if (intersectLeft && !intersectRight) {\n self.logDebug(action.context, `Pushed down optional expression to left-hand operator`);\n return {\n recurse: true,\n result: factory.createLeftJoin(\n factory.createFilter(op.input[0], op.expression),\n op.input[1],\n ),\n };\n }\n if (!intersectLeft && intersectRight) {\n self.logDebug(action.context, `Pushed down optional expression to right-hand operator`);\n return {\n recurse: true,\n result: factory.createLeftJoin(\n op.input[0],\n factory.createFilter(op.input[1], op.expression),\n ),\n };\n }\n }\n\n return {\n recurse: true,\n result: op,\n };\n },\n }, algebraFactory);\n\n return { operation, context: action.context };\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-optimize-query-operation-leftjoin-expression-pushdown",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "A leftjoin-expression-pushdown optimize-query-operation actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,13 +41,13 @@
|
|
|
41
41
|
"build:components": "componentsjs-generator"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@comunica/bus-optimize-query-operation": "4.
|
|
45
|
-
"@comunica/context-entries": "4.
|
|
46
|
-
"@comunica/core": "4.
|
|
47
|
-
"@comunica/types": "4.
|
|
48
|
-
"@comunica/utils-
|
|
49
|
-
"@
|
|
50
|
-
"
|
|
44
|
+
"@comunica/bus-optimize-query-operation": "^4.5.0",
|
|
45
|
+
"@comunica/context-entries": "^4.5.0",
|
|
46
|
+
"@comunica/core": "^4.5.0",
|
|
47
|
+
"@comunica/types": "^4.5.0",
|
|
48
|
+
"@comunica/utils-query-operation": "^4.5.0",
|
|
49
|
+
"@rdfjs/types": "*",
|
|
50
|
+
"sparqlalgebrajs": "^5.0.2"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "2bcd98c387a021fc5c08d375793c205ca3d1bf0d"
|
|
53
53
|
}
|