@transitive-sdk/clickhouse 0.4.0 → 0.4.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 +13 -11
- package/package.json +1 -1
- package/test/clickhouse.test.js +1 -0
package/index.js
CHANGED
|
@@ -391,7 +391,7 @@ class ClickHouse {
|
|
|
391
391
|
const pathSelector = topicToPath(topicSelector);
|
|
392
392
|
|
|
393
393
|
// interpret wildcards
|
|
394
|
-
const { where
|
|
394
|
+
const { where } = path2where(pathSelector);
|
|
395
395
|
since && where.push(`Timestamp >= fromUnixTimestamp64Milli(${since.getTime()})`);
|
|
396
396
|
until && where.push(`Timestamp <= fromUnixTimestamp64Milli(${until.getTime()})`);
|
|
397
397
|
const whereStatement = where.length > 0 ? `WHERE ${where.join(' AND ')}` : '';
|
|
@@ -413,13 +413,15 @@ class ClickHouse {
|
|
|
413
413
|
// if aggregation is requested, build the GROUP BY expression and update SELECT
|
|
414
414
|
if (aggSeconds) {
|
|
415
415
|
// SQL sub-string to extract the desired value from the JSON payload
|
|
416
|
-
const wildParts = wildIndices.map(i => `TopicParts[${i + 1}]`);
|
|
416
|
+
// const wildParts = wildIndices.map(i => `TopicParts[${i + 1}]`);
|
|
417
417
|
// update SELECT statement with aggregations
|
|
418
418
|
select = [`${agg}(${extractValue}) as aggValue`,
|
|
419
|
-
...wildParts,
|
|
419
|
+
// ...wildParts,
|
|
420
|
+
'TopicParts',
|
|
420
421
|
`toStartOfInterval(Timestamp, INTERVAL ${aggSeconds} SECOND) as time`
|
|
421
422
|
];
|
|
422
|
-
group = `GROUP BY (time,${wildParts.join(',')})`
|
|
423
|
+
// group = `GROUP BY (time,${wildParts.join(',')})`
|
|
424
|
+
group = `GROUP BY (time,TopicParts)`
|
|
423
425
|
}
|
|
424
426
|
|
|
425
427
|
const query = `SELECT ${select.join(',')} FROM default.${this.mqttHistoryTable} ${
|
|
@@ -433,13 +435,13 @@ class ClickHouse {
|
|
|
433
435
|
// registerMqttTopicForStorage
|
|
434
436
|
return rows.map(row => {
|
|
435
437
|
row.Payload = row.Payload ? JSON.parse(row.Payload) : null;
|
|
436
|
-
row.Timestamp = new Date(row.
|
|
437
|
-
row.OrgId = row.TopicParts
|
|
438
|
-
row.DeviceId = row.TopicParts
|
|
439
|
-
row.Scope = row.TopicParts
|
|
440
|
-
row.CapabilityName = row.TopicParts
|
|
441
|
-
row.CapabilityVersion = row.TopicParts
|
|
442
|
-
row.SubTopic = row.TopicParts
|
|
438
|
+
row.Timestamp = new Date(`${row.time}Z`);
|
|
439
|
+
row.OrgId = row.TopicParts[0];
|
|
440
|
+
row.DeviceId = row.TopicParts[1];
|
|
441
|
+
row.Scope = row.TopicParts[2];
|
|
442
|
+
row.CapabilityName = row.TopicParts[3];
|
|
443
|
+
row.CapabilityVersion = row.TopicParts[4];
|
|
444
|
+
row.SubTopic = row.TopicParts.slice(5);
|
|
443
445
|
return row;
|
|
444
446
|
});
|
|
445
447
|
}
|
package/package.json
CHANGED