@comunica/actor-optimize-query-operation-group-sources 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/ActorOptimizeQueryOperationGroupSources.jsonld +15 -15
- package/components/components.jsonld +1 -1
- package/components/context.jsonld +1 -1
- package/lib/ActorOptimizeQueryOperationGroupSources.d.ts +1 -1
- package/lib/ActorOptimizeQueryOperationGroupSources.js +24 -24
- package/lib/ActorOptimizeQueryOperationGroupSources.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 +8 -8
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-group-sources/^
|
|
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-group-sources/^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-group-sources",
|
|
8
8
|
"components": [
|
|
@@ -35,37 +35,37 @@
|
|
|
35
35
|
"genericTypeInstances": [
|
|
36
36
|
{
|
|
37
37
|
"@type": "ParameterRangeGenericTypeReference",
|
|
38
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
38
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
41
|
"@type": "ParameterRangeGenericTypeReference",
|
|
42
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
42
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
"@type": "ParameterRangeGenericTypeReference",
|
|
46
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
46
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
49
|
"@type": "ParameterRangeGenericTypeReference",
|
|
50
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
50
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
51
51
|
}
|
|
52
52
|
]
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
"@type": "ParameterRangeGenericTypeReference",
|
|
56
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
56
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
"@type": "ParameterRangeGenericTypeReference",
|
|
60
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
60
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
61
61
|
},
|
|
62
62
|
{
|
|
63
63
|
"@type": "ParameterRangeGenericTypeReference",
|
|
64
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
64
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
"@type": "ParameterRangeGenericTypeReference",
|
|
68
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
68
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
69
69
|
}
|
|
70
70
|
]
|
|
71
71
|
},
|
|
@@ -102,19 +102,19 @@
|
|
|
102
102
|
"genericTypeInstances": [
|
|
103
103
|
{
|
|
104
104
|
"@type": "ParameterRangeGenericTypeReference",
|
|
105
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
105
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
106
106
|
},
|
|
107
107
|
{
|
|
108
108
|
"@type": "ParameterRangeGenericTypeReference",
|
|
109
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
109
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
110
110
|
},
|
|
111
111
|
{
|
|
112
112
|
"@type": "ParameterRangeGenericTypeReference",
|
|
113
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
113
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
114
114
|
},
|
|
115
115
|
{
|
|
116
116
|
"@type": "ParameterRangeGenericTypeReference",
|
|
117
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
117
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
118
118
|
}
|
|
119
119
|
]
|
|
120
120
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-group-sources/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-group-sources/^5.0.0/components/context.jsonld"
|
|
4
4
|
],
|
|
5
5
|
"@id": "npmd:@comunica/actor-optimize-query-operation-group-sources",
|
|
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
|
-
"caoqogs": "npmd:@comunica/actor-optimize-query-operation-group-sources/^
|
|
6
|
+
"caoqogs": "npmd:@comunica/actor-optimize-query-operation-group-sources/^5.0.0/",
|
|
7
7
|
"ActorOptimizeQueryOperationGroupSources": {
|
|
8
8
|
"@id": "caoqogs:components/ActorOptimizeQueryOperationGroupSources.jsonld#ActorOptimizeQueryOperationGroupSources",
|
|
9
9
|
"@prefix": true,
|
|
@@ -2,7 +2,7 @@ import type { IActionOptimizeQueryOperation, IActorOptimizeQueryOperationOutput,
|
|
|
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 { Algebra } from '
|
|
5
|
+
import { Algebra } from '@comunica/utils-algebra';
|
|
6
6
|
/**
|
|
7
7
|
* A comunica Group Sources Optimize Query Operation Actor.
|
|
8
8
|
*/
|
|
@@ -4,8 +4,8 @@ exports.ActorOptimizeQueryOperationGroupSources = 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
|
-
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
|
|
9
9
|
/**
|
|
10
10
|
* A comunica Group Sources Optimize Query Operation Actor.
|
|
11
11
|
*/
|
|
@@ -31,7 +31,7 @@ class ActorOptimizeQueryOperationGroupSources extends bus_optimize_query_operati
|
|
|
31
31
|
*/
|
|
32
32
|
async groupOperation(operation, context) {
|
|
33
33
|
const dataFactory = context.getSafe(context_entries_1.KeysInitQuery.dataFactory);
|
|
34
|
-
const algebraFactory = new
|
|
34
|
+
const algebraFactory = new utils_algebra_1.AlgebraFactory(dataFactory);
|
|
35
35
|
// Return operation as-is if the operation already has a single source, or if the operation has no children.
|
|
36
36
|
if ((0, utils_query_operation_1.getOperationSource)(operation) ?? !('input' in operation)) {
|
|
37
37
|
return operation;
|
|
@@ -60,30 +60,30 @@ class ActorOptimizeQueryOperationGroupSources extends bus_optimize_query_operati
|
|
|
60
60
|
}
|
|
61
61
|
// If the number of clusters is equal to the number of original inputs, do nothing.
|
|
62
62
|
if (clusters.length === inputs.length) {
|
|
63
|
-
|
|
63
|
+
const result = { ...operation, input: inputs };
|
|
64
|
+
return result;
|
|
64
65
|
}
|
|
65
66
|
// If we have multiple clusters, created nested multi-operations
|
|
66
67
|
let multiFactoryMethod;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
throw new Error(`Unsupported operation '${operation.type}' detected while grouping sources`);
|
|
68
|
+
if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.JOIN)) {
|
|
69
|
+
multiFactoryMethod = algebraFactory.createJoin.bind(algebraFactory);
|
|
70
|
+
}
|
|
71
|
+
else if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.UNION)) {
|
|
72
|
+
multiFactoryMethod = algebraFactory.createUnion.bind(algebraFactory);
|
|
73
|
+
}
|
|
74
|
+
else if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.ALT)) {
|
|
75
|
+
multiFactoryMethod = algebraFactory.createAlt.bind(algebraFactory);
|
|
76
|
+
}
|
|
77
|
+
else if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.SEQ)) {
|
|
78
|
+
multiFactoryMethod = algebraFactory.createSeq.bind(algebraFactory);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// While LeftJoin and Minus are also multi-operations,
|
|
82
|
+
// these can never occur because they only have 2 inputs,
|
|
83
|
+
// so these cases will always be captured by one of the 2 if-cases above
|
|
84
|
+
// (clusters.length === 1 or clusters.length === input.length)
|
|
85
|
+
// In all other cases, error
|
|
86
|
+
throw new Error(`Unsupported operation '${operation.type}' detected while grouping sources`);
|
|
87
87
|
}
|
|
88
88
|
return await this.groupOperationMulti(clusters, multiFactoryMethod, context);
|
|
89
89
|
}
|
|
@@ -167,7 +167,7 @@ class ActorOptimizeQueryOperationGroupSources extends bus_optimize_query_operati
|
|
|
167
167
|
const extensionFunctions = context.get(context_entries_1.KeysInitQuery.extensionFunctions);
|
|
168
168
|
const expression = operation.expression;
|
|
169
169
|
return !extensionFunctions ||
|
|
170
|
-
expression
|
|
170
|
+
!(expression && (0, utils_algebra_1.isKnownSubType)(expression, utils_algebra_1.Algebra.ExpressionTypes.NAMED)) ||
|
|
171
171
|
!(expression?.name.value in extensionFunctions) ||
|
|
172
172
|
(0, utils_query_operation_1.doesShapeAcceptOperation)(shape, expression, { wildcardAcceptAllExtensionFunctions });
|
|
173
173
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorOptimizeQueryOperationGroupSources.js","sourceRoot":"","sources":["ActorOptimizeQueryOperationGroupSources.ts"],"names":[],"mappings":";;;AAKA,yFAAqF;AACrF,+DAA0D;AAE1D,yCAAwD;AAExD,2EAKyC;AACzC,qDAAmD;AAEnD;;GAEG;AACH,MAAa,uCAAwC,SAAQ,0DAA2B;IACtF,YAAmB,IAAsC;QACvD,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,MAAqC;QACrD,IAAI,IAAA,0CAAkB,EAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YACzC,OAAO,IAAA,eAAQ,EAAC,SAAS,IAAI,CAAC,IAAI,kDAAkD,CAAC,CAAC;QACxF,CAAC;QACD,OAAO,IAAA,mBAAY,GAAE,CAAC;IACxB,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,MAAqC;QACpD,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;IAC7G,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,cAAc,CAAC,SAA4B,EAAE,OAAuB;QAC/E,MAAM,WAAW,GAAwB,OAAO,CAAC,OAAO,CAAC,+BAAa,C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OAAO,CAAC,GAAG,CAAC,+BAAa,CAAC,gCAAgC,CAAC,CAAC;QACxG,IAAI,IAAA,gDAAwB,EAAC,KAAK,EAAE,SAAS,EAAE,EAAE,mCAAmC,EAAE,CAAC,EAAE,CAAC;YACxF,MAAM,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,+BAAa,CAAC,kBAAkB,CAAC,CAAC;YACzE,MAAM,UAAU,GAAmC,SAAS,CAAC,UAAU,CAAC;YACxE,OAAO,CAAC,kBAAkB;gBACxB,UAAU,EAAE,cAAc,KAAK,yBAAO,CAAC,eAAe,CAAC,KAAK;gBAC5D,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,IAAI,kBAAkB,CAAC;gBAC/C,IAAA,gDAAwB,EAAC,KAAK,EAAE,UAAU,EAAE,EAAE,mCAAmC,EAAE,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AApMD,0FAoMC","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 { IActorTest, TestResult } from '@comunica/core';\nimport { failTest, passTestVoid } from '@comunica/core';\nimport type { ComunicaDataFactory, FragmentSelectorShape, IActionContext, IQuerySourceWrapper } from '@comunica/types';\nimport {\n assignOperationSource,\n doesShapeAcceptOperation,\n getOperationSource,\n removeOperationSource,\n} from '@comunica/utils-query-operation';\nimport { Algebra, Factory } from 'sparqlalgebrajs';\n\n/**\n * A comunica Group Sources Optimize Query Operation Actor.\n */\nexport class ActorOptimizeQueryOperationGroupSources extends ActorOptimizeQueryOperation {\n public constructor(args: IActorOptimizeQueryOperationArgs) {\n super(args);\n }\n\n public async test(action: IActionOptimizeQueryOperation): Promise<TestResult<IActorTest>> {\n if (getOperationSource(action.operation)) {\n return failTest(`Actor ${this.name} does not work with top-level operation sources.`);\n }\n return passTestVoid();\n }\n\n public async run(action: IActionOptimizeQueryOperation): Promise<IActorOptimizeQueryOperationOutput> {\n return { operation: await this.groupOperation(action.operation, action.context), context: action.context };\n }\n\n /**\n * Group operations belonging to the same source together, only if that source accepts the grouped operations.\n * This grouping will be done recursively for the whole operation tree.\n * Operations annotated with sources are considered leaves in the tree.\n * @param operation An operation to group.\n * @param context The action context.\n */\n public async groupOperation(operation: Algebra.Operation, context: IActionContext): Promise<Algebra.Operation> {\n const dataFactory: ComunicaDataFactory = context.getSafe(KeysInitQuery.dataFactory);\n const algebraFactory = new Factory(dataFactory);\n\n // Return operation as-is if the operation already has a single source, or if the operation has no children.\n if (getOperationSource(operation) ?? !('input' in operation)) {\n return operation;\n }\n\n // If operation has a single input, move source annotation upwards if the source can handle it.\n if (!Array.isArray(operation.input)) {\n const groupedInput = await this.groupOperation(operation.input, context);\n if (groupedInput.metadata?.scopedSource) {\n const source: IQuerySourceWrapper = <IQuerySourceWrapper> getOperationSource(groupedInput);\n operation = await this.moveSourceAnnotationUpwardsIfPossible(operation, [ groupedInput ], source, context);\n }\n return <Algebra.Operation> { ...operation, input: groupedInput };\n }\n\n // If operation has multiple inputs, cluster source annotations.\n const inputs: Algebra.Operation[] = await Promise.all(operation.input\n .map(subInput => this.groupOperation(subInput, context)));\n const clusters = this.clusterOperationsWithEqualSources(inputs);\n\n // If we just have a single cluster, move the source annotation upwards\n if (clusters.length === 1) {\n const newInputs = clusters[0];\n const source = getOperationSource(clusters[0][0])!;\n return <Algebra.Operation> {\n ...await this.moveSourceAnnotationUpwardsIfPossible(operation, newInputs, source, context),\n input: newInputs,\n };\n }\n\n // If the number of clusters is equal to the number of original inputs, do nothing.\n if (clusters.length === inputs.length) {\n return <Algebra.Operation> { ...operation, input: inputs };\n }\n\n // If we have multiple clusters, created nested multi-operations\n let multiFactoryMethod: (children: Algebra.Operation[], flatten: boolean) => Algebra.Operation;\n switch (operation.type) {\n case Algebra.types.JOIN:\n multiFactoryMethod = algebraFactory.createJoin.bind(algebraFactory);\n break;\n case Algebra.types.UNION:\n multiFactoryMethod = algebraFactory.createUnion.bind(algebraFactory);\n break;\n case Algebra.types.ALT:\n multiFactoryMethod = <any> algebraFactory.createAlt.bind(algebraFactory);\n break;\n case Algebra.types.SEQ:\n multiFactoryMethod = <any> algebraFactory.createSeq.bind(algebraFactory);\n break;\n default:\n // While LeftJoin and Minus are also multi-operations,\n // these can never occur because they only have 2 inputs,\n // so these cases will always be captured by one of the 2 if-cases above\n // (clusters.length === 1 or clusters.length === input.length)\n\n // In all other cases, error\n throw new Error(`Unsupported operation '${operation.type}' detected while grouping sources`);\n }\n return await this.groupOperationMulti(clusters, multiFactoryMethod, context);\n }\n\n protected async groupOperationMulti(\n clusters: Algebra.Operation[][],\n factoryMethod: (children: Algebra.Operation[], flatten: boolean) => Algebra.Operation,\n context: IActionContext,\n ): Promise<Algebra.Operation> {\n let flatten = true;\n const nestedMerges = await Promise.all(clusters.map(async(cluster) => {\n const source = getOperationSource(cluster[0])!;\n const merged = await this\n .moveSourceAnnotationUpwardsIfPossible(factoryMethod(cluster, true), cluster, source, context);\n if (getOperationSource(merged)) {\n flatten = false;\n }\n return merged;\n }));\n return factoryMethod(nestedMerges, flatten);\n }\n\n /**\n * Cluster the given operations by equal source annotations.\n * @param operationsIn An array of operations to cluster.\n */\n public clusterOperationsWithEqualSources(operationsIn: Algebra.Operation[]): Algebra.Operation[][] {\n // Operations can have a source, or no source at all\n const sourceOperations: Map<IQuerySourceWrapper, Algebra.Operation[]> = new Map();\n const sourcelessOperations: Algebra.Operation[] = [];\n\n // Cluster by source\n for (const operation of operationsIn) {\n const source = getOperationSource(operation);\n if (source) {\n if (!sourceOperations.has(source)) {\n sourceOperations.set(source, []);\n }\n sourceOperations.get(source)!.push(operation);\n } else {\n sourcelessOperations.push(operation);\n }\n }\n\n // Return clusters\n const clusters: Algebra.Operation[][] = [];\n if (sourcelessOperations.length > 0) {\n clusters.push(sourcelessOperations);\n }\n for (const [ source, operations ] of sourceOperations.entries()) {\n clusters.push(operations\n .map(operation => assignOperationSource(operation, source)));\n }\n return clusters;\n }\n\n /**\n * If the given source accepts the grouped operation, annotate the grouped operation with the source,\n * and remove the source annotation from the seperate input operations.\n * Otherwise, return the grouped operation unchanged.\n * @param operation A grouped operation consisting of all given input operations.\n * @param inputs An array of operations that share the same source annotation.\n * @param source The common source.\n * @param context The action context.\n */\n public async moveSourceAnnotationUpwardsIfPossible<O extends Algebra.Operation>(\n operation: O,\n inputs: Algebra.Operation[],\n source: IQuerySourceWrapper | undefined,\n context: IActionContext,\n ): Promise<O> {\n if (source && this.isPossibleToMoveSourceAnnotationUpwards(\n operation,\n await source.source.getSelectorShape(context),\n context,\n )) {\n this.logDebug(context, `Hoist ${inputs.length} source-specific operations into a single ${operation.type} operation for ${source.source.toString()}`);\n operation = assignOperationSource(operation, source);\n for (const input of inputs) {\n removeOperationSource(input);\n }\n }\n return operation;\n }\n\n /**\n * Checks if it's possible to move the source annotation upwards using the following rules:\n * - If the shape doesn't accept the operation, then it's not possible.\n * - If it does and the operation does not contain extension functions or\n * comunica doesn't support them, then it's possible.\n * - If comunica does support them, then it's possible only if the shape accepts the extension function expressions.\n * @param operation A grouped operation consisting of all given input operations.\n * @param shape The common source's shape.\n * @param context The action context.\n */\n public isPossibleToMoveSourceAnnotationUpwards<O extends Algebra.Operation>(\n operation: O,\n shape: FragmentSelectorShape,\n context: IActionContext,\n ): boolean {\n const wildcardAcceptAllExtensionFunctions = context.get(KeysInitQuery.extensionFunctionsAlwaysPushdown);\n if (doesShapeAcceptOperation(shape, operation, { wildcardAcceptAllExtensionFunctions })) {\n const extensionFunctions = context.get(KeysInitQuery.extensionFunctions);\n const expression: Algebra.Expression | undefined = operation.expression;\n return !extensionFunctions ||\n expression?.expressionType !== Algebra.expressionTypes.NAMED ||\n !(expression?.name.value in extensionFunctions) ||\n doesShapeAcceptOperation(shape, expression, { wildcardAcceptAllExtensionFunctions });\n }\n return false;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ActorOptimizeQueryOperationGroupSources.js","sourceRoot":"","sources":["ActorOptimizeQueryOperationGroupSources.ts"],"names":[],"mappings":";;;AAKA,yFAAqF;AACrF,+DAA0D;AAE1D,yCAAwD;AAExD,2DAAoG;AACpG,2EAKyC;AAEzC;;GAEG;AACH,MAAa,uCAAwC,SAAQ,0DAA2B;IACtF,YAAmB,IAAsC;QACvD,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,MAAqC;QACrD,IAAI,IAAA,0CAAkB,EAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YACzC,OAAO,IAAA,eAAQ,EAAC,SAAS,IAAI,CAAC,IAAI,kDAAkD,CAAC,CAAC;QACxF,CAAC;QACD,OAAO,IAAA,mBAAY,GAAE,CAAC;IACxB,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,MAAqC;QACpD,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;IAC7G,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,cAAc,CAAC,SAA4B,EAAE,OAAuB;QAC/E,MAAM,WAAW,GAAwB,OAAO,CAAC,OAAO,CAAC,+BAAa,CAAC,WAAW,CAAC,CAAC;QACpF,MAAM,cAAc,GAAG,IAAI,8BAAc,CAAC,WAAW,CAAC,CAAC;QAEvD,4GAA4G;QAC5G,IAAI,IAAA,0CAAkB,EAAC,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,IAAI,SAAS,CAAC,EAAE,CAAC;YAC7D,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,+FAA+F;QAC/F,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,EAA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AAmC,EAAE,CAAC,EAAE,CAAC;YACxF,MAAM,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,+BAAa,CAAC,kBAAkB,CAAC,CAAC;YACzE,MAAM,UAAU,GAA0C,SAAU,CAAC,UAAU,CAAC;YAChF,OAAO,CAAC,kBAAkB;gBACxB,CAAC,CAAC,UAAU,IAAI,IAAA,8BAAc,EAAC,UAAU,EAAE,uBAAO,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;gBAC1E,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,IAAI,kBAAkB,CAAC;gBAC/C,IAAA,gDAAwB,EAAC,KAAK,EAAE,UAAU,EAAE,EAAE,mCAAmC,EAAE,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAhMD,0FAgMC","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 { IActorTest, TestResult } from '@comunica/core';\nimport { failTest, passTestVoid } from '@comunica/core';\nimport type { ComunicaDataFactory, FragmentSelectorShape, IActionContext, IQuerySourceWrapper } from '@comunica/types';\nimport { Algebra, AlgebraFactory, isKnownOperation, isKnownSubType } from '@comunica/utils-algebra';\nimport {\n assignOperationSource,\n doesShapeAcceptOperation,\n getOperationSource,\n removeOperationSource,\n} from '@comunica/utils-query-operation';\n\n/**\n * A comunica Group Sources Optimize Query Operation Actor.\n */\nexport class ActorOptimizeQueryOperationGroupSources extends ActorOptimizeQueryOperation {\n public constructor(args: IActorOptimizeQueryOperationArgs) {\n super(args);\n }\n\n public async test(action: IActionOptimizeQueryOperation): Promise<TestResult<IActorTest>> {\n if (getOperationSource(action.operation)) {\n return failTest(`Actor ${this.name} does not work with top-level operation sources.`);\n }\n return passTestVoid();\n }\n\n public async run(action: IActionOptimizeQueryOperation): Promise<IActorOptimizeQueryOperationOutput> {\n return { operation: await this.groupOperation(action.operation, action.context), context: action.context };\n }\n\n /**\n * Group operations belonging to the same source together, only if that source accepts the grouped operations.\n * This grouping will be done recursively for the whole operation tree.\n * Operations annotated with sources are considered leaves in the tree.\n * @param operation An operation to group.\n * @param context The action context.\n */\n public async groupOperation(operation: Algebra.Operation, context: IActionContext): Promise<Algebra.Operation> {\n const dataFactory: ComunicaDataFactory = context.getSafe(KeysInitQuery.dataFactory);\n const algebraFactory = new AlgebraFactory(dataFactory);\n\n // Return operation as-is if the operation already has a single source, or if the operation has no children.\n if (getOperationSource(operation) ?? !('input' in operation)) {\n return operation;\n }\n\n // If operation has a single input, move source annotation upwards if the source can handle it.\n if (!Array.isArray(operation.input)) {\n const groupedInput = await this.groupOperation(<Algebra.Operation> operation.input, context);\n if (groupedInput.metadata?.scopedSource) {\n const source: IQuerySourceWrapper = <IQuerySourceWrapper> getOperationSource(groupedInput);\n operation = await this.moveSourceAnnotationUpwardsIfPossible(operation, [ groupedInput ], source, context);\n }\n return <Algebra.Operation> { ...operation, input: groupedInput };\n }\n\n // If operation has multiple inputs, cluster source annotations.\n const inputs: Algebra.Operation[] = await Promise.all(operation.input\n .map(subInput => this.groupOperation(subInput, context)));\n const clusters = this.clusterOperationsWithEqualSources(inputs);\n\n // If we just have a single cluster, move the source annotation upwards\n if (clusters.length === 1) {\n const newInputs = clusters[0];\n const source = getOperationSource(clusters[0][0])!;\n return <Algebra.Operation> {\n ...await this.moveSourceAnnotationUpwardsIfPossible(operation, newInputs, source, context),\n input: newInputs,\n };\n }\n\n // If the number of clusters is equal to the number of original inputs, do nothing.\n if (clusters.length === inputs.length) {\n const result: Algebra.Multi = { ...operation, input: inputs };\n return result;\n }\n\n // If we have multiple clusters, created nested multi-operations\n let multiFactoryMethod: (children: Algebra.Operation[], flatten: boolean) => Algebra.Operation;\n if (isKnownOperation(operation, Algebra.Types.JOIN)) {\n multiFactoryMethod = algebraFactory.createJoin.bind(algebraFactory);\n } else if (isKnownOperation(operation, Algebra.Types.UNION)) {\n multiFactoryMethod = algebraFactory.createUnion.bind(algebraFactory);\n } else if (isKnownOperation(operation, Algebra.Types.ALT)) {\n multiFactoryMethod = <any> algebraFactory.createAlt.bind(algebraFactory);\n } else if (isKnownOperation(operation, Algebra.Types.SEQ)) {\n multiFactoryMethod = <any> algebraFactory.createSeq.bind(algebraFactory);\n } else {\n // While LeftJoin and Minus are also multi-operations,\n // these can never occur because they only have 2 inputs,\n // so these cases will always be captured by one of the 2 if-cases above\n // (clusters.length === 1 or clusters.length === input.length)\n\n // In all other cases, error\n throw new Error(`Unsupported operation '${operation.type}' detected while grouping sources`);\n }\n return await this.groupOperationMulti(clusters, multiFactoryMethod, context);\n }\n\n protected async groupOperationMulti(\n clusters: Algebra.Operation[][],\n factoryMethod: (children: Algebra.Operation[], flatten: boolean) => Algebra.Operation,\n context: IActionContext,\n ): Promise<Algebra.Operation> {\n let flatten = true;\n const nestedMerges = await Promise.all(clusters.map(async(cluster) => {\n const source = getOperationSource(cluster[0])!;\n const merged = await this\n .moveSourceAnnotationUpwardsIfPossible(factoryMethod(cluster, true), cluster, source, context);\n if (getOperationSource(merged)) {\n flatten = false;\n }\n return merged;\n }));\n return factoryMethod(nestedMerges, flatten);\n }\n\n /**\n * Cluster the given operations by equal source annotations.\n * @param operationsIn An array of operations to cluster.\n */\n public clusterOperationsWithEqualSources(operationsIn: Algebra.Operation[]): Algebra.Operation[][] {\n // Operations can have a source, or no source at all\n const sourceOperations: Map<IQuerySourceWrapper, Algebra.Operation[]> = new Map();\n const sourcelessOperations: Algebra.Operation[] = [];\n\n // Cluster by source\n for (const operation of operationsIn) {\n const source = getOperationSource(operation);\n if (source) {\n if (!sourceOperations.has(source)) {\n sourceOperations.set(source, []);\n }\n sourceOperations.get(source)!.push(operation);\n } else {\n sourcelessOperations.push(operation);\n }\n }\n\n // Return clusters\n const clusters: Algebra.Operation[][] = [];\n if (sourcelessOperations.length > 0) {\n clusters.push(sourcelessOperations);\n }\n for (const [ source, operations ] of sourceOperations.entries()) {\n clusters.push(operations\n .map(operation => assignOperationSource(operation, source)));\n }\n return clusters;\n }\n\n /**\n * If the given source accepts the grouped operation, annotate the grouped operation with the source,\n * and remove the source annotation from the seperate input operations.\n * Otherwise, return the grouped operation unchanged.\n * @param operation A grouped operation consisting of all given input operations.\n * @param inputs An array of operations that share the same source annotation.\n * @param source The common source.\n * @param context The action context.\n */\n public async moveSourceAnnotationUpwardsIfPossible<O extends Algebra.Operation>(\n operation: O,\n inputs: Algebra.Operation[],\n source: IQuerySourceWrapper | undefined,\n context: IActionContext,\n ): Promise<O> {\n if (source && this.isPossibleToMoveSourceAnnotationUpwards(\n operation,\n await source.source.getSelectorShape(context),\n context,\n )) {\n this.logDebug(context, `Hoist ${inputs.length} source-specific operations into a single ${operation.type} operation for ${source.source.toString()}`);\n operation = assignOperationSource(operation, source);\n for (const input of inputs) {\n removeOperationSource(input);\n }\n }\n return operation;\n }\n\n /**\n * Checks if it's possible to move the source annotation upwards using the following rules:\n * - If the shape doesn't accept the operation, then it's not possible.\n * - If it does and the operation does not contain extension functions or\n * comunica doesn't support them, then it's possible.\n * - If comunica does support them, then it's possible only if the shape accepts the extension function expressions.\n * @param operation A grouped operation consisting of all given input operations.\n * @param shape The common source's shape.\n * @param context The action context.\n */\n public isPossibleToMoveSourceAnnotationUpwards<O extends Algebra.Operation>(\n operation: O,\n shape: FragmentSelectorShape,\n context: IActionContext,\n ): boolean {\n const wildcardAcceptAllExtensionFunctions = context.get(KeysInitQuery.extensionFunctionsAlwaysPushdown);\n if (doesShapeAcceptOperation(shape, operation, { wildcardAcceptAllExtensionFunctions })) {\n const extensionFunctions = context.get(KeysInitQuery.extensionFunctions);\n const expression: Algebra.Expression | undefined = (<any> operation).expression;\n return !extensionFunctions ||\n !(expression && isKnownSubType(expression, Algebra.ExpressionTypes.NAMED)) ||\n !(expression?.name.value in extensionFunctions) ||\n doesShapeAcceptOperation(shape, expression, { wildcardAcceptAllExtensionFunctions });\n }\n return false;\n }\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-group-sources",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "A group-sources optimize-query-operation actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,12 +41,12 @@
|
|
|
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-
|
|
49
|
-
"
|
|
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"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "0b1756fdb9bef014133432489627c1bd71779bd0"
|
|
52
52
|
}
|