@transitive-sdk/clickhouse 0.3.1 → 0.3.2
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 +6 -5
- package/package.json +1 -1
- package/test/clickhouse.test.js +4 -0
package/index.js
CHANGED
|
@@ -26,7 +26,7 @@ const path2where = (path) => {
|
|
|
26
26
|
_.forEach(path, (value, i) => {
|
|
27
27
|
if (!['+','#'].includes(value[0])) {
|
|
28
28
|
// it's a constant, filter by it
|
|
29
|
-
where.push(`
|
|
29
|
+
where.push(`TopicParts[${i + 1}] = '${value}'`);
|
|
30
30
|
// Note that ClickHouse/SQL index starting at 1, not 0
|
|
31
31
|
}
|
|
32
32
|
});
|
|
@@ -287,7 +287,6 @@ class ClickHouse {
|
|
|
287
287
|
// .map(([i, value]) => `((TopicParts[${i + 1}]) = '${value}')`);
|
|
288
288
|
const where = path2where(path);
|
|
289
289
|
|
|
290
|
-
|
|
291
290
|
if (where.length == 0) {
|
|
292
291
|
// underspecified, don't set TTL
|
|
293
292
|
return;
|
|
@@ -305,11 +304,13 @@ class ClickHouse {
|
|
|
305
304
|
const ttls = matched ? matched[1].split(',').map(x => x.trim()) : [];
|
|
306
305
|
|
|
307
306
|
const whereStatement = `WHERE ${where.join(' AND ')}`;
|
|
308
|
-
|
|
307
|
+
const newTTLStatement =
|
|
308
|
+
`toDateTime(Timestamp) + toIntervalDay(${ttlDays}) ${whereStatement}`;
|
|
309
309
|
|
|
310
|
+
let present = false;
|
|
310
311
|
// check if TTL statement already present on table definiton
|
|
311
312
|
ttls.forEach((ttl, i) => {
|
|
312
|
-
if (ttl.endsWith(whereStatement)) {
|
|
313
|
+
if (ttl.replace(/[()]/g, '').endsWith(whereStatement)) {
|
|
313
314
|
// condition already present, just replace it to update time
|
|
314
315
|
ttls[i] = newTTLStatement;
|
|
315
316
|
present = true;
|
|
@@ -317,7 +318,7 @@ class ClickHouse {
|
|
|
317
318
|
});
|
|
318
319
|
|
|
319
320
|
if (!present) {
|
|
320
|
-
ttls.push(
|
|
321
|
+
ttls.push(newTTLStatement);
|
|
321
322
|
}
|
|
322
323
|
|
|
323
324
|
await this.client.command({
|
package/package.json
CHANGED
package/test/clickhouse.test.js
CHANGED
|
@@ -193,6 +193,10 @@ describe('ClickHouse', function() {
|
|
|
193
193
|
assert.equal(rows.length, 1);
|
|
194
194
|
});
|
|
195
195
|
|
|
196
|
+
it('updates TTL without crashing', async () => {
|
|
197
|
+
await clickhouse.registerMqttTopicForStorage('/+/+/myscope/+/+/#', 13);
|
|
198
|
+
await clickhouse.registerMqttTopicForStorage('/+/+/myscope/+/+/#', 15);
|
|
199
|
+
});
|
|
196
200
|
});
|
|
197
201
|
|
|
198
202
|
|