Skip to content

Commit

Permalink
feedback: use hash of map for comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
dhable committed Feb 21, 2025
1 parent d9bbaf8 commit 915a77c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions packages/common-utils/src/__tests__/renderChartConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ describe('renderChartConfig', () => {
expect(actual).toBe(
'WITH RawSum AS (SELECT MetricName,Value,TimeUnix,Attributes,\n' +
' any(Value) OVER (ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) AS PrevValue,\n' +
' any(Attributes) OVER (ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) AS PrevAttributes,\n' +
' any(AttributesHash) OVER (ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) AS PrevAttributesHash,\n' +
' IF(AggregationTemporality = 1,\n' +
' Value,IF(Value - PrevValue < 0 AND Attributes = PrevAttributes,Value,\n' +
' IF(Attributes != PrevAttributes, 0, Value - PrevValue))) as Rate\n' +
' Value,IF(Value - PrevValue < 0 AND AttributesHash = PrevAttributesHash, Value,\n' +
' IF(AttributesHash != PrevAttributesHash, 0, Value - PrevValue))) as Rate\n' +
' FROM (\n' +
' SELECT mapConcat(ScopeAttributes, ResourceAttributes, Attributes) AS Attributes, Value, MetricName, TimeUnix, AggregationTemporality\n' +
' SELECT mapConcat(ScopeAttributes, ResourceAttributes, Attributes) AS Attributes,\n' +
' cityHash64(Attributes) AS AttributesHash, Value, MetricName, TimeUnix, AggregationTemporality\n' +
' FROM default.otel_metrics_sum\n' +
" WHERE MetricName = 'db.client.connections.usage'\n" +
' ORDER BY Attributes, TimeUnix ASC\n' +
Expand Down
9 changes: 5 additions & 4 deletions packages/common-utils/src/renderChartConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,13 @@ function translateMetricChartConfig(
name: 'RawSum',
sql: chSql`SELECT MetricName,Value,TimeUnix,Attributes,
any(Value) OVER (ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) AS PrevValue,
any(Attributes) OVER (ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) AS PrevAttributes,
any(AttributesHash) OVER (ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) AS PrevAttributesHash,
IF(AggregationTemporality = 1,
Value,IF(Value - PrevValue < 0 AND Attributes = PrevAttributes,Value,
IF(Attributes != PrevAttributes, 0, Value - PrevValue))) as Rate
Value,IF(Value - PrevValue < 0 AND AttributesHash = PrevAttributesHash, Value,
IF(AttributesHash != PrevAttributesHash, 0, Value - PrevValue))) as Rate
FROM (
SELECT mapConcat(ScopeAttributes, ResourceAttributes, Attributes) AS Attributes, Value, MetricName, TimeUnix, AggregationTemporality
SELECT mapConcat(ScopeAttributes, ResourceAttributes, Attributes) AS Attributes,
cityHash64(Attributes) AS AttributesHash, Value, MetricName, TimeUnix, AggregationTemporality
FROM ${renderFrom({ from: { ...from, tableName: metricTables[MetricsDataType.Sum] } })}
WHERE MetricName = '${metricName}'
ORDER BY Attributes, TimeUnix ASC
Expand Down

0 comments on commit 915a77c

Please sign in to comment.