@transitive-sdk/clickhouse 0.4.1 → 0.4.3
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 +7 -3
- package/package.json +2 -2
- package/test/clickhouse.test.js +3 -0
package/index.js
CHANGED
|
@@ -415,7 +415,12 @@ class ClickHouse {
|
|
|
415
415
|
// SQL sub-string to extract the desired value from the JSON payload
|
|
416
416
|
// const wildParts = wildIndices.map(i => `TopicParts[${i + 1}]`);
|
|
417
417
|
// update SELECT statement with aggregations
|
|
418
|
-
|
|
418
|
+
|
|
419
|
+
select = [
|
|
420
|
+
// Cast `count` result to Float64 to avoid UInt64 which ClickHouse turns
|
|
421
|
+
// into a string in JSON.
|
|
422
|
+
agg == 'count' ? `CAST(${agg}(${extractValue}), 'Float64') as aggValue`
|
|
423
|
+
: `${agg}(${extractValue}) as aggValue`,
|
|
419
424
|
// ...wildParts,
|
|
420
425
|
'TopicParts',
|
|
421
426
|
`toStartOfInterval(Timestamp, INTERVAL ${aggSeconds} SECOND) as time`
|
|
@@ -428,14 +433,13 @@ class ClickHouse {
|
|
|
428
433
|
whereStatement} ${group} ORDER BY ${orderBy} ${limit ? ` LIMIT ${limit}` : ''}`;
|
|
429
434
|
// console.log(query);
|
|
430
435
|
const result = await this.client.query({ query, format: 'JSONEachRow' });
|
|
431
|
-
|
|
432
436
|
const rows = await result.json();
|
|
433
437
|
|
|
434
438
|
// map payloads back from JSON; this is the inverse of what we do in
|
|
435
439
|
// registerMqttTopicForStorage
|
|
436
440
|
return rows.map(row => {
|
|
437
441
|
row.Payload = row.Payload ? JSON.parse(row.Payload) : null;
|
|
438
|
-
row.Timestamp = new Date(row.
|
|
442
|
+
row.Timestamp = new Date(`${row.time}Z`);
|
|
439
443
|
row.OrgId = row.TopicParts[0];
|
|
440
444
|
row.DeviceId = row.TopicParts[1];
|
|
441
445
|
row.Scope = row.TopicParts[2];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transitive-sdk/clickhouse",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "A tiny ClickHouse utility class for use in the Transitive framework.",
|
|
5
5
|
"homepage": "https://transitiverobotics.com",
|
|
6
6
|
"repository": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"test": "node --test --watch"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@clickhouse/client": "^1.
|
|
27
|
+
"@clickhouse/client": "^1.16.0",
|
|
28
28
|
"@transitive-sdk/datacache": "^0.14.1",
|
|
29
29
|
"wait-port": "^1.1.0"
|
|
30
30
|
},
|
package/test/clickhouse.test.js
CHANGED
|
@@ -443,6 +443,7 @@ describe('ClickHouse', function() {
|
|
|
443
443
|
limit: 2 * ROWS,
|
|
444
444
|
});
|
|
445
445
|
// there can be one-off errors due to rounding down to start of interval:
|
|
446
|
+
assert.strictEqual(typeof rows[0].aggValue, 'number');
|
|
446
447
|
assert(Math.abs(rows.length - 60) < 2);
|
|
447
448
|
assertTimelimit(ROWS / 10000);
|
|
448
449
|
});
|
|
@@ -470,6 +471,8 @@ describe('ClickHouse', function() {
|
|
|
470
471
|
agg: 'avg',
|
|
471
472
|
limit: 2 * ROWS,
|
|
472
473
|
});
|
|
474
|
+
console.log(rows[0]);
|
|
475
|
+
assert.strictEqual(typeof rows[0].aggValue, 'number');
|
|
473
476
|
assert.equal(rows.length, 10000);
|
|
474
477
|
assertTimelimit(ROWS / 1000);
|
|
475
478
|
});
|