@vizabi/reader-ddfcsv 4.2.0 → 4.3.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/dist/reader-ddfcsv-polyfill.js +1 -1
- package/dist/reader-ddfcsv-polyfill.js.map +1 -1
- package/dist/reader-ddfcsv.js +7 -1
- package/dist/reader-ddfcsv.js.map +1 -1
- package/lib/src/ddf-csv.d.ts +1 -0
- package/lib/src/ddf-csv.js +20 -7
- package/lib/src/ddf-csv.js.map +1 -1
- package/lib/src/ddfcsv-reader.js +1 -1
- package/lib/src/interfaces.d.ts +1 -0
- package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.d.ts +2 -2
- package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.js +17 -42
- package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.js.map +1 -1
- package/lib/src/resource-selection-optimizer/index.d.ts +1 -1
- package/lib/src/resource-selection-optimizer/index.js +2 -2
- package/lib/src/resource-selection-optimizer/index.js.map +1 -1
- package/lib-web/src/ddf-csv.d.ts +1 -0
- package/lib-web/src/ddf-csv.js +277 -378
- package/lib-web/src/ddf-csv.js.map +1 -1
- package/lib-web/src/ddfcsv-error.js +8 -12
- package/lib-web/src/ddfcsv-error.js.map +1 -1
- package/lib-web/src/ddfcsv-reader.js +81 -123
- package/lib-web/src/ddfcsv-reader.js.map +1 -1
- package/lib-web/src/file-readers/frontend-file-reader.js +13 -16
- package/lib-web/src/file-readers/frontend-file-reader.js.map +1 -1
- package/lib-web/src/file-readers/github-path-adapter.js +5 -5
- package/lib-web/src/file-readers/github-path-adapter.js.map +1 -1
- package/lib-web/src/index-web.js +2 -2
- package/lib-web/src/index-web.js.map +1 -1
- package/lib-web/src/interfaces.d.ts +1 -0
- package/lib-web/src/resource-selection-optimizer/in-clause-under-conjunction.d.ts +2 -2
- package/lib-web/src/resource-selection-optimizer/in-clause-under-conjunction.js +164 -368
- 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 +1 -1
- package/lib-web/src/resource-selection-optimizer/index.js +6 -6
- package/lib-web/src/resource-selection-optimizer/index.js.map +1 -1
- package/package.json +2 -1
- package/src/ddf-csv.ts +22 -17
- package/src/interfaces.ts +1 -0
- package/src/resource-selection-optimizer/in-clause-under-conjunction.ts +16 -45
- package/src/resource-selection-optimizer/index.ts +2 -2
- package/tsconfig-web.json +1 -1
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InClauseUnderConjunction = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function InClauseUnderConjunction(queryParam, options) {
|
|
4
|
+
const head = require("lodash.head");
|
|
5
|
+
const values = require("lodash.values");
|
|
6
|
+
const keys = require("lodash.keys");
|
|
7
|
+
const get = require("lodash.get");
|
|
8
|
+
const flattenDeep = require("lodash.flattendeep");
|
|
9
|
+
const isEmpty = require("lodash.isempty");
|
|
10
|
+
const startsWith = require("lodash.startswith");
|
|
11
|
+
const includes = require("lodash.includes");
|
|
12
|
+
const compact = require("lodash.compact");
|
|
13
|
+
const ddfcsv_error_1 = require("../ddfcsv-error");
|
|
14
|
+
const ddf_query_validator_1 = require("ddf-query-validator");
|
|
15
|
+
const Papa = require('papaparse');
|
|
16
|
+
const WHERE_KEYWORD = 'where';
|
|
17
|
+
const JOIN_KEYWORD = 'join';
|
|
18
|
+
const KEY_IN = '$in';
|
|
19
|
+
const KEY_NIN = '$nin';
|
|
20
|
+
const KEY_AND = '$and';
|
|
21
|
+
const KEY_OR = '$or';
|
|
22
|
+
const getFirstConditionClause = clause => head(values(clause));
|
|
23
|
+
const getFirstKey = obj => head(keys(obj));
|
|
24
|
+
const isOneKeyBased = obj => keys(obj).length === 1;
|
|
25
|
+
class InClauseUnderConjunction {
|
|
26
|
+
constructor(parent, queryParam, options) {
|
|
27
|
+
this.parent = parent;
|
|
29
28
|
this.options = options;
|
|
30
29
|
this.flow = {};
|
|
31
30
|
this.fileReader = options.fileReader;
|
|
@@ -34,395 +33,192 @@ var InClauseUnderConjunction = (function () {
|
|
|
34
33
|
this.datapackage = options.datapackage;
|
|
35
34
|
this.conceptsLookup = options.conceptsLookup;
|
|
36
35
|
}
|
|
37
|
-
|
|
38
|
-
var _this = this;
|
|
36
|
+
isMatched() {
|
|
39
37
|
this.flow.joinObject = get(this.query, JOIN_KEYWORD);
|
|
40
|
-
|
|
38
|
+
const relatedFeatures = compact(ddf_query_validator_1.featureDetectors.map(detector => detector(this.query, this.conceptsLookup)));
|
|
41
39
|
return this.query.from === "datapoints";
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
_b.trys.push([1, 3, , 4]);
|
|
56
|
-
this.fillResourceToFileHash();
|
|
57
|
-
this.collectProcessableClauses();
|
|
58
|
-
this.collectEntityFilesNames();
|
|
59
|
-
return [4, this.collectEntities()];
|
|
60
|
-
case 2:
|
|
61
|
-
data = _b.sent();
|
|
62
|
-
this.fillEntityValuesHash(data);
|
|
63
|
-
this.getFilesGroupsQueryClause();
|
|
64
|
-
result = this.getOptimalFilesGroup();
|
|
65
|
-
return [3, 4];
|
|
66
|
-
case 3:
|
|
67
|
-
err_1 = _b.sent();
|
|
68
|
-
error('wrong data processing', err_1);
|
|
69
|
-
return [2, []];
|
|
70
|
-
case 4:
|
|
71
|
-
debug('recommended files found', result);
|
|
72
|
-
return [2, result];
|
|
73
|
-
case 5:
|
|
74
|
-
message = "Plugin \"InClauseUnderConjunction\" is not matched!";
|
|
75
|
-
warning(message);
|
|
76
|
-
throw new ddfcsv_error_1.DdfCsvError(message, 'InClauseUnderConjunction plugin');
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
InClauseUnderConjunction.prototype.fillResourceToFileHash = function () {
|
|
82
|
-
this.flow.resourceToFile = get(this.datapackage, 'resources', []).reduce(function (hash, resource) {
|
|
83
|
-
var constraints = resource.schema.fields.reduce(function (result, field) {
|
|
84
|
-
var _a;
|
|
85
|
-
if ((_a = field.constraints) === null || _a === void 0 ? void 0 : _a.enum) {
|
|
86
|
-
result.set(field.name, field.constraints.enum);
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
|
-
}, new Map());
|
|
90
|
-
hash.set(resource.name, {
|
|
91
|
-
path: resource.path,
|
|
92
|
-
constraints: constraints
|
|
93
|
-
});
|
|
94
|
-
return hash;
|
|
95
|
-
}, new Map());
|
|
96
|
-
return this;
|
|
97
|
-
};
|
|
98
|
-
InClauseUnderConjunction.prototype.collectProcessableClauses = function () {
|
|
99
|
-
var e_1, _a, _b, _c, _d;
|
|
100
|
-
var _this = this;
|
|
101
|
-
var joinKeys = keys(this.flow.joinObject);
|
|
102
|
-
this.flow.processableClauses = [];
|
|
103
|
-
try {
|
|
104
|
-
for (var joinKeys_1 = tslib_1.__values(joinKeys), joinKeys_1_1 = joinKeys_1.next(); !joinKeys_1_1.done; joinKeys_1_1 = joinKeys_1.next()) {
|
|
105
|
-
var joinKey = joinKeys_1_1.value;
|
|
106
|
-
var where = get(this.flow.joinObject, "".concat(joinKey, ".").concat(WHERE_KEYWORD), {});
|
|
107
|
-
if (this.singleAndField(where)) {
|
|
108
|
-
(_b = this.flow.processableClauses).push.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(flattenDeep(where[KEY_AND].map(function (el) { return _this.getProcessableClauses(el); }))), false));
|
|
109
|
-
}
|
|
110
|
-
else if (this.singleOrField(where)) {
|
|
111
|
-
(_c = this.flow.processableClauses).push.apply(_c, tslib_1.__spreadArray([], tslib_1.__read(flattenDeep(where[KEY_OR].map(function (el) { return _this.getProcessableClauses(el); }))), false));
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
(_d = this.flow.processableClauses).push.apply(_d, tslib_1.__spreadArray([], tslib_1.__read(this.getProcessableClauses(where)), false));
|
|
115
|
-
}
|
|
40
|
+
}
|
|
41
|
+
async getRecommendedFilesSet() {
|
|
42
|
+
const { debug, error, warning } = this.options.diagnostic.prepareDiagnosticFor('getRecommendedFilesSet');
|
|
43
|
+
if (this.isMatched()) {
|
|
44
|
+
debug('plugin matched');
|
|
45
|
+
let result;
|
|
46
|
+
try {
|
|
47
|
+
this.collectProcessableClauses();
|
|
48
|
+
this.collectEntityFilesNames();
|
|
49
|
+
const data = await this.collectEntities();
|
|
50
|
+
this.fillEntityValuesHash(data);
|
|
51
|
+
this.getFilesGroupsQueryClause();
|
|
52
|
+
result = this.getOptimalFilesGroup();
|
|
116
53
|
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
error('wrong data processing', err);
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
debug('recommended files found', result);
|
|
59
|
+
return result;
|
|
117
60
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
61
|
+
else {
|
|
62
|
+
const message = `Plugin "InClauseUnderConjunction" is not matched!`;
|
|
63
|
+
warning(message);
|
|
64
|
+
throw new ddfcsv_error_1.DdfCsvError(message, 'InClauseUnderConjunction plugin');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
collectProcessableClauses() {
|
|
68
|
+
const joinKeys = keys(this.flow.joinObject);
|
|
69
|
+
this.flow.processableClauses = [];
|
|
70
|
+
for (const joinKey of joinKeys) {
|
|
71
|
+
const where = get(this.flow.joinObject, `${joinKey}.${WHERE_KEYWORD}`, {});
|
|
72
|
+
if (this.singleAndField(where)) {
|
|
73
|
+
this.flow.processableClauses.push(...flattenDeep(where[KEY_AND].map(el => this.getProcessableClauses(el))));
|
|
74
|
+
}
|
|
75
|
+
else if (this.singleOrField(where)) {
|
|
76
|
+
this.flow.processableClauses.push(...flattenDeep(where[KEY_OR].map(el => this.getProcessableClauses(el))));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.flow.processableClauses.push(...this.getProcessableClauses(where));
|
|
122
80
|
}
|
|
123
|
-
finally { if (e_1) throw e_1.error; }
|
|
124
81
|
}
|
|
125
82
|
return this;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
var e_2, _a, e_3, _b, e_4, _c;
|
|
83
|
+
}
|
|
84
|
+
collectEntityFilesNames() {
|
|
129
85
|
this.flow.entityFilesNames = new Set();
|
|
86
|
+
this.flow.entityResources = new Set();
|
|
130
87
|
this.flow.fileNameToPrimaryKeyHash = new Map();
|
|
131
|
-
|
|
132
|
-
for (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
for (
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
for (var _h = (e_4 = void 0, tslib_1.__values(schemaResourceRecord.resources)), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
141
|
-
var resourceName = _j.value;
|
|
142
|
-
var file = this.flow.resourceToFile.get(resourceName).path;
|
|
143
|
-
this.flow.entityFilesNames.add(file);
|
|
144
|
-
this.flow.fileNameToPrimaryKeyHash.set(file, primaryKey);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
148
|
-
finally {
|
|
149
|
-
try {
|
|
150
|
-
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
151
|
-
}
|
|
152
|
-
finally { if (e_4) throw e_4.error; }
|
|
153
|
-
}
|
|
154
|
-
}
|
|
88
|
+
for (const schemaResourceRecord of this.datapackage.ddfSchema.entities) {
|
|
89
|
+
for (const clause of this.flow.processableClauses) {
|
|
90
|
+
const primaryKey = getFirstKey(clause);
|
|
91
|
+
if (head(schemaResourceRecord.primaryKey) === primaryKey) {
|
|
92
|
+
for (const resourceName of schemaResourceRecord.resources) {
|
|
93
|
+
const resource = this.options.resourcesLookup.get(resourceName);
|
|
94
|
+
this.flow.entityResources.add(resource);
|
|
95
|
+
this.flow.entityFilesNames.add(resource.path);
|
|
96
|
+
this.flow.fileNameToPrimaryKeyHash.set(resource.path, primaryKey);
|
|
155
97
|
}
|
|
156
98
|
}
|
|
157
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
158
|
-
finally {
|
|
159
|
-
try {
|
|
160
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
161
|
-
}
|
|
162
|
-
finally { if (e_3) throw e_3.error; }
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
167
|
-
finally {
|
|
168
|
-
try {
|
|
169
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
170
99
|
}
|
|
171
|
-
finally { if (e_2) throw e_2.error; }
|
|
172
100
|
}
|
|
173
101
|
return this;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
Papa.parse(text, {
|
|
183
|
-
header: true,
|
|
184
|
-
skipEmptyLines: true,
|
|
185
|
-
complete: function (result) { return actResolve({ file: file, result: result }); },
|
|
186
|
-
error: function (error) { return actReject(error); }
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
}); });
|
|
102
|
+
}
|
|
103
|
+
collectEntities() {
|
|
104
|
+
const self = this;
|
|
105
|
+
const actions = [...self.flow.entityResources].map(resource => {
|
|
106
|
+
return (resource.data || (resource.data = self.parent.loadFile(resource.path, self.options)))
|
|
107
|
+
.then(data => ({ result: data, file: resource.path }));
|
|
108
|
+
});
|
|
190
109
|
return Promise.all(actions);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
.
|
|
196
|
-
.map(function (key) { return key.replace(/^is--/, ''); })); };
|
|
110
|
+
}
|
|
111
|
+
fillEntityValuesHash(entitiesData) {
|
|
112
|
+
const getSubdomainsFromRecord = record => compact(keys(record)
|
|
113
|
+
.filter(key => startsWith(key, 'is--') && (record[key] === true))
|
|
114
|
+
.map(key => key.replace(/^is--/, '')));
|
|
197
115
|
this.flow.entityValueToFileHash = new Map();
|
|
198
116
|
this.flow.entityValueToDomainHash = new Map();
|
|
199
|
-
|
|
200
|
-
for (
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
var primaryKeyCellValue = entityRecord[primaryKeyForThisFile] || entityRecord[domainsForCurrentRecord[0]];
|
|
211
|
-
this.flow.entityValueToDomainHash.set(primaryKeyCellValue, domainsForCurrentRecord);
|
|
212
|
-
this.flow.entityValueToFileHash.set(primaryKeyCellValue, entityFileDescriptor.file);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
216
|
-
finally {
|
|
217
|
-
try {
|
|
218
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
219
|
-
}
|
|
220
|
-
finally { if (e_6) throw e_6.error; }
|
|
221
|
-
}
|
|
117
|
+
for (const entityFileDescriptor of entitiesData) {
|
|
118
|
+
for (const entityRecord of entityFileDescriptor.result.data) {
|
|
119
|
+
const primaryKeyForThisFile = this.flow.fileNameToPrimaryKeyHash.get(entityFileDescriptor.file);
|
|
120
|
+
const domainsForCurrentRecord = [...getSubdomainsFromRecord(entityRecord)];
|
|
121
|
+
if (isEmpty(domainsForCurrentRecord)) {
|
|
122
|
+
domainsForCurrentRecord.push(primaryKeyForThisFile);
|
|
123
|
+
}
|
|
124
|
+
const primaryKeyCellValue = entityRecord[primaryKeyForThisFile] || entityRecord[domainsForCurrentRecord[0]];
|
|
125
|
+
this.flow.entityValueToDomainHash.set(primaryKeyCellValue, domainsForCurrentRecord);
|
|
126
|
+
this.flow.entityValueToFileHash.set(primaryKeyCellValue, entityFileDescriptor.file);
|
|
222
127
|
}
|
|
223
128
|
}
|
|
224
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
225
|
-
finally {
|
|
226
|
-
try {
|
|
227
|
-
if (entitiesData_1_1 && !entitiesData_1_1.done && (_a = entitiesData_1.return)) _a.call(entitiesData_1);
|
|
228
|
-
}
|
|
229
|
-
finally { if (e_5) throw e_5.error; }
|
|
230
|
-
}
|
|
231
129
|
return this;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
try {
|
|
240
|
-
for (var _b = tslib_1.__values(_this.flow.entityValueToDomainHash.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
241
|
-
var entityKey = _c.value;
|
|
242
|
-
if (!includes(entityValuesToExclude, entityKey)) {
|
|
243
|
-
result.push(entityKey);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
248
|
-
finally {
|
|
249
|
-
try {
|
|
250
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
130
|
+
}
|
|
131
|
+
getFilesGroupsQueryClause() {
|
|
132
|
+
const getEntitiesExcept = (entityValuesToExclude) => {
|
|
133
|
+
const result = [];
|
|
134
|
+
for (const entityKey of this.flow.entityValueToDomainHash.keys()) {
|
|
135
|
+
if (!includes(entityValuesToExclude, entityKey)) {
|
|
136
|
+
result.push(entityKey);
|
|
251
137
|
}
|
|
252
|
-
finally { if (e_14) throw e_14.error; }
|
|
253
138
|
}
|
|
254
139
|
return result;
|
|
255
140
|
};
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
for (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
var schemaResourceRecord = _l.value;
|
|
277
|
-
try {
|
|
278
|
-
for (var _m = (e_11 = void 0, tslib_1.__values(schemaResourceRecord.resources)), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
279
|
-
var resourceName = _o.value;
|
|
280
|
-
var file = this.flow.resourceToFile.get(resourceName);
|
|
281
|
-
if (includes(schemaResourceRecord.primaryKey, entityByQuery)) {
|
|
282
|
-
var constraint = file.constraints.get(entityByQuery);
|
|
283
|
-
if (constraint) {
|
|
284
|
-
if (constraint.includes(entityValueFromClause)) {
|
|
285
|
-
filesGroupByClause.datapoints.add(file.path);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
filesGroupByClause.datapoints.add(file.path);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
295
|
-
finally {
|
|
296
|
-
try {
|
|
297
|
-
if (_o && !_o.done && (_e = _m.return)) _e.call(_m);
|
|
298
|
-
}
|
|
299
|
-
finally { if (e_11) throw e_11.error; }
|
|
300
|
-
}
|
|
141
|
+
const filesGroupsByClause = new Map();
|
|
142
|
+
for (const clause of this.flow.processableClauses) {
|
|
143
|
+
const filesGroupByClause = {
|
|
144
|
+
entities: this.flow.entityFilesNames,
|
|
145
|
+
datapoints: new Set(),
|
|
146
|
+
concepts: new Set()
|
|
147
|
+
};
|
|
148
|
+
const firstConditionClause = getFirstConditionClause(clause);
|
|
149
|
+
const entityValuesFromClause = firstConditionClause[KEY_IN] || getEntitiesExcept(firstConditionClause[KEY_NIN]);
|
|
150
|
+
for (const entityValueFromClause of entityValuesFromClause) {
|
|
151
|
+
const entitiesByQuery = this.flow.entityValueToDomainHash.get(entityValueFromClause);
|
|
152
|
+
for (const entityByQuery of entitiesByQuery) {
|
|
153
|
+
for (const schemaResourceRecord of this.datapackage.ddfSchema.datapoints) {
|
|
154
|
+
for (const resourceName of schemaResourceRecord.resources) {
|
|
155
|
+
if (includes(schemaResourceRecord.primaryKey, entityByQuery)) {
|
|
156
|
+
const resource = this.options.resourcesLookup.get(resourceName);
|
|
157
|
+
const constraint = resource.constraints[entityByQuery];
|
|
158
|
+
if (constraint) {
|
|
159
|
+
if (constraint.includes(entityValueFromClause)) {
|
|
160
|
+
filesGroupByClause.datapoints.add(resource.path);
|
|
301
161
|
}
|
|
302
162
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
try {
|
|
306
|
-
if (_l && !_l.done && (_d = _k.return)) _d.call(_k);
|
|
307
|
-
}
|
|
308
|
-
finally { if (e_10) throw e_10.error; }
|
|
163
|
+
else {
|
|
164
|
+
filesGroupByClause.datapoints.add(resource.path);
|
|
309
165
|
}
|
|
310
166
|
}
|
|
311
167
|
}
|
|
312
|
-
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
313
|
-
finally {
|
|
314
|
-
try {
|
|
315
|
-
if (entitiesByQuery_1_1 && !entitiesByQuery_1_1.done && (_c = entitiesByQuery_1.return)) _c.call(entitiesByQuery_1);
|
|
316
|
-
}
|
|
317
|
-
finally { if (e_9) throw e_9.error; }
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
322
|
-
finally {
|
|
323
|
-
try {
|
|
324
|
-
if (entityValuesFromClause_1_1 && !entityValuesFromClause_1_1.done && (_b = entityValuesFromClause_1.return)) _b.call(entityValuesFromClause_1);
|
|
325
|
-
}
|
|
326
|
-
finally { if (e_8) throw e_8.error; }
|
|
327
|
-
}
|
|
328
|
-
try {
|
|
329
|
-
for (var _p = (e_12 = void 0, tslib_1.__values(this.datapackage.ddfSchema.concepts)), _q = _p.next(); !_q.done; _q = _p.next()) {
|
|
330
|
-
var schemaResourceRecord = _q.value;
|
|
331
|
-
try {
|
|
332
|
-
for (var _r = (e_13 = void 0, tslib_1.__values(schemaResourceRecord.resources)), _s = _r.next(); !_s.done; _s = _r.next()) {
|
|
333
|
-
var resourceName = _s.value;
|
|
334
|
-
filesGroupByClause.concepts.add(this.flow.resourceToFile.get(resourceName).path);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
338
|
-
finally {
|
|
339
|
-
try {
|
|
340
|
-
if (_s && !_s.done && (_g = _r.return)) _g.call(_r);
|
|
341
|
-
}
|
|
342
|
-
finally { if (e_13) throw e_13.error; }
|
|
343
|
-
}
|
|
344
168
|
}
|
|
345
169
|
}
|
|
346
|
-
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
347
|
-
finally {
|
|
348
|
-
try {
|
|
349
|
-
if (_q && !_q.done && (_f = _p.return)) _f.call(_p);
|
|
350
|
-
}
|
|
351
|
-
finally { if (e_12) throw e_12.error; }
|
|
352
|
-
}
|
|
353
|
-
filesGroupsByClause.set(clause, filesGroupByClause);
|
|
354
170
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (_j && !_j.done && (_a = _h.return)) _a.call(_h);
|
|
171
|
+
for (const schemaResourceRecord of this.datapackage.ddfSchema.concepts) {
|
|
172
|
+
for (const resourceName of schemaResourceRecord.resources) {
|
|
173
|
+
filesGroupByClause.concepts.add(this.options.resourcesLookup.get(resourceName).path);
|
|
174
|
+
}
|
|
360
175
|
}
|
|
361
|
-
|
|
176
|
+
filesGroupsByClause.set(clause, filesGroupByClause);
|
|
362
177
|
}
|
|
363
178
|
this.flow.filesGroupsByClause = filesGroupsByClause;
|
|
364
179
|
return this;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
if (!appropriateClauseKey || size < appropriateClauseSize) {
|
|
378
|
-
appropriateClauseKey = key;
|
|
379
|
-
appropriateClauseSize = size;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
384
|
-
finally {
|
|
385
|
-
try {
|
|
386
|
-
if (clauseKeys_1_1 && !clauseKeys_1_1.done && (_a = clauseKeys_1.return)) _a.call(clauseKeys_1);
|
|
180
|
+
}
|
|
181
|
+
getOptimalFilesGroup() {
|
|
182
|
+
const clauseKeys = this.flow.filesGroupsByClause.keys();
|
|
183
|
+
let appropriateClauseKey;
|
|
184
|
+
let appropriateClauseSize;
|
|
185
|
+
for (const key of clauseKeys) {
|
|
186
|
+
const size = this.flow.filesGroupsByClause.get(key).datapoints.size +
|
|
187
|
+
this.flow.filesGroupsByClause.get(key).entities.size +
|
|
188
|
+
this.flow.filesGroupsByClause.get(key).concepts.size;
|
|
189
|
+
if (!appropriateClauseKey || size < appropriateClauseSize) {
|
|
190
|
+
appropriateClauseKey = key;
|
|
191
|
+
appropriateClauseSize = size;
|
|
387
192
|
}
|
|
388
|
-
finally { if (e_15) throw e_15.error; }
|
|
389
193
|
}
|
|
390
194
|
if (!this.flow.filesGroupsByClause.get(appropriateClauseKey)) {
|
|
391
195
|
return [];
|
|
392
196
|
}
|
|
393
|
-
return
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
197
|
+
return [
|
|
198
|
+
...Array.from(this.flow.filesGroupsByClause.get(appropriateClauseKey).concepts),
|
|
199
|
+
...Array.from(this.flow.filesGroupsByClause.get(appropriateClauseKey).entities),
|
|
200
|
+
...Array.from(this.flow.filesGroupsByClause.get(appropriateClauseKey).datapoints)
|
|
201
|
+
];
|
|
202
|
+
}
|
|
203
|
+
getProcessableClauses(clause) {
|
|
204
|
+
const result = [];
|
|
205
|
+
const clauseKeys = keys(clause);
|
|
206
|
+
for (const key of clauseKeys) {
|
|
207
|
+
if (!startsWith(key, '$') && isOneKeyBased(clause[key])) {
|
|
208
|
+
const conditionKey = head(keys(clause[key]));
|
|
209
|
+
if (conditionKey === KEY_IN || conditionKey === KEY_NIN) {
|
|
210
|
+
result.push(clause);
|
|
407
211
|
}
|
|
408
212
|
}
|
|
409
213
|
}
|
|
410
|
-
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
411
|
-
finally {
|
|
412
|
-
try {
|
|
413
|
-
if (clauseKeys_2_1 && !clauseKeys_2_1.done && (_a = clauseKeys_2.return)) _a.call(clauseKeys_2);
|
|
414
|
-
}
|
|
415
|
-
finally { if (e_16) throw e_16.error; }
|
|
416
|
-
}
|
|
417
214
|
return result;
|
|
418
|
-
}
|
|
419
|
-
|
|
215
|
+
}
|
|
216
|
+
singleAndField(clause) {
|
|
420
217
|
return isOneKeyBased(clause) && !!get(clause, KEY_AND);
|
|
421
|
-
}
|
|
422
|
-
|
|
218
|
+
}
|
|
219
|
+
singleOrField(clause) {
|
|
423
220
|
return isOneKeyBased(clause) && !!get(clause, KEY_OR);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
}());
|
|
221
|
+
}
|
|
222
|
+
}
|
|
427
223
|
exports.InClauseUnderConjunction = InClauseUnderConjunction;
|
|
428
224
|
//# sourceMappingURL=in-clause-under-conjunction.js.map
|