@transitive-sdk/clickhouse 0.3.0 → 0.3.1
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/index.js +36 -18
- package/package.json +1 -1
- package/test/clickhouse.test.js +1 -2
package/index.js
CHANGED
|
@@ -19,6 +19,21 @@ const MULTI_TENANT_SCHEMA = {
|
|
|
19
19
|
]
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
/** Given a Topic path (array), return an array of conditions to use in a
|
|
23
|
+
* WHERE clause. */
|
|
24
|
+
const path2where = (path) => {
|
|
25
|
+
const where = [];
|
|
26
|
+
_.forEach(path, (value, i) => {
|
|
27
|
+
if (!['+','#'].includes(value[0])) {
|
|
28
|
+
// it's a constant, filter by it
|
|
29
|
+
where.push(`((TopicParts[${i + 1}]) = '${value}')`);
|
|
30
|
+
// Note that ClickHouse/SQL index starting at 1, not 0
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return where;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
|
|
22
37
|
/** Singleton ClickHouse client wrapper with multi-tenant table support */
|
|
23
38
|
class ClickHouse {
|
|
24
39
|
|
|
@@ -258,18 +273,20 @@ class ClickHouse {
|
|
|
258
273
|
}
|
|
259
274
|
|
|
260
275
|
// list of TopicParts indices and selected value to use in WHERE statement
|
|
261
|
-
const topicPartSelectors = [
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
];
|
|
276
|
+
// const topicPartSelectors = [
|
|
277
|
+
// [2, path[2]],
|
|
278
|
+
// [3, path[3]]
|
|
279
|
+
// ];
|
|
280
|
+
|
|
281
|
+
// path.slice(5).forEach((value, i) => topicPartSelectors.push([i + 5, value]));
|
|
265
282
|
|
|
266
|
-
|
|
283
|
+
// const where = topicPartSelectors
|
|
284
|
+
// // filter out wildcards
|
|
285
|
+
// .filter(([i, value]) => !['+','#'].includes(value[0]))
|
|
286
|
+
// // map to WHERE conditions
|
|
287
|
+
// .map(([i, value]) => `((TopicParts[${i + 1}]) = '${value}')`);
|
|
288
|
+
const where = path2where(path);
|
|
267
289
|
|
|
268
|
-
const where = topicPartSelectors
|
|
269
|
-
// filter out wildcards
|
|
270
|
-
.filter(([i, value]) => !['+','#'].includes(value[0]))
|
|
271
|
-
// map to WHERE conditions
|
|
272
|
-
.map(([i, value]) => `((TopicParts[${i}]) = '${value}')`);
|
|
273
290
|
|
|
274
291
|
if (where.length == 0) {
|
|
275
292
|
// underspecified, don't set TTL
|
|
@@ -327,14 +344,15 @@ class ClickHouse {
|
|
|
327
344
|
const path = topicToPath(topicSelector);
|
|
328
345
|
|
|
329
346
|
// interpret wildcards
|
|
330
|
-
const where = [];
|
|
331
|
-
_.forEach(path, (value, i) => {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
});
|
|
347
|
+
// const where = [];
|
|
348
|
+
// _.forEach(path, (value, i) => {
|
|
349
|
+
// if (!['+','#'].includes(value[0])) {
|
|
350
|
+
// // it's a constant, filter by it
|
|
351
|
+
// where.push(`TopicParts[${i + 1}] = '${value}'`);
|
|
352
|
+
// // Note that ClickHouse/SQL index starting at 1, not 0
|
|
353
|
+
// }
|
|
354
|
+
// });
|
|
355
|
+
const where = path2where(path);
|
|
338
356
|
|
|
339
357
|
since && where.push(`Timestamp >= fromUnixTimestamp64Milli(${since.getTime()})`);
|
|
340
358
|
until && where.push(`Timestamp <= fromUnixTimestamp64Milli(${until.getTime()})`);
|
package/package.json
CHANGED
package/test/clickhouse.test.js
CHANGED