Skip to content

Commit 61c79a1

Browse files
authored
fix: Ensure percentile aggregations on histograms dont create invalid SQL queries due to improperly escaped aliases. (#1021)
Closes #1020 Closes HDX-2063 <img width="1855" height="897" alt="image" src="https://github.com/user-attachments/assets/5f7f0505-934c-4da0-8e46-f07aa5035455" />
1 parent 6c13403 commit 61c79a1

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

.changeset/little-parents-rescue.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@hyperdx/common-utils": patch
3+
"@hyperdx/api": patch
4+
"@hyperdx/app": patch
5+
---
6+
7+
fix: Ensure percentile aggregations on histograms don't create invalid SQL queries due to improperly escaped aliases.

packages/common-utils/src/__tests__/__snapshots__/renderChartConfig.test.ts.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ exports[`renderChartConfig histogram metric queries should generate a query with
8282
WHEN upper_bound = inf THEN point[upper_idx - 1].2
8383
WHEN lower_bound = inf THEN point[1].2
8484
ELSE lower_bound + (upper_bound - lower_bound) * ((rank - lower_count) / (upper_count - lower_count))
85-
END AS Value
85+
END AS \\"Value\\"
8686
FROM points
8787
WHERE length(point) > 1 AND total > 0
88-
) SELECT \`__hdx_time_bucket\`, group, Value FROM metrics WHERE (\`__hdx_time_bucket\` >= fromUnixTimestamp64Milli(1739318400000) AND \`__hdx_time_bucket\` <= fromUnixTimestamp64Milli(1765670400000)) LIMIT 10 SETTINGS short_circuit_function_evaluation = 'force_enable'"
88+
) SELECT \`__hdx_time_bucket\`, group, \\"Value\\" FROM metrics WHERE (\`__hdx_time_bucket\` >= fromUnixTimestamp64Milli(1739318400000) AND \`__hdx_time_bucket\` <= fromUnixTimestamp64Milli(1765670400000)) LIMIT 10 SETTINGS short_circuit_function_evaluation = 'force_enable'"
8989
`;
9090

9191
exports[`renderChartConfig histogram metric queries should generate a query without grouping but time bucketing 1`] = `
@@ -166,10 +166,10 @@ exports[`renderChartConfig histogram metric queries should generate a query with
166166
WHEN upper_bound = inf THEN point[upper_idx - 1].2
167167
WHEN lower_bound = inf THEN point[1].2
168168
ELSE lower_bound + (upper_bound - lower_bound) * ((rank - lower_count) / (upper_count - lower_count))
169-
END AS Value
169+
END AS \\"Value\\"
170170
FROM points
171171
WHERE length(point) > 1 AND total > 0
172-
) SELECT \`__hdx_time_bucket\`, Value FROM metrics WHERE (\`__hdx_time_bucket\` >= fromUnixTimestamp64Milli(1739318400000) AND \`__hdx_time_bucket\` <= fromUnixTimestamp64Milli(1765670400000)) LIMIT 10 SETTINGS short_circuit_function_evaluation = 'force_enable'"
172+
) SELECT \`__hdx_time_bucket\`, \\"Value\\" FROM metrics WHERE (\`__hdx_time_bucket\` >= fromUnixTimestamp64Milli(1739318400000) AND \`__hdx_time_bucket\` <= fromUnixTimestamp64Milli(1765670400000)) LIMIT 10 SETTINGS short_circuit_function_evaluation = 'force_enable'"
173173
`;
174174

175175
exports[`renderChartConfig histogram metric queries should generate a query without grouping or time bucketing 1`] = `
@@ -250,10 +250,10 @@ exports[`renderChartConfig histogram metric queries should generate a query with
250250
WHEN upper_bound = inf THEN point[upper_idx - 1].2
251251
WHEN lower_bound = inf THEN point[1].2
252252
ELSE lower_bound + (upper_bound - lower_bound) * ((rank - lower_count) / (upper_count - lower_count))
253-
END AS Value
253+
END AS \\"Value\\"
254254
FROM points
255255
WHERE length(point) > 1 AND total > 0
256-
) SELECT \`__hdx_time_bucket\`, Value FROM metrics WHERE (\`__hdx_time_bucket\` >= fromUnixTimestamp64Milli(1739318400000) AND \`__hdx_time_bucket\` <= fromUnixTimestamp64Milli(1765670400000)) LIMIT 10 SETTINGS short_circuit_function_evaluation = 'force_enable'"
256+
) SELECT \`__hdx_time_bucket\`, \\"Value\\" FROM metrics WHERE (\`__hdx_time_bucket\` >= fromUnixTimestamp64Milli(1739318400000) AND \`__hdx_time_bucket\` <= fromUnixTimestamp64Milli(1765670400000)) LIMIT 10 SETTINGS short_circuit_function_evaluation = 'force_enable'"
257257
`;
258258

259259
exports[`renderChartConfig should generate sql for a single gauge metric 1`] = `

packages/common-utils/src/renderChartConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,13 +1250,13 @@ async function translateMetricChartConfig(
12501250
WHEN upper_bound = inf THEN point[upper_idx - 1].2
12511251
WHEN lower_bound = inf THEN point[1].2
12521252
ELSE lower_bound + (upper_bound - lower_bound) * ((rank - lower_count) / (upper_count - lower_count))
1253-
END AS ${valueAlias}
1253+
END AS "${valueAlias}"
12541254
FROM points
12551255
WHERE length(point) > 1 AND total > 0
12561256
`,
12571257
},
12581258
],
1259-
select: `\`__hdx_time_bucket\`${groupBy ? ', group' : ''}, ${valueAlias}`,
1259+
select: `\`__hdx_time_bucket\`${groupBy ? ', group' : ''}, "${valueAlias}"`,
12601260
from: {
12611261
databaseName: '',
12621262
tableName: 'metrics',

0 commit comments

Comments
 (0)