@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 CHANGED
@@ -391,7 +391,7 @@ class ClickHouse {
391
391
  const pathSelector = topicToPath(topicSelector);
392
392
 
393
393
  // interpret wildcards
394
- const { where, wildIndices } = path2where(pathSelector);
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.Timestamp);
437
- row.OrgId = row.TopicParts?.[0];
438
- row.DeviceId = row.TopicParts?.[1];
439
- row.Scope = row.TopicParts?.[2];
440
- row.CapabilityName = row.TopicParts?.[3];
441
- row.CapabilityVersion = row.TopicParts?.[4];
442
- row.SubTopic = row.TopicParts?.slice(5);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transitive-sdk/clickhouse",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "A tiny ClickHouse utility class for use in the Transitive framework.",
5
5
  "homepage": "https://transitiverobotics.com",
6
6
  "repository": {
@@ -470,6 +470,7 @@ describe('ClickHouse', function() {
470
470
  agg: 'avg',
471
471
  limit: 2 * ROWS,
472
472
  });
473
+ console.log(rows[0]);
473
474
  assert.equal(rows.length, 10000);
474
475
  assertTimelimit(ROWS / 1000);
475
476
  });