@vizabi/reader-ddfcsv 4.3.2 → 4.3.5
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/.nyc_output/04da916d5240a86facf0fcb14d89854a.json +1 -0
- package/.nyc_output/{b4e1a7f86ae858c85e0528842263588d.json → b6c2172ea4b73ef30a769f84462d042b.json} +0 -0
- package/.travis.yml +0 -0
- package/CHANGELOG.md +0 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/coverage/base.css +0 -0
- package/coverage/block-navigation.js +0 -0
- package/coverage/index.html +29 -29
- package/coverage/prettify.css +0 -0
- package/coverage/prettify.js +0 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -0
- package/coverage/src/ddf-csv.ts.html +518 -404
- package/coverage/src/ddfcsv-error.ts.html +6 -6
- package/coverage/src/ddfcsv-reader.ts.html +63 -51
- package/coverage/src/file-readers/backend-file-reader.ts.html +6 -6
- package/coverage/src/file-readers/github-path-adapter.ts.html +3 -3
- package/coverage/src/file-readers/index.html +1 -1
- package/coverage/src/index.html +28 -28
- package/coverage/src/index.ts.html +6 -6
- package/coverage/src/resource-selection-optimizer/in-clause-under-conjunction.ts.html +219 -408
- package/coverage/src/resource-selection-optimizer/index.html +20 -20
- package/coverage/src/resource-selection-optimizer/index.ts.html +5 -5
- package/coverage/src/test-cases/concepts.ts.html +1 -1
- package/coverage/src/test-cases/entities.ts.html +1 -1
- package/coverage/src/test-cases/index.html +1 -1
- package/deploy.js +0 -0
- package/dist/reader-ddfcsv-polyfill.js +1 -1
- package/dist/reader-ddfcsv-polyfill.js.map +1 -1
- package/dist/reader-ddfcsv.js +2 -2
- package/dist/reader-ddfcsv.js.map +1 -1
- package/icon.png +0 -0
- package/lib/src/ddf-csv.d.ts +2 -1
- package/lib/src/ddf-csv.js +41 -9
- package/lib/src/ddf-csv.js.map +1 -1
- package/lib/src/ddfcsv-error.d.ts +0 -0
- package/lib/src/ddfcsv-error.js +0 -0
- package/lib/src/ddfcsv-error.js.map +0 -0
- package/lib/src/ddfcsv-reader.d.ts +0 -0
- package/lib/src/ddfcsv-reader.js +2 -2
- package/lib/src/ddfcsv-reader.js.map +1 -1
- package/lib/src/file-readers/backend-file-reader.d.ts +0 -0
- package/lib/src/file-readers/backend-file-reader.js +0 -0
- package/lib/src/file-readers/backend-file-reader.js.map +0 -0
- package/lib/src/file-readers/github-path-adapter.d.ts +0 -0
- package/lib/src/file-readers/github-path-adapter.js +0 -0
- package/lib/src/file-readers/github-path-adapter.js.map +0 -0
- package/lib/src/index.d.ts +0 -0
- package/lib/src/index.js +0 -0
- package/lib/src/index.js.map +0 -0
- package/lib/src/interfaces.d.ts +0 -0
- package/lib/src/interfaces.js +0 -0
- package/lib/src/interfaces.js.map +0 -0
- package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.d.ts +1 -3
- package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.js +38 -83
- package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.js.map +1 -1
- package/lib/src/resource-selection-optimizer/index.d.ts +0 -0
- package/lib/src/resource-selection-optimizer/index.js +0 -0
- package/lib/src/resource-selection-optimizer/index.js.map +0 -0
- package/lib-web/src/ddf-csv.d.ts +2 -1
- package/lib-web/src/ddf-csv.js +41 -9
- package/lib-web/src/ddf-csv.js.map +1 -1
- package/lib-web/src/ddfcsv-error.d.ts +0 -0
- package/lib-web/src/ddfcsv-error.js +0 -0
- package/lib-web/src/ddfcsv-error.js.map +0 -0
- package/lib-web/src/ddfcsv-reader.d.ts +0 -0
- package/lib-web/src/ddfcsv-reader.js +2 -2
- package/lib-web/src/ddfcsv-reader.js.map +1 -1
- package/lib-web/src/file-readers/frontend-file-reader.d.ts +0 -0
- package/lib-web/src/file-readers/frontend-file-reader.js +0 -0
- package/lib-web/src/file-readers/frontend-file-reader.js.map +0 -0
- package/lib-web/src/file-readers/github-path-adapter.d.ts +0 -0
- package/lib-web/src/file-readers/github-path-adapter.js +0 -0
- package/lib-web/src/file-readers/github-path-adapter.js.map +0 -0
- package/lib-web/src/index-web.d.ts +0 -0
- package/lib-web/src/index-web.js +0 -0
- package/lib-web/src/index-web.js.map +0 -0
- package/lib-web/src/interfaces.d.ts +0 -0
- package/lib-web/src/interfaces.js +0 -0
- package/lib-web/src/interfaces.js.map +0 -0
- package/lib-web/src/resource-selection-optimizer/in-clause-under-conjunction.d.ts +1 -3
- package/lib-web/src/resource-selection-optimizer/in-clause-under-conjunction.js +38 -83
- package/lib-web/src/resource-selection-optimizer/in-clause-under-conjunction.js.map +1 -1
- package/lib-web/src/resource-selection-optimizer/index.d.ts +0 -0
- package/lib-web/src/resource-selection-optimizer/index.js +0 -0
- package/lib-web/src/resource-selection-optimizer/index.js.map +0 -0
- package/package.json +3 -3
- package/scripts/set-own-version.js +0 -0
- package/src/ddf-csv.ts +42 -10
- package/src/ddfcsv-error.ts +0 -0
- package/src/ddfcsv-reader.ts +1 -1
- package/src/file-readers/backend-file-reader.ts +0 -0
- package/src/file-readers/frontend-file-reader.ts +0 -0
- package/src/file-readers/github-path-adapter.ts +0 -0
- package/src/index-web.ts +0 -0
- package/src/index.ts +0 -0
- package/src/interfaces.ts +0 -0
- package/src/resource-selection-optimizer/in-clause-under-conjunction.ts +39 -101
- package/src/resource-selection-optimizer/index.ts +0 -0
- package/src/test-cases/concepts.ts +0 -0
- package/src/test-cases/entities.ts +0 -0
- package/test/assets-fixtures/world-50m.json +0 -0
- package/test/assets.spec.ts +0 -0
- package/test/common.ts +0 -0
- package/test/definition/concepts-definition.spec.ts +0 -0
- package/test/definition/datapoints-definition.spec.ts +1 -1
- package/test/definition/entities-definition.spec.ts +0 -0
- package/test/definition/schema-definition.spec.ts +0 -0
- package/test/diagnostics.spec.ts +0 -0
- package/test/features-service.spec.ts +0 -0
- package/test/high-load.spec.ts +0 -0
- package/test/main.spec.ts +8 -4
- package/test/mocha.opts +0 -0
- package/test/multi-instances.spec.ts +0 -0
- package/test/result-fixtures/datapoints-assets.json +0 -0
- package/test/result-fixtures/in-clause-under-conjunction-1.json +100 -100
- package/test/result-fixtures/in-clause-under-conjunction-2.json +70169 -70169
- package/test/result-fixtures/multi-instances/concepts-sg.json +0 -0
- package/test/result-fixtures/multi-instances/concepts-soderstornsmodellen.json +0 -0
- package/test/result-fixtures/multi-instances/datapoints-sg.json +0 -0
- package/test/result-fixtures/multi-instances/datapoints-soderstornsmodellen.json +0 -0
- package/test/result-fixtures/multi-instances/entities-sg.json +2 -2
- package/test/result-fixtures/multi-instances/entities-soderstornsmodellen.json +0 -0
- package/test/result-fixtures/multi-instances/schema-sg.json +0 -0
- package/test/result-fixtures/multi-instances/schema-soderstornsmodellen.json +0 -0
- package/test/schema.spec.ts +0 -0
- package/test/tslint.json +3 -2
- package/tsconfig-web.json +0 -0
- package/tsconfig.json +0 -0
- package/tslint.json +1 -1
- package/.nyc_output/795caf0b3acca8aacbd9d932d086ab81.json +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizabi/reader-ddfcsv",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.5",
|
|
4
4
|
"description": "Vizabi DDFcsv reader",
|
|
5
5
|
"author": "Vyacheslav Chub<vyacheslav.chub@valor-software.com>",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -125,8 +125,8 @@
|
|
|
125
125
|
"ts-loader": "4.3.0",
|
|
126
126
|
"ts-node": "10.9.2",
|
|
127
127
|
"tslib": " 2.6.2",
|
|
128
|
-
"tslint": "
|
|
129
|
-
"tslint-no-unused-expression-chai": "0.1.
|
|
128
|
+
"tslint": "6.1.3",
|
|
129
|
+
"tslint-no-unused-expression-chai": "0.1.4",
|
|
130
130
|
"typescript": "5.4.5",
|
|
131
131
|
"uglifyjs-webpack-plugin": "1.2.5",
|
|
132
132
|
"webpack": "4.8.1",
|
|
File without changes
|
package/src/ddf-csv.ts
CHANGED
|
@@ -41,6 +41,7 @@ export function ddfCsvReader (logger?: any) {
|
|
|
41
41
|
let optimalFilesSet = [];
|
|
42
42
|
let datapackage;
|
|
43
43
|
let datapackagePromise;
|
|
44
|
+
let datasetWithConstraints = false;
|
|
44
45
|
|
|
45
46
|
function loadDataPackage (baseOptions: IBaseReaderOptions): Promise<IDatapackage> {
|
|
46
47
|
const datapackagePath = getFilePath(baseOptions.basePath);
|
|
@@ -165,8 +166,8 @@ export function ddfCsvReader (logger?: any) {
|
|
|
165
166
|
concepts.forEach(row => options.conceptsLookup.set(row.concept, row));
|
|
166
167
|
}
|
|
167
168
|
|
|
168
|
-
async function query (queryParam,
|
|
169
|
-
|
|
169
|
+
async function query (queryParam, _baseOptions: IBaseReaderOptions) {
|
|
170
|
+
const baseOptions = Object.assign({}, _baseOptions);
|
|
170
171
|
const { warning, error } = baseOptions.diagnostic.prepareDiagnosticFor('query');
|
|
171
172
|
let data;
|
|
172
173
|
|
|
@@ -180,10 +181,10 @@ export function ddfCsvReader (logger?: any) {
|
|
|
180
181
|
if (isSchemaQuery(queryParam)) {
|
|
181
182
|
data = await querySchema(queryParam, baseOptions);
|
|
182
183
|
} else {
|
|
183
|
-
const appropriatePlugin = getAppropriatePlugin(this, queryParam, baseOptions);
|
|
184
|
+
const appropriatePlugin = datasetWithConstraints && getAppropriatePlugin(this, queryParam, baseOptions);
|
|
184
185
|
|
|
186
|
+
optimalFilesSet = [];
|
|
185
187
|
if (appropriatePlugin) {
|
|
186
|
-
optimalFilesSet = [];
|
|
187
188
|
const files = await appropriatePlugin.getRecommendedFilesSet();
|
|
188
189
|
optimalFilesSet = files;
|
|
189
190
|
queryParam.optimalFilesSet = [].concat(files, queryParam.optimalFilesSet);
|
|
@@ -201,7 +202,8 @@ export function ddfCsvReader (logger?: any) {
|
|
|
201
202
|
return data;
|
|
202
203
|
}
|
|
203
204
|
|
|
204
|
-
function queryData (queryParam,
|
|
205
|
+
function queryData (queryParam, _options: IBaseReaderOptions) {
|
|
206
|
+
const options = Object.assign({}, _options);
|
|
205
207
|
const { debug } = options.diagnostic.prepareDiagnosticFor('queryData');
|
|
206
208
|
const {
|
|
207
209
|
select: { key = [], value = [] },
|
|
@@ -381,9 +383,37 @@ export function ddfCsvReader (logger?: any) {
|
|
|
381
383
|
return result;
|
|
382
384
|
}
|
|
383
385
|
|
|
386
|
+
function patchFilterForOrClause(filter) {
|
|
387
|
+
|
|
388
|
+
function processFilter(where) {
|
|
389
|
+
const whereKeys = Object.keys(where);
|
|
390
|
+
for (const key of whereKeys) {
|
|
391
|
+
if (key == "$or") {
|
|
392
|
+
where[key] = where[key].reduce((res, value) => {
|
|
393
|
+
const valueKeys = Object.keys(value);
|
|
394
|
+
if (valueKeys.length > 1) {
|
|
395
|
+
for (const key of valueKeys) {
|
|
396
|
+
res.push({ [key]: value[key] });
|
|
397
|
+
}
|
|
398
|
+
} else {
|
|
399
|
+
res.push(value);
|
|
400
|
+
}
|
|
401
|
+
return res;
|
|
402
|
+
}, []);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return where;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return processFilter(filter);
|
|
409
|
+
}
|
|
410
|
+
|
|
384
411
|
function mergeFilters (...filters) {
|
|
385
412
|
return filters.reduce((a, b) => {
|
|
386
|
-
|
|
413
|
+
if (!isEmpty(b)) {
|
|
414
|
+
patchFilterForOrClause(b);
|
|
415
|
+
a.$and.push(b);
|
|
416
|
+
}
|
|
387
417
|
|
|
388
418
|
return a;
|
|
389
419
|
}, { $and: [] });
|
|
@@ -461,7 +491,7 @@ export function ddfCsvReader (logger?: any) {
|
|
|
461
491
|
return Promise.resolve({ [ joinID ]: join.where });
|
|
462
492
|
} else {
|
|
463
493
|
// entity concept
|
|
464
|
-
return
|
|
494
|
+
return queryData({
|
|
465
495
|
select: { key: [ join.key ] },
|
|
466
496
|
where: join.where,
|
|
467
497
|
from: options.conceptsLookup.has(join.key) ? 'entities' : 'concepts'
|
|
@@ -557,7 +587,7 @@ export function ddfCsvReader (logger?: any) {
|
|
|
557
587
|
*/
|
|
558
588
|
function getEntitySetFilter (conceptStrings, queryParam, options) {
|
|
559
589
|
const promises = filterConceptsByType([ 'entity_set' ], conceptStrings, options)
|
|
560
|
-
.map(concept =>
|
|
590
|
+
.map(concept => queryData({
|
|
561
591
|
select: { key: [ concept.domain ], value: [ 'is--' + concept.concept ] },
|
|
562
592
|
from: 'entities'
|
|
563
593
|
}, Object.assign({}, options))
|
|
@@ -680,7 +710,7 @@ export function ddfCsvReader (logger?: any) {
|
|
|
680
710
|
|
|
681
711
|
joinRow(resultRow, row, joinMode);
|
|
682
712
|
} else {
|
|
683
|
-
result.set(keyString, row);
|
|
713
|
+
result.set(keyString, Object.assign({}, row));
|
|
684
714
|
}
|
|
685
715
|
});
|
|
686
716
|
|
|
@@ -835,7 +865,8 @@ export function ddfCsvReader (logger?: any) {
|
|
|
835
865
|
|
|
836
866
|
const constraints = resource.schema.fields.reduce((result, field) => {
|
|
837
867
|
if (field.constraints?.enum) {
|
|
838
|
-
|
|
868
|
+
if (!datasetWithConstraints) datasetWithConstraints = true;
|
|
869
|
+
result[field.name] = field.constraints.enum.map(e => +e || e);
|
|
839
870
|
}
|
|
840
871
|
return result;
|
|
841
872
|
}, {});
|
|
@@ -873,6 +904,7 @@ export function ddfCsvReader (logger?: any) {
|
|
|
873
904
|
|
|
874
905
|
return {
|
|
875
906
|
query,
|
|
907
|
+
queryData,
|
|
876
908
|
loadFile
|
|
877
909
|
};
|
|
878
910
|
}
|
package/src/ddfcsv-error.ts
CHANGED
|
File without changes
|
package/src/ddfcsv-reader.ts
CHANGED
|
@@ -15,7 +15,7 @@ export function prepareDDFCsvReaderObject (defaultResourceReader?: IResourceRead
|
|
|
15
15
|
return {
|
|
16
16
|
init (readerInfo) {
|
|
17
17
|
// TODO: check validity of base path
|
|
18
|
-
this._basePath = githubPathAdapter(readerInfo.path);
|
|
18
|
+
this._basePath = githubPathAdapter(readerInfo.path || '');
|
|
19
19
|
|
|
20
20
|
this._lastModified = readerInfo._lastModified;
|
|
21
21
|
this.fileReader = externalResourceReader || defaultResourceReader;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/index-web.ts
CHANGED
|
File without changes
|
package/src/index.ts
CHANGED
|
File without changes
|
package/src/interfaces.ts
CHANGED
|
File without changes
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
1
|
import * as head from 'lodash.head';
|
|
3
2
|
import * as values from 'lodash.values';
|
|
4
3
|
import * as keys from 'lodash.keys';
|
|
5
4
|
import * as get from 'lodash.get';
|
|
6
|
-
import * as flattenDeep from 'lodash.flattendeep';
|
|
7
5
|
import * as isEmpty from 'lodash.isempty';
|
|
8
6
|
import * as startsWith from 'lodash.startswith';
|
|
9
7
|
import * as includes from 'lodash.includes';
|
|
@@ -12,8 +10,6 @@ import { DdfCsvError } from '../ddfcsv-error';
|
|
|
12
10
|
import { IDatapackage, IResourceSelectionOptimizer, IResourceRead, IBaseReaderOptions } from '../interfaces';
|
|
13
11
|
import { QueryFeature, featureDetectors, IQuery } from 'ddf-query-validator';
|
|
14
12
|
|
|
15
|
-
const Papa = require('papaparse');
|
|
16
|
-
|
|
17
13
|
const WHERE_KEYWORD = 'where';
|
|
18
14
|
const JOIN_KEYWORD = 'join';
|
|
19
15
|
const KEY_IN = '$in';
|
|
@@ -21,10 +17,6 @@ const KEY_NIN = '$nin';
|
|
|
21
17
|
const KEY_AND = '$and';
|
|
22
18
|
const KEY_OR = '$or';
|
|
23
19
|
|
|
24
|
-
const getFirstConditionClause = clause => head(values(clause));
|
|
25
|
-
const getFirstKey = obj => head(keys(obj));
|
|
26
|
-
const isOneKeyBased = obj => keys(obj).length === 1;
|
|
27
|
-
|
|
28
20
|
export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
|
|
29
21
|
private flow: any = {};
|
|
30
22
|
private fileReader: IResourceRead;
|
|
@@ -44,11 +36,7 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
|
|
|
44
36
|
isMatched(): boolean {
|
|
45
37
|
this.flow.joinObject = get(this.query, JOIN_KEYWORD);
|
|
46
38
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return this.query.from === "datapoints";
|
|
50
|
-
// return includes(relatedFeatures, QueryFeature.WhereClauseBasedOnConjunction) &&
|
|
51
|
-
// includes(relatedFeatures, QueryFeature.ConjunctionPartFromWhereClauseCorrespondsToJoin);
|
|
39
|
+
return this.query.from === "datapoints" && this.flow.joinObject;
|
|
52
40
|
}
|
|
53
41
|
|
|
54
42
|
async getRecommendedFilesSet(): Promise<string[]> {
|
|
@@ -59,7 +47,8 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
|
|
|
59
47
|
|
|
60
48
|
let result;
|
|
61
49
|
try {
|
|
62
|
-
this.collectProcessableClauses();
|
|
50
|
+
this.flow.processableClauses = await this.collectProcessableClauses();
|
|
51
|
+
if (!this.flow.processableClauses) return [];
|
|
63
52
|
this.collectEntityFilesNames();
|
|
64
53
|
const data = await this.collectEntities();
|
|
65
54
|
this.fillEntityValuesHash(data);
|
|
@@ -80,24 +69,26 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
|
|
|
80
69
|
}
|
|
81
70
|
}
|
|
82
71
|
|
|
83
|
-
private collectProcessableClauses():
|
|
84
|
-
const joinKeys = keys(this.flow.joinObject)
|
|
85
|
-
|
|
86
|
-
|
|
72
|
+
private collectProcessableClauses(): Promise<any> {
|
|
73
|
+
const joinKeys = keys(this.flow.joinObject).filter(
|
|
74
|
+
key => ["entity_domain", "entity_set"].includes(this.options.conceptsLookup.get(key.slice(1))?.concept_type));
|
|
75
|
+
if (!joinKeys.length) return Promise.resolve(false);
|
|
87
76
|
|
|
88
|
-
|
|
77
|
+
return Promise.all(joinKeys.map(joinKey => {
|
|
78
|
+
const key = this.flow.joinObject[joinKey].key;
|
|
89
79
|
const where = get(this.flow.joinObject, `${joinKey}.${WHERE_KEYWORD}`, {});
|
|
90
80
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this.
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
81
|
+
return this.parent.queryData({
|
|
82
|
+
select: { key: [key] },
|
|
83
|
+
where,
|
|
84
|
+
from: this.options.conceptsLookup.has(key) ? 'entities' : 'concepts'
|
|
85
|
+
}, Object.assign({ joinID: joinKey }, this.options))
|
|
86
|
+
.then(result => ({
|
|
87
|
+
key,
|
|
88
|
+
entities: new Set(result.map(row => row[ key ]))
|
|
89
|
+
}));
|
|
90
|
+
}));
|
|
99
91
|
|
|
100
|
-
return this;
|
|
101
92
|
}
|
|
102
93
|
|
|
103
94
|
private collectEntityFilesNames(): InClauseUnderConjunction {
|
|
@@ -107,15 +98,15 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
|
|
|
107
98
|
|
|
108
99
|
for (const schemaResourceRecord of this.datapackage.ddfSchema.entities) {
|
|
109
100
|
for (const clause of this.flow.processableClauses) {
|
|
110
|
-
const
|
|
101
|
+
const key = clause.key;
|
|
111
102
|
|
|
112
|
-
if (head(schemaResourceRecord.primaryKey) ===
|
|
103
|
+
if (head(schemaResourceRecord.primaryKey) === key) {
|
|
113
104
|
for (const resourceName of schemaResourceRecord.resources) {
|
|
114
105
|
const resource = this.options.resourcesLookup.get(resourceName);
|
|
115
106
|
|
|
116
107
|
this.flow.entityResources.add(resource);
|
|
117
108
|
this.flow.entityFilesNames.add(resource.path);
|
|
118
|
-
this.flow.fileNameToPrimaryKeyHash.set(resource.path,
|
|
109
|
+
this.flow.fileNameToPrimaryKeyHash.set(resource.path, key);
|
|
119
110
|
}
|
|
120
111
|
}
|
|
121
112
|
}
|
|
@@ -162,30 +153,14 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
|
|
|
162
153
|
}
|
|
163
154
|
|
|
164
155
|
private getFilesGroupsQueryClause(): InClauseUnderConjunction {
|
|
165
|
-
const getEntitiesExcept = (entityValuesToExclude: string[]): string[] => {
|
|
166
|
-
const result = [];
|
|
167
|
-
|
|
168
|
-
for (const entityKey of this.flow.entityValueToDomainHash.keys()) {
|
|
169
|
-
if (!includes(entityValuesToExclude, entityKey)) {
|
|
170
|
-
result.push(entityKey);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return result;
|
|
175
|
-
};
|
|
176
156
|
const filesGroupsByClause = new Map();
|
|
177
157
|
|
|
178
158
|
for (const clause of this.flow.processableClauses) {
|
|
179
159
|
const filesGroupByClause = {
|
|
180
|
-
|
|
181
|
-
datapoints: new Set(),
|
|
182
|
-
concepts: new Set()
|
|
160
|
+
datapoints: new Set()
|
|
183
161
|
};
|
|
184
|
-
const firstConditionClause = getFirstConditionClause(clause);
|
|
185
|
-
const entityValuesFromClause = firstConditionClause[KEY_IN] || getEntitiesExcept(firstConditionClause[KEY_NIN]);
|
|
186
162
|
|
|
187
|
-
for (const entityValueFromClause of
|
|
188
|
-
//filesGroupByClause.entities.add(this.flow.entityValueToFileHash.get(entityValueFromClause));
|
|
163
|
+
for (const entityValueFromClause of clause.entities) {
|
|
189
164
|
|
|
190
165
|
const entitiesByQuery = this.flow.entityValueToDomainHash.get(entityValueFromClause);
|
|
191
166
|
|
|
@@ -194,13 +169,12 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
|
|
|
194
169
|
for (const resourceName of schemaResourceRecord.resources) {
|
|
195
170
|
if (includes(schemaResourceRecord.primaryKey, entityByQuery)) {
|
|
196
171
|
const resource = this.options.resourcesLookup.get(resourceName);
|
|
197
|
-
const constraint = resource.constraints[entityByQuery];
|
|
172
|
+
const constraint = resource.constraints?.[entityByQuery];
|
|
198
173
|
if ( constraint ) {
|
|
199
174
|
if (constraint.includes(entityValueFromClause)) {
|
|
200
175
|
filesGroupByClause.datapoints.add(resource.path);
|
|
201
176
|
}
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
177
|
+
} else {
|
|
204
178
|
filesGroupByClause.datapoints.add(resource.path);
|
|
205
179
|
}
|
|
206
180
|
}
|
|
@@ -209,13 +183,7 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
|
|
|
209
183
|
}
|
|
210
184
|
}
|
|
211
185
|
|
|
212
|
-
|
|
213
|
-
for (const resourceName of schemaResourceRecord.resources) {
|
|
214
|
-
filesGroupByClause.concepts.add(this.options.resourcesLookup.get(resourceName).path);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
filesGroupsByClause.set(clause, filesGroupByClause);
|
|
186
|
+
filesGroupsByClause.set(clause.key, filesGroupByClause);
|
|
219
187
|
}
|
|
220
188
|
|
|
221
189
|
this.flow.filesGroupsByClause = filesGroupsByClause;
|
|
@@ -224,59 +192,29 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
|
|
|
224
192
|
}
|
|
225
193
|
|
|
226
194
|
private getOptimalFilesGroup(): string[] {
|
|
227
|
-
const clauseKeys = this.flow.filesGroupsByClause.keys();
|
|
228
195
|
|
|
229
|
-
|
|
230
|
-
let appropriateClauseSize;
|
|
231
|
-
|
|
232
|
-
for (const key of clauseKeys) {
|
|
233
|
-
const size = this.flow.filesGroupsByClause.get(key).datapoints.size +
|
|
234
|
-
this.flow.filesGroupsByClause.get(key).entities.size +
|
|
235
|
-
this.flow.filesGroupsByClause.get(key).concepts.size;
|
|
196
|
+
const entities = this.flow.entityFilesNames;
|
|
236
197
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
198
|
+
const concepts = new Set();
|
|
199
|
+
for (const schemaResourceRecord of this.datapackage.ddfSchema.concepts) {
|
|
200
|
+
for (const resourceName of schemaResourceRecord.resources) {
|
|
201
|
+
concepts.add(this.options.resourcesLookup.get(resourceName).path);
|
|
240
202
|
}
|
|
241
203
|
}
|
|
242
204
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return [
|
|
248
|
-
...Array.from(this.flow.filesGroupsByClause.get(appropriateClauseKey).concepts),
|
|
249
|
-
...Array.from(this.flow.filesGroupsByClause.get(appropriateClauseKey).entities),
|
|
250
|
-
...Array.from(this.flow.filesGroupsByClause.get(appropriateClauseKey).datapoints)
|
|
251
|
-
] as string[];
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
private getProcessableClauses(clause) {
|
|
255
|
-
const result = [];
|
|
256
|
-
const clauseKeys = keys(clause);
|
|
205
|
+
const clauseKeys = this.flow.filesGroupsByClause.keys();
|
|
206
|
+
let datapoints = Array.from(this.flow.filesGroupsByClause.get(clauseKeys.next().value).datapoints);
|
|
257
207
|
|
|
258
208
|
for (const key of clauseKeys) {
|
|
259
|
-
|
|
260
|
-
// attention! this functionality process only first clause
|
|
261
|
-
// for example, { geo: { '$in': ['world'] } }
|
|
262
|
-
// in this example { geo: { '$in': ['world'] }, foo: { '$in': ['bar', 'baz'] } }]
|
|
263
|
-
// foo: { '$in': ['bar', 'baz'] } will NOT be processed
|
|
264
|
-
const conditionKey = head(keys(clause[key]));
|
|
265
|
-
|
|
266
|
-
if (conditionKey === KEY_IN || conditionKey === KEY_NIN) {
|
|
267
|
-
result.push(clause);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
209
|
+
datapoints = this.intersectArray(datapoints, Array.from(this.flow.filesGroupsByClause.get(key).datapoints));
|
|
270
210
|
}
|
|
271
211
|
|
|
272
|
-
return
|
|
212
|
+
return [...Array.from(concepts), ...Array.from(entities)].concat(datapoints) as string[];
|
|
273
213
|
}
|
|
274
214
|
|
|
275
|
-
private singleAndField(clause): boolean {
|
|
276
|
-
return isOneKeyBased(clause) && !!get(clause, KEY_AND);
|
|
277
|
-
}
|
|
278
215
|
|
|
279
|
-
private
|
|
280
|
-
return
|
|
216
|
+
private intersectArray(array1, array2) {
|
|
217
|
+
return array1.filter(value => array2.includes(value));
|
|
281
218
|
}
|
|
219
|
+
|
|
282
220
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/test/assets.spec.ts
CHANGED
|
File without changes
|
package/test/common.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/test/diagnostics.spec.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/test/high-load.spec.ts
CHANGED
|
File without changes
|
package/test/main.spec.ts
CHANGED
|
@@ -127,8 +127,10 @@ describe('General errors in ddfcsv reader', () => {
|
|
|
127
127
|
|
|
128
128
|
expect(error.file).to.equal(expectedPath);
|
|
129
129
|
expect(error.name).to.equal('DdfCsvError');
|
|
130
|
-
expect(error.message).to.equal(`JSON parsing error [filepath: ${expectedPath}]. Unexpected token (
|
|
131
|
-
|
|
130
|
+
expect(error.message).to.equal(`JSON parsing error [filepath: ${expectedPath}]. Unexpected token '(', "(
|
|
131
|
+
"nam"... is not valid JSON.`);
|
|
132
|
+
expect(error.details).to.equal(`Unexpected token '(', "(
|
|
133
|
+
"nam"... is not valid JSON`);
|
|
132
134
|
}
|
|
133
135
|
});
|
|
134
136
|
});
|
|
@@ -245,8 +247,10 @@ describe('General errors in ddfcsv reader', () => {
|
|
|
245
247
|
|
|
246
248
|
expect(error.file).to.equal(expectedPath);
|
|
247
249
|
expect(error.name).to.equal('DdfCsvError');
|
|
248
|
-
expect(error.message).to.equal(`JSON parsing error [filepath: ${expectedPath}]. Unexpected token (
|
|
249
|
-
|
|
250
|
+
expect(error.message).to.equal(`JSON parsing error [filepath: ${expectedPath}]. Unexpected token '(', "(
|
|
251
|
+
"nam"... is not valid JSON.`);
|
|
252
|
+
expect(error.details).to.equal(`Unexpected token '(', "(
|
|
253
|
+
"nam"... is not valid JSON`);
|
|
250
254
|
}
|
|
251
255
|
});
|
|
252
256
|
});
|
package/test/mocha.opts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|