@transitive-sdk/clickhouse 0.4.2 → 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 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
- select = [`${agg}(${extractValue}) as aggValue`,
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,7 +433,6 @@ 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transitive-sdk/clickhouse",
3
- "version": "0.4.2",
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.12.1",
27
+ "@clickhouse/client": "^1.16.0",
28
28
  "@transitive-sdk/datacache": "^0.14.1",
29
29
  "wait-port": "^1.1.0"
30
30
  },
@@ -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
  });
@@ -471,6 +472,7 @@ describe('ClickHouse', function() {
471
472
  limit: 2 * ROWS,
472
473
  });
473
474
  console.log(rows[0]);
475
+ assert.strictEqual(typeof rows[0].aggValue, 'number');
474
476
  assert.equal(rows.length, 10000);
475
477
  assertTimelimit(ROWS / 1000);
476
478
  });