@vizabi/reader-ddfcsv 4.5.3 → 4.5.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 (137) hide show
  1. package/.nyc_output/574fe7f0-58f6-4de2-9524-16e72b784218.json +1 -0
  2. package/.nyc_output/9aede69f-00e6-432d-bdeb-2c9f4084a6dc.json +1 -0
  3. package/.nyc_output/processinfo/574fe7f0-58f6-4de2-9524-16e72b784218.json +1 -0
  4. package/.nyc_output/processinfo/9aede69f-00e6-432d-bdeb-2c9f4084a6dc.json +1 -0
  5. package/.nyc_output/processinfo/index.json +1 -0
  6. package/LICENSE +0 -0
  7. package/README.md +2 -2
  8. package/coverage/base.css +224 -0
  9. package/coverage/block-navigation.js +87 -0
  10. package/coverage/favicon.png +0 -0
  11. package/coverage/index.html +161 -0
  12. package/coverage/prettify.css +1 -0
  13. package/coverage/prettify.js +2 -0
  14. package/coverage/sort-arrow-sprite.png +0 -0
  15. package/coverage/sorter.js +210 -0
  16. package/coverage/src/ddf-csv.ts.html +2866 -0
  17. package/coverage/src/ddfcsv-error.ts.html +148 -0
  18. package/coverage/src/ddfcsv-reader.ts.html +538 -0
  19. package/coverage/src/file-readers/backend-file-reader.ts.html +175 -0
  20. package/coverage/src/file-readers/github-path-adapter.ts.html +244 -0
  21. package/coverage/src/file-readers/index.html +131 -0
  22. package/coverage/src/index.html +176 -0
  23. package/coverage/src/index.ts.html +145 -0
  24. package/coverage/src/interfaces.ts.html +196 -0
  25. package/coverage/src/resource-selection-optimizer/in-clause-under-conjunction.ts.html +745 -0
  26. package/coverage/src/resource-selection-optimizer/index.html +131 -0
  27. package/coverage/src/resource-selection-optimizer/index.ts.html +118 -0
  28. package/coverage/src/test-cases/concepts.ts.html +166 -0
  29. package/coverage/src/test-cases/entities.ts.html +241 -0
  30. package/coverage/src/test-cases/index.html +131 -0
  31. package/dist/reader-ddfcsv.js +15 -1
  32. package/dist/reader-ddfcsv.js.map +1 -0
  33. package/dist/stats.html +4950 -0
  34. package/icon.png +0 -0
  35. package/lib/src/ddf-csv.d.ts +0 -0
  36. package/lib/src/ddf-csv.js +13 -14
  37. package/lib/src/ddf-csv.js.map +1 -1
  38. package/lib/src/ddfcsv-error.d.ts +0 -0
  39. package/lib/src/ddfcsv-error.js +0 -0
  40. package/lib/src/ddfcsv-error.js.map +0 -0
  41. package/lib/src/ddfcsv-reader.d.ts +0 -0
  42. package/lib/src/ddfcsv-reader.js +5 -5
  43. package/lib/src/ddfcsv-reader.js.map +1 -1
  44. package/lib/src/file-readers/backend-file-reader.d.ts +0 -0
  45. package/lib/src/file-readers/backend-file-reader.js +0 -0
  46. package/lib/src/file-readers/backend-file-reader.js.map +0 -0
  47. package/lib/src/file-readers/github-path-adapter.d.ts +0 -0
  48. package/lib/src/file-readers/github-path-adapter.js +0 -0
  49. package/lib/src/file-readers/github-path-adapter.js.map +0 -0
  50. package/lib/src/index.d.ts +0 -0
  51. package/lib/src/index.js +2 -2
  52. package/lib/src/index.js.map +0 -0
  53. package/lib/src/interfaces.d.ts +0 -0
  54. package/lib/src/interfaces.js +0 -0
  55. package/lib/src/interfaces.js.map +0 -0
  56. package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.d.ts +0 -0
  57. package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.js +16 -17
  58. package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.js.map +1 -1
  59. package/lib/src/resource-selection-optimizer/index.d.ts +0 -0
  60. package/lib/src/resource-selection-optimizer/index.js +2 -2
  61. package/lib/src/resource-selection-optimizer/index.js.map +1 -1
  62. package/lib-web/src/ddf-csv.d.ts +0 -0
  63. package/lib-web/src/ddf-csv.js +30 -34
  64. package/lib-web/src/ddf-csv.js.map +1 -1
  65. package/lib-web/src/ddfcsv-error.d.ts +0 -0
  66. package/lib-web/src/ddfcsv-error.js +5 -9
  67. package/lib-web/src/ddfcsv-error.js.map +1 -1
  68. package/lib-web/src/ddfcsv-reader.d.ts +0 -0
  69. package/lib-web/src/ddfcsv-reader.js +16 -19
  70. package/lib-web/src/ddfcsv-reader.js.map +1 -1
  71. package/lib-web/src/file-readers/frontend-file-reader.d.ts +0 -0
  72. package/lib-web/src/file-readers/frontend-file-reader.js +1 -5
  73. package/lib-web/src/file-readers/frontend-file-reader.js.map +1 -1
  74. package/lib-web/src/file-readers/github-path-adapter.d.ts +0 -0
  75. package/lib-web/src/file-readers/github-path-adapter.js +1 -4
  76. package/lib-web/src/file-readers/github-path-adapter.js.map +1 -1
  77. package/lib-web/src/index-web.d.ts +0 -0
  78. package/lib-web/src/index-web.js +9 -14
  79. package/lib-web/src/index-web.js.map +1 -1
  80. package/lib-web/src/interfaces.d.ts +0 -0
  81. package/lib-web/src/interfaces.js +1 -2
  82. package/lib-web/src/interfaces.js.map +0 -0
  83. package/lib-web/src/resource-selection-optimizer/in-clause-under-conjunction.d.ts +0 -0
  84. package/lib-web/src/resource-selection-optimizer/in-clause-under-conjunction.js +12 -17
  85. package/lib-web/src/resource-selection-optimizer/in-clause-under-conjunction.js.map +1 -1
  86. package/lib-web/src/resource-selection-optimizer/index.d.ts +0 -0
  87. package/lib-web/src/resource-selection-optimizer/index.js +4 -7
  88. package/lib-web/src/resource-selection-optimizer/index.js.map +1 -1
  89. package/package.json +94 -129
  90. package/rollup.config.mjs +36 -0
  91. package/scripts/set-own-version.js +0 -0
  92. package/src/ddf-csv.ts +927 -927
  93. package/src/ddfcsv-error.ts +0 -0
  94. package/src/ddfcsv-reader.ts +151 -151
  95. package/src/file-readers/backend-file-reader.ts +0 -0
  96. package/src/file-readers/frontend-file-reader.ts +0 -0
  97. package/src/file-readers/github-path-adapter.ts +0 -0
  98. package/src/index-web.ts +0 -0
  99. package/src/index.ts +0 -0
  100. package/src/interfaces.ts +0 -0
  101. package/src/resource-selection-optimizer/in-clause-under-conjunction.ts +220 -220
  102. package/src/resource-selection-optimizer/index.ts +11 -11
  103. package/src/test-cases/concepts.ts +0 -0
  104. package/src/test-cases/entities.ts +52 -52
  105. package/test/assets-fixtures/world-50m.json +0 -0
  106. package/test/assets.spec.ts +0 -0
  107. package/test/common.ts +1 -1
  108. package/test/definition/concepts-definition.spec.ts +0 -0
  109. package/test/definition/datapoints-definition.spec.ts +1 -1
  110. package/test/definition/entities-definition.spec.ts +264 -264
  111. package/test/definition/schema-definition.spec.ts +0 -0
  112. package/test/diagnostics.spec.ts +0 -0
  113. package/test/features-service.spec.ts +95 -95
  114. package/test/high-load.spec.ts +0 -0
  115. package/test/main.spec.ts +0 -0
  116. package/test/multi-instances.spec.ts +0 -0
  117. package/test/result-fixtures/datapoints-assets.json +0 -0
  118. package/test/result-fixtures/in-clause-under-conjunction-1.json +0 -0
  119. package/test/result-fixtures/in-clause-under-conjunction-2.json +0 -0
  120. package/test/result-fixtures/multi-instances/concepts-sg.json +0 -0
  121. package/test/result-fixtures/multi-instances/concepts-soderstornsmodellen.json +0 -0
  122. package/test/result-fixtures/multi-instances/datapoints-sg.json +0 -0
  123. package/test/result-fixtures/multi-instances/datapoints-soderstornsmodellen.json +0 -0
  124. package/test/result-fixtures/multi-instances/entities-sg.json +0 -0
  125. package/test/result-fixtures/multi-instances/entities-soderstornsmodellen.json +0 -0
  126. package/test/result-fixtures/multi-instances/schema-sg.json +0 -0
  127. package/test/result-fixtures/multi-instances/schema-soderstornsmodellen.json +0 -0
  128. package/test/schema.spec.ts +0 -0
  129. package/test/tslint.json +0 -0
  130. package/tsconfig-web.json +41 -41
  131. package/tsconfig.json +40 -37
  132. package/tslint.json +0 -0
  133. package/.travis.yml +0 -37
  134. package/deploy.js +0 -87
  135. package/dist/reader-ddfcsv-polyfill.js +0 -2
  136. package/dist/reader-ddfcsv-polyfill.js.map +0 -1
  137. package/test/mocha.opts +0 -7
