@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.
Files changed (132) hide show
  1. package/.nyc_output/04da916d5240a86facf0fcb14d89854a.json +1 -0
  2. package/.nyc_output/{b4e1a7f86ae858c85e0528842263588d.json → b6c2172ea4b73ef30a769f84462d042b.json} +0 -0
  3. package/.travis.yml +0 -0
  4. package/CHANGELOG.md +0 -0
  5. package/LICENSE +0 -0
  6. package/README.md +0 -0
  7. package/coverage/base.css +0 -0
  8. package/coverage/block-navigation.js +0 -0
  9. package/coverage/index.html +29 -29
  10. package/coverage/prettify.css +0 -0
  11. package/coverage/prettify.js +0 -0
  12. package/coverage/sort-arrow-sprite.png +0 -0
  13. package/coverage/sorter.js +0 -0
  14. package/coverage/src/ddf-csv.ts.html +518 -404
  15. package/coverage/src/ddfcsv-error.ts.html +6 -6
  16. package/coverage/src/ddfcsv-reader.ts.html +63 -51
  17. package/coverage/src/file-readers/backend-file-reader.ts.html +6 -6
  18. package/coverage/src/file-readers/github-path-adapter.ts.html +3 -3
  19. package/coverage/src/file-readers/index.html +1 -1
  20. package/coverage/src/index.html +28 -28
  21. package/coverage/src/index.ts.html +6 -6
  22. package/coverage/src/resource-selection-optimizer/in-clause-under-conjunction.ts.html +219 -408
  23. package/coverage/src/resource-selection-optimizer/index.html +20 -20
  24. package/coverage/src/resource-selection-optimizer/index.ts.html +5 -5
  25. package/coverage/src/test-cases/concepts.ts.html +1 -1
  26. package/coverage/src/test-cases/entities.ts.html +1 -1
  27. package/coverage/src/test-cases/index.html +1 -1
  28. package/deploy.js +0 -0
  29. package/dist/reader-ddfcsv-polyfill.js +1 -1
  30. package/dist/reader-ddfcsv-polyfill.js.map +1 -1
  31. package/dist/reader-ddfcsv.js +2 -2
  32. package/dist/reader-ddfcsv.js.map +1 -1
  33. package/icon.png +0 -0
  34. package/lib/src/ddf-csv.d.ts +2 -1
  35. package/lib/src/ddf-csv.js +41 -9
  36. package/lib/src/ddf-csv.js.map +1 -1
  37. package/lib/src/ddfcsv-error.d.ts +0 -0
  38. package/lib/src/ddfcsv-error.js +0 -0
  39. package/lib/src/ddfcsv-error.js.map +0 -0
  40. package/lib/src/ddfcsv-reader.d.ts +0 -0
  41. package/lib/src/ddfcsv-reader.js +2 -2
  42. package/lib/src/ddfcsv-reader.js.map +1 -1
  43. package/lib/src/file-readers/backend-file-reader.d.ts +0 -0
  44. package/lib/src/file-readers/backend-file-reader.js +0 -0
  45. package/lib/src/file-readers/backend-file-reader.js.map +0 -0
  46. package/lib/src/file-readers/github-path-adapter.d.ts +0 -0
  47. package/lib/src/file-readers/github-path-adapter.js +0 -0
  48. package/lib/src/file-readers/github-path-adapter.js.map +0 -0
  49. package/lib/src/index.d.ts +0 -0
  50. package/lib/src/index.js +0 -0
  51. package/lib/src/index.js.map +0 -0
  52. package/lib/src/interfaces.d.ts +0 -0
  53. package/lib/src/interfaces.js +0 -0
  54. package/lib/src/interfaces.js.map +0 -0
  55. package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.d.ts +1 -3
  56. package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.js +38 -83
  57. package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.js.map +1 -1
  58. package/lib/src/resource-selection-optimizer/index.d.ts +0 -0
  59. package/lib/src/resource-selection-optimizer/index.js +0 -0
  60. package/lib/src/resource-selection-optimizer/index.js.map +0 -0
  61. package/lib-web/src/ddf-csv.d.ts +2 -1
  62. package/lib-web/src/ddf-csv.js +41 -9
  63. package/lib-web/src/ddf-csv.js.map +1 -1
  64. package/lib-web/src/ddfcsv-error.d.ts +0 -0
  65. package/lib-web/src/ddfcsv-error.js +0 -0
  66. package/lib-web/src/ddfcsv-error.js.map +0 -0
  67. package/lib-web/src/ddfcsv-reader.d.ts +0 -0
  68. package/lib-web/src/ddfcsv-reader.js +2 -2
  69. package/lib-web/src/ddfcsv-reader.js.map +1 -1
  70. package/lib-web/src/file-readers/frontend-file-reader.d.ts +0 -0
  71. package/lib-web/src/file-readers/frontend-file-reader.js +0 -0
  72. package/lib-web/src/file-readers/frontend-file-reader.js.map +0 -0
  73. package/lib-web/src/file-readers/github-path-adapter.d.ts +0 -0
  74. package/lib-web/src/file-readers/github-path-adapter.js +0 -0
  75. package/lib-web/src/file-readers/github-path-adapter.js.map +0 -0
  76. package/lib-web/src/index-web.d.ts +0 -0
  77. package/lib-web/src/index-web.js +0 -0
  78. package/lib-web/src/index-web.js.map +0 -0
  79. package/lib-web/src/interfaces.d.ts +0 -0
  80. package/lib-web/src/interfaces.js +0 -0
  81. package/lib-web/src/interfaces.js.map +0 -0
  82. package/lib-web/src/resource-selection-optimizer/in-clause-under-conjunction.d.ts +1 -3
  83. package/lib-web/src/resource-selection-optimizer/in-clause-under-conjunction.js +38 -83
  84. package/lib-web/src/resource-selection-optimizer/in-clause-under-conjunction.js.map +1 -1
  85. package/lib-web/src/resource-selection-optimizer/index.d.ts +0 -0
  86. package/lib-web/src/resource-selection-optimizer/index.js +0 -0
  87. package/lib-web/src/resource-selection-optimizer/index.js.map +0 -0
  88. package/package.json +3 -3
  89. package/scripts/set-own-version.js +0 -0
  90. package/src/ddf-csv.ts +42 -10
  91. package/src/ddfcsv-error.ts +0 -0
  92. package/src/ddfcsv-reader.ts +1 -1
  93. package/src/file-readers/backend-file-reader.ts +0 -0
  94. package/src/file-readers/frontend-file-reader.ts +0 -0
  95. package/src/file-readers/github-path-adapter.ts +0 -0
  96. package/src/index-web.ts +0 -0
  97. package/src/index.ts +0 -0
  98. package/src/interfaces.ts +0 -0
  99. package/src/resource-selection-optimizer/in-clause-under-conjunction.ts +39 -101
  100. package/src/resource-selection-optimizer/index.ts +0 -0
  101. package/src/test-cases/concepts.ts +0 -0
  102. package/src/test-cases/entities.ts +0 -0
  103. package/test/assets-fixtures/world-50m.json +0 -0
  104. package/test/assets.spec.ts +0 -0
  105. package/test/common.ts +0 -0
  106. package/test/definition/concepts-definition.spec.ts +0 -0
  107. package/test/definition/datapoints-definition.spec.ts +1 -1
  108. package/test/definition/entities-definition.spec.ts +0 -0
  109. package/test/definition/schema-definition.spec.ts +0 -0
  110. package/test/diagnostics.spec.ts +0 -0
  111. package/test/features-service.spec.ts +0 -0
  112. package/test/high-load.spec.ts +0 -0
  113. package/test/main.spec.ts +8 -4
  114. package/test/mocha.opts +0 -0
  115. package/test/multi-instances.spec.ts +0 -0
  116. package/test/result-fixtures/datapoints-assets.json +0 -0
  117. package/test/result-fixtures/in-clause-under-conjunction-1.json +100 -100
  118. package/test/result-fixtures/in-clause-under-conjunction-2.json +70169 -70169
  119. package/test/result-fixtures/multi-instances/concepts-sg.json +0 -0
  120. package/test/result-fixtures/multi-instances/concepts-soderstornsmodellen.json +0 -0
  121. package/test/result-fixtures/multi-instances/datapoints-sg.json +0 -0
  122. package/test/result-fixtures/multi-instances/datapoints-soderstornsmodellen.json +0 -0
  123. package/test/result-fixtures/multi-instances/entities-sg.json +2 -2
  124. package/test/result-fixtures/multi-instances/entities-soderstornsmodellen.json +0 -0
  125. package/test/result-fixtures/multi-instances/schema-sg.json +0 -0
  126. package/test/result-fixtures/multi-instances/schema-soderstornsmodellen.json +0 -0
  127. package/test/schema.spec.ts +0 -0
  128. package/test/tslint.json +3 -2
  129. package/tsconfig-web.json +0 -0
  130. package/tsconfig.json +0 -0
  131. package/tslint.json +1 -1
  132. 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.2",
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": "5.11.0",
129
- "tslint-no-unused-expression-chai": "0.1.3",
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, baseOptions: IBaseReaderOptions) {
169
- // console.log(JSON.stringify(queryParam, null, '\t'))
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, options: IBaseReaderOptions) {
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
- a.$and.push(b);
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 query({
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 => query({
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
- result[field.name] = field.constraints.enum;
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
  }
File without changes
@@ -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
- const relatedFeatures = compact(featureDetectors.map(detector => detector(this.query, this.conceptsLookup)));
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(): InClauseUnderConjunction {
84
- const joinKeys = keys(this.flow.joinObject);
85
-
86
- this.flow.processableClauses = [];
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
- for (const joinKey of joinKeys) {
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
- if (this.singleAndField(where)) {
92
- this.flow.processableClauses.push(...flattenDeep(where[KEY_AND].map(el => this.getProcessableClauses(el))));
93
- } else if (this.singleOrField(where)) {
94
- this.flow.processableClauses.push(...flattenDeep(where[KEY_OR].map(el => this.getProcessableClauses(el))));
95
- } else {
96
- this.flow.processableClauses.push(...this.getProcessableClauses(where));
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 primaryKey = getFirstKey(clause);
101
+ const key = clause.key;
111
102
 
112
- if (head(schemaResourceRecord.primaryKey) === 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, primaryKey);
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
- entities: this.flow.entityFilesNames,
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 entityValuesFromClause) {
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
- for (const schemaResourceRecord of this.datapackage.ddfSchema.concepts) {
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
- let appropriateClauseKey;
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
- if (!appropriateClauseKey || size < appropriateClauseSize) {
238
- appropriateClauseKey = key;
239
- appropriateClauseSize = size;
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
- if (!this.flow.filesGroupsByClause.get(appropriateClauseKey)) {
244
- return [];
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
- if (!startsWith(key, '$') && isOneKeyBased(clause[key])) {
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 result;
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 singleOrField(clause): boolean {
280
- return isOneKeyBased(clause) && !!get(clause, KEY_OR);
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
File without changes
package/test/common.ts CHANGED
File without changes
File without changes
@@ -232,7 +232,7 @@ describe('Datapoints definition errors in query', () => {
232
232
  where: {
233
233
  country_code: {
234
234
  $in: [
235
- '900'
235
+ 900
236
236
  ]
237
237
  }
238
238
  }
File without changes
File without changes
File without changes
File without changes
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 ( in JSON at position 0.`);
131
- expect(error.details).to.equal('Unexpected token ( in JSON at position 0');
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 ( in JSON at position 0.`);
249
- expect(error.details).to.equal('Unexpected token ( in JSON at position 0');
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