@@ -1,220 +1,220 @@
1
- import * as head from 'lodash.head';
2
- import * as values from 'lodash.values';
3
- import * as keys from 'lodash.keys';
4
- import * as get from 'lodash.get';
5
- import * as isEmpty from 'lodash.isempty';
6
- import * as startsWith from 'lodash.startswith';
7
- import * as includes from 'lodash.includes';
8
- import * as compact from 'lodash.compact';
9
- import { DdfCsvError } from '../ddfcsv-error';
10
- import { IDatapackage, IResourceSelectionOptimizer, IResourceRead, IBaseReaderOptions } from '../interfaces';
11
- import { QueryFeature, featureDetectors, IQuery } from '@vizabi/ddf-query-validator';
12
-
13
- const WHERE_KEYWORD = 'where';
14
- const JOIN_KEYWORD = 'join';
15
- const KEY_IN = '$in';
16
- const KEY_NIN = '$nin';
17
- const KEY_AND = '$and';
18
- const KEY_OR = '$or';
19
-
20
- export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
21
- private flow: any = {};
22
- private fileReader: IResourceRead;
23
- private datasetPath: string;
24
- private query: IQuery;
25
- private datapackage: IDatapackage;
26
- private conceptsLookup;
27
-
28
- constructor(private parent, queryParam, private options: IBaseReaderOptions) {
29
- this.fileReader = options.fileReader;
30
- this.datasetPath = options.basePath;
31
- this.query = queryParam;
32
- this.datapackage = options.datapackage;
33
- this.conceptsLookup = options.conceptsLookup;
34
- }
35
-
36
- isMatched(): boolean {
37
- this.flow.joinObject = get(this.query, JOIN_KEYWORD);
38
-
39
- return this.query.from === "datapoints" && this.flow.joinObject;
40
- }
41
-
42
- async getRecommendedFilesSet(): Promise<string[]> {
43
- const { debug, error, warning } = this.options.diagnostic.prepareDiagnosticFor('getRecommendedFilesSet');
44
-
45
- if (this.isMatched()) {
46
- debug('plugin matched');
47
-
48
- let result;
49
- try {
50
- this.flow.processableClauses = await this.collectProcessableClauses();
51
- if (!this.flow.processableClauses) return [];
52
- this.collectEntityFilesNames();
53
- const data = await this.collectEntities();
54
- this.fillEntityValuesHash(data);
55
- this.getFilesGroupsQueryClause();
56
- result = this.getOptimalFilesGroup();
57
- } catch (err) {
58
- error('wrong data processing', err);
59
- return [];
60
- }
61
-
62
- debug('recommended files found', result);
63
-
64
- return result;
65
- } else {
66
- const message = `Plugin "InClauseUnderConjunction" is not matched!`;
67
- warning(message);
68
- throw new DdfCsvError(message, 'InClauseUnderConjunction plugin');
69
- }
70
- }
71
-
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);
76
-
77
- return Promise.all(joinKeys.map(joinKey => {
78
- const key = this.flow.joinObject[joinKey].key;
79
- const where = get(this.flow.joinObject, `${joinKey}.${WHERE_KEYWORD}`, {});
80
-
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
- }));
91
-
92
- }
93
-
94
- private collectEntityFilesNames(): InClauseUnderConjunction {
95
- this.flow.entityFilesNames = new Set();
96
- this.flow.entityResources = new Set();
97
- this.flow.fileNameToPrimaryKeyHash = new Map();
98
-
99
- for (const schemaResourceRecord of this.datapackage.ddfSchema.entities) {
100
- for (const clause of this.flow.processableClauses) {
101
- const key = clause.key;
102
-
103
- if (head(schemaResourceRecord.primaryKey) === key) {
104
- for (const resourceName of schemaResourceRecord.resources) {
105
- const resource = this.options.resourcesLookup.get(resourceName);
106
-
107
- this.flow.entityResources.add(resource);
108
- this.flow.entityFilesNames.add(resource.path);
109
- this.flow.fileNameToPrimaryKeyHash.set(resource.path, key);
110
- }
111
- }
112
- }
113
- }
114
-
115
- return this;
116
- }
117
-
118
- private collectEntities(): Promise<any> {
119
- const self = this;
120
- const actions = [...self.flow.entityResources].map(resource => {
121
- return (resource.data || (resource.data = self.parent.loadFile(resource.path, self.options)))
122
- .then(data => ({result: data, file: resource.path}));
123
- });
124
-
125
- return Promise.all(actions);
126
- }
127
-
128
- private fillEntityValuesHash(entitiesData): InClauseUnderConjunction {
129
- const getSubdomainsFromRecord = record => compact(keys(record)
130
- .filter(key => startsWith(key, 'is--') && (record[key] === true))
131
- .map(key => key.replace(/^is--/, '')));
132
-
133
- this.flow.entityValueToFileHash = new Map();
134
- this.flow.entityValueToDomainHash = new Map();
135
-
136
- for (const entityFileDescriptor of entitiesData) {
137
- for (const entityRecord of entityFileDescriptor.result.data) {
138
- const primaryKeyForThisFile = this.flow.fileNameToPrimaryKeyHash.get(entityFileDescriptor.file);
139
- const domainsForCurrentRecord = [...getSubdomainsFromRecord(entityRecord)];
140
-
141
- if (isEmpty(domainsForCurrentRecord)) {
142
- domainsForCurrentRecord.push(primaryKeyForThisFile);
143
- }
144
-
145
- const primaryKeyCellValue = entityRecord[primaryKeyForThisFile] || entityRecord[domainsForCurrentRecord[0]];
146
-
147
- this.flow.entityValueToDomainHash.set(primaryKeyCellValue, domainsForCurrentRecord);
148
- this.flow.entityValueToFileHash.set(primaryKeyCellValue, entityFileDescriptor.file);
149
- }
150
- }
151
-
152
- return this;
153
- }
154
-
155
- private getFilesGroupsQueryClause(): InClauseUnderConjunction {
156
- const filesGroupsByClause = new Map();
157
-
158
- for (const clause of this.flow.processableClauses) {
159
- const filesGroupByClause = {
160
- datapoints: new Set()
161
- };
162
-
163
- for (const entityValueFromClause of clause.entities) {
164
-
165
- const entitiesByQuery = this.flow.entityValueToDomainHash.get(entityValueFromClause);
166
-
167
- for (const entityByQuery of entitiesByQuery) {
168
- for (const schemaResourceRecord of this.datapackage.ddfSchema.datapoints) {
169
- for (const resourceName of schemaResourceRecord.resources) {
170
- if (includes(schemaResourceRecord.primaryKey, entityByQuery)) {
171
- const resource = this.options.resourcesLookup.get(resourceName);
172
- const constraint = resource.constraints?.[entityByQuery];
173
- if ( constraint ) {
174
- if (constraint.includes(entityValueFromClause)) {
175
- filesGroupByClause.datapoints.add(resource.path);
176
- }
177
- } else {
178
- filesGroupByClause.datapoints.add(resource.path);
179
- }
180
- }
181
- }
182
- }
183
- }
184
- }
185
-
186
- filesGroupsByClause.set(clause.key, filesGroupByClause);
187
- }
188
-
189
- this.flow.filesGroupsByClause = filesGroupsByClause;
190
-
191
- return this;
192
- }
193
-
194
- private getOptimalFilesGroup(): string[] {
195
-
196
- const entities = this.flow.entityFilesNames;
197
-
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);
202
- }
203
- }
204
-
205
- const clauseKeys = this.flow.filesGroupsByClause.keys();
206
- let datapoints = Array.from(this.flow.filesGroupsByClause.get(clauseKeys.next().value).datapoints);
207
-
208
- for (const key of clauseKeys) {
209
- datapoints = this.intersectArray(datapoints, Array.from(this.flow.filesGroupsByClause.get(key).datapoints));
210
- }
211
-
212
- return [...Array.from(concepts), ...Array.from(entities)].concat(datapoints) as string[];
213
- }
214
-
215
-
216
- private intersectArray(array1, array2) {
217
- return array1.filter(value => array2.includes(value));
218
- }
219
-
220
- }
1
+ import head from 'lodash-es/head';
2
+ import values from 'lodash-es/values';
3
+ import keys from 'lodash-es/keys';
4
+ import get from 'lodash-es/get';
5
+ import isEmpty from 'lodash-es/isEmpty';
6
+ import startsWith from 'lodash-es/startsWith';
7
+ import includes from 'lodash-es/includes';
8
+ import compact from 'lodash-es/compact';
9
+ import { DdfCsvError } from '../ddfcsv-error';
10
+ import { IDatapackage, IResourceSelectionOptimizer, IResourceRead, IBaseReaderOptions } from '../interfaces';
11
+ import { QueryFeature, featureDetectors, IQuery } from '@vizabi/ddf-query-validator';
12
+
13
+ const WHERE_KEYWORD = 'where';
14
+ const JOIN_KEYWORD = 'join';
15
+ const KEY_IN = '$in';
16
+ const KEY_NIN = '$nin';
17
+ const KEY_AND = '$and';
18
+ const KEY_OR = '$or';
19
+
20
+ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
21
+ private flow: any = {};
22
+ private fileReader: IResourceRead;
23
+ private datasetPath: string;
24
+ private query: IQuery;
25
+ private datapackage: IDatapackage;
26
+ private conceptsLookup;
27
+
28
+ constructor(private parent, queryParam, private options: IBaseReaderOptions) {
29
+ this.fileReader = options.fileReader;
30
+ this.datasetPath = options.basePath;
31
+ this.query = queryParam;
32
+ this.datapackage = options.datapackage;
33
+ this.conceptsLookup = options.conceptsLookup;
34
+ }
35
+
36
+ isMatched(): boolean {
37
+ this.flow.joinObject = get(this.query, JOIN_KEYWORD);
38
+
39
+ return this.query.from === "datapoints" && this.flow.joinObject;
40
+ }
41
+
42
+ async getRecommendedFilesSet(): Promise<string[]> {
43
+ const { debug, error, warning } = this.options.diagnostic.prepareDiagnosticFor('getRecommendedFilesSet');
44
+
45
+ if (this.isMatched()) {
46
+ debug('plugin matched');
47
+
48
+ let result;
49
+ try {
50
+ this.flow.processableClauses = await this.collectProcessableClauses();
51
+ if (!this.flow.processableClauses) return [];
52
+ this.collectEntityFilesNames();
53
+ const data = await this.collectEntities();
54
+ this.fillEntityValuesHash(data);
55
+ this.getFilesGroupsQueryClause();
56
+ result = this.getOptimalFilesGroup();
57
+ } catch (err) {
58
+ error('wrong data processing', err);
59
+ return [];
60
+ }
61
+
62
+ debug('recommended files found', result);
63
+
64
+ return result;
65
+ } else {
66
+ const message = `Plugin "InClauseUnderConjunction" is not matched!`;
67
+ warning(message);
68
+ throw new DdfCsvError(message, 'InClauseUnderConjunction plugin');
69
+ }
70
+ }
71
+
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);
76
+
77
+ return Promise.all(joinKeys.map(joinKey => {
78
+ const key = this.flow.joinObject[joinKey].key;
79
+ const where = get(this.flow.joinObject, `${joinKey}.${WHERE_KEYWORD}`, {});
80
+
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
+ }));
91
+
92
+ }
93
+
94
+ private collectEntityFilesNames(): InClauseUnderConjunction {
95
+ this.flow.entityFilesNames = new Set();
96
+ this.flow.entityResources = new Set();
97
+ this.flow.fileNameToPrimaryKeyHash = new Map();
98
+
99
+ for (const schemaResourceRecord of this.datapackage.ddfSchema.entities) {
100
+ for (const clause of this.flow.processableClauses) {
101
+ const key = clause.key;
102
+
103
+ if (head(schemaResourceRecord.primaryKey) === key) {
104
+ for (const resourceName of schemaResourceRecord.resources) {
105
+ const resource = this.options.resourcesLookup.get(resourceName);
106
+
107
+ this.flow.entityResources.add(resource);
108
+ this.flow.entityFilesNames.add(resource.path);
109
+ this.flow.fileNameToPrimaryKeyHash.set(resource.path, key);
110
+ }
111
+ }
112
+ }
113
+ }
114
+
115
+ return this;
116
+ }
117
+
118
+ private collectEntities(): Promise<any> {
119
+ const self = this;
120
+ const actions = [...self.flow.entityResources].map(resource => {
121
+ return (resource.data || (resource.data = self.parent.loadFile(resource.path, self.options)))
122
+ .then(data => ({result: data, file: resource.path}));
123
+ });
124
+
125
+ return Promise.all(actions);
126
+ }
127
+
128
+ private fillEntityValuesHash(entitiesData): InClauseUnderConjunction {
129
+ const getSubdomainsFromRecord = record => compact(keys(record)
130
+ .filter(key => startsWith(key, 'is--') && (record[key] === true))
131
+ .map(key => key.replace(/^is--/, '')));
132
+
133
+ this.flow.entityValueToFileHash = new Map();
134
+ this.flow.entityValueToDomainHash = new Map();
135
+
136
+ for (const entityFileDescriptor of entitiesData) {
137
+ for (const entityRecord of entityFileDescriptor.result.data) {
138
+ const primaryKeyForThisFile = this.flow.fileNameToPrimaryKeyHash.get(entityFileDescriptor.file);
139
+ const domainsForCurrentRecord = [...getSubdomainsFromRecord(entityRecord)];
140
+
141
+ if (isEmpty(domainsForCurrentRecord)) {
142
+ domainsForCurrentRecord.push(primaryKeyForThisFile);
143
+ }
144
+
145
+ const primaryKeyCellValue = entityRecord[primaryKeyForThisFile] || entityRecord[domainsForCurrentRecord[0]];
146
+
147
+ this.flow.entityValueToDomainHash.set(primaryKeyCellValue, domainsForCurrentRecord);
148
+ this.flow.entityValueToFileHash.set(primaryKeyCellValue, entityFileDescriptor.file);
149
+ }
150
+ }
151
+
152
+ return this;
153
+ }
154
+
155
+ private getFilesGroupsQueryClause(): InClauseUnderConjunction {
156
+ const filesGroupsByClause = new Map();
157
+
158
+ for (const clause of this.flow.processableClauses) {
159
+ const filesGroupByClause = {
160
+ datapoints: new Set()
161
+ };
162
+
163
+ for (const entityValueFromClause of clause.entities) {
164
+
165
+ const entitiesByQuery = this.flow.entityValueToDomainHash.get(entityValueFromClause);
166
+
167
+ for (const entityByQuery of entitiesByQuery) {
168
+ for (const schemaResourceRecord of this.datapackage.ddfSchema.datapoints) {
169
+ for (const resourceName of schemaResourceRecord.resources) {
170
+ if (includes(schemaResourceRecord.primaryKey, entityByQuery)) {
171
+ const resource = this.options.resourcesLookup.get(resourceName);
172
+ const constraint = resource.constraints?.[entityByQuery];
173
+ if ( constraint ) {
174
+ if (constraint.includes(entityValueFromClause)) {
175
+ filesGroupByClause.datapoints.add(resource.path);
176
+ }
177
+ } else {
178
+ filesGroupByClause.datapoints.add(resource.path);
179
+ }
180
+ }
181
+ }
182
+ }
183
+ }
184
+ }
185
+
186
+ filesGroupsByClause.set(clause.key, filesGroupByClause);
187
+ }
188
+
189
+ this.flow.filesGroupsByClause = filesGroupsByClause;
190
+
191
+ return this;
192
+ }
193
+
194
+ private getOptimalFilesGroup(): string[] {
195
+
196
+ const entities = this.flow.entityFilesNames;
197
+
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);
202
+ }
203
+ }
204
+
205
+ const clauseKeys = this.flow.filesGroupsByClause.keys();
206
+ let datapoints = Array.from(this.flow.filesGroupsByClause.get(clauseKeys.next().value).datapoints);
207
+
208
+ for (const key of clauseKeys) {
209
+ datapoints = this.intersectArray(datapoints, Array.from(this.flow.filesGroupsByClause.get(key).datapoints));
210
+ }
211
+
212
+ return [...Array.from(concepts), ...Array.from(entities)].concat(datapoints) as string[];
213
+ }
214
+
215
+
216
+ private intersectArray(array1, array2) {
217
+ return array1.filter(value => array2.includes(value));
218
+ }
219
+
220
+ }
@@ -1,11 +1,11 @@
1
- import { InClauseUnderConjunction } from './in-clause-under-conjunction';
2
- import * as head from 'lodash.head';
3
- import { IBaseReaderOptions, IResourceSelectionOptimizer } from '../interfaces';
4
-
5
- export function getAppropriatePlugin(parent, queryParam, options: IBaseReaderOptions): IResourceSelectionOptimizer {
6
- const plugins = [
7
- new InClauseUnderConjunction(parent, queryParam, options)
8
- ];
9
-
10
- return head(plugins.filter(plugin => plugin.isMatched()));
11
- }
1
+ import { InClauseUnderConjunction } from './in-clause-under-conjunction';
2
+ import head from 'lodash-es/head';
3
+ import { IBaseReaderOptions, IResourceSelectionOptimizer } from '../interfaces';
4
+
5
+ export function getAppropriatePlugin(parent, queryParam, options: IBaseReaderOptions): IResourceSelectionOptimizer {
6
+ const plugins = [
7
+ new InClauseUnderConjunction(parent, queryParam, options)
8
+ ];
9
+
10
+ return head(plugins.filter(plugin => plugin.isMatched()));
11
+ }
File without changes
@@ -1,52 +1,52 @@
1
- import {
2
- BASE_PATH,
3
- EMPTY_TRANSLATIONS_PATH,
4
- WS_TESTING_PATH
5
- } from '../../test/common';
6
- import {
7
- CONCEPT_TYPE_ENTITY_DOMAIN,
8
- CONCEPT_TYPE_ENTITY_SET,
9
- isEntityDomainOrSet,
10
- RESERVED_CONCEPT,
11
- RESERVED_CONCEPT_TYPE,
12
- RESERVED_DOMAIN,
13
- RESERVED_DRILL_UP
14
- } from '@vizabi/ddf-query-validator';
15
-
16
- import * as map from 'lodash.map';
17
- import * as flatMap from 'lodash.flatmap';
18
- import * as isNil from 'lodash.isnil';
19
- import * as flatten from 'lodash.flatten';
20
-
21
- const ALL_OPERATORS: string[] = [null, '.', '.is--'];
22
- const ALL_CONCEPTS: string[] = ['', ' ', RESERVED_CONCEPT, RESERVED_CONCEPT_TYPE, RESERVED_DOMAIN, RESERVED_DRILL_UP, 'company', 'english_speaking', 'company_scale', 'name', 'anno', 'lines_of_code', 'region', 'country', 'latitude', 'longitude', 'full_name_changed', 'project', 'domain', 'additional_column', 'meeting_style', 'popular_appeal', 'methodology'];
23
- const ALL_ENTITY_SETS_AND_DOMAINS: string[] = ['company', 'english_speaking', 'company_scale', 'region', 'project'];
24
-
25
- export const initData = {};
26
- export const testsDescriptors = ALL_ENTITY_SETS_AND_DOMAINS.reduce((acc, entitySetOrDomain: string) => {
27
- const BINARY_OPERATORS = [...flatMap(ALL_CONCEPTS, (parent: string) => map(ALL_CONCEPTS, (child) => [parent, child]))];
28
- const UNARY_OPERATORS = [...ALL_CONCEPTS];
29
-
30
- const description = `Autogenerated tests for ${entitySetOrDomain}`;
31
-
32
- acc[description] = flatten(
33
- ALL_OPERATORS.map((operator: string) => {
34
- const CONCEPTS_CLAUSE: any[] = isNil(operator) ? UNARY_OPERATORS : map([...BINARY_OPERATORS], (args: string[]) => args.join(operator));
35
-
36
- return CONCEPTS_CLAUSE.map((clause: string) => ({
37
- itTitle: `should be fine for ${clause}`,
38
- query: {
39
- repositoryPath: BASE_PATH + WS_TESTING_PATH + '/master-HEAD',
40
- dataset: WS_TESTING_PATH,
41
- from: 'entities',
42
- select: {key: [entitySetOrDomain]},
43
- where: {
44
- [clause]: true
45
- }
46
- }
47
- }));
48
- })
49
- );
50
-
51
- return acc;
52
- }, {});
1
+ import {
2
+ BASE_PATH,
3
+ EMPTY_TRANSLATIONS_PATH,
4
+ WS_TESTING_PATH
5
+ } from '../../test/common';
6
+ import {
7
+ CONCEPT_TYPE_ENTITY_DOMAIN,
8
+ CONCEPT_TYPE_ENTITY_SET,
9
+ isEntityDomainOrSet,
10
+ RESERVED_CONCEPT,
11
+ RESERVED_CONCEPT_TYPE,
12
+ RESERVED_DOMAIN,
13
+ RESERVED_DRILL_UP
14
+ } from '@vizabi/ddf-query-validator';
15
+
16
+ import map from 'lodash-es/map';
17
+ import flatMap from 'lodash-es/flatMap';
18
+ import isNil from 'lodash-es/isNil';
19
+ import flatten from 'lodash-es/flatten';
20
+
21
+ const ALL_OPERATORS: string[] = [null, '.', '.is--'];
22
+ const ALL_CONCEPTS: string[] = ['', ' ', RESERVED_CONCEPT, RESERVED_CONCEPT_TYPE, RESERVED_DOMAIN, RESERVED_DRILL_UP, 'company', 'english_speaking', 'company_scale', 'name', 'anno', 'lines_of_code', 'region', 'country', 'latitude', 'longitude', 'full_name_changed', 'project', 'domain', 'additional_column', 'meeting_style', 'popular_appeal', 'methodology'];
23
+ const ALL_ENTITY_SETS_AND_DOMAINS: string[] = ['company', 'english_speaking', 'company_scale', 'region', 'project'];
24
+
25
+ export const initData = {};
26
+ export const testsDescriptors = ALL_ENTITY_SETS_AND_DOMAINS.reduce((acc, entitySetOrDomain: string) => {
27
+ const BINARY_OPERATORS = [...flatMap(ALL_CONCEPTS, (parent: string) => map(ALL_CONCEPTS, (child) => [parent, child]))];
28
+ const UNARY_OPERATORS = [...ALL_CONCEPTS];
29
+
30
+ const description = `Autogenerated tests for ${entitySetOrDomain}`;
31
+
32
+ acc[description] = flatten(
33
+ ALL_OPERATORS.map((operator: string) => {
34
+ const CONCEPTS_CLAUSE: any[] = isNil(operator) ? UNARY_OPERATORS : map([...BINARY_OPERATORS], (args: string[]) => args.join(operator));
35
+
36
+ return CONCEPTS_CLAUSE.map((clause: string) => ({
37
+ itTitle: `should be fine for ${clause}`,
38
+ query: {
39
+ repositoryPath: BASE_PATH + WS_TESTING_PATH + '/master-HEAD',
40
+ dataset: WS_TESTING_PATH,
41
+ from: 'entities',
42
+ select: {key: [entitySetOrDomain]},
43
+ where: {
44
+ [clause]: true
45
+ }
46
+ }
47
+ }));
48
+ })
49
+ );
50
+
51
+ return acc;
52
+ }, {});
File without changes
File without changes
package/test/common.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as chai from 'chai';
2
- import * as _ from 'lodash';
2
+ import * as _ from 'lodash-es';
3
3
 
4
4
  const expect = chai.expect;
5
5
 
File without changes
@@ -1,6 +1,6 @@
1
1
  import * as chai from 'chai';
2
2
  import { getDDFCsvReaderObject } from '../../src/index';
3
- import * as _ from 'lodash';
3
+ // import * as _ from 'lodash';
4
4
  import {
5
5
  BASE_PATH,
6
6
  BIG_PATH,