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" />
This commit is contained in:
Mike Shi 2025-07-25 10:15:37 -07:00 committed by GitHub
parent 6c134035c4
commit 61c79a16a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 8 deletions

View file

@ -0,0 +1,7 @@
---
"@hyperdx/common-utils": patch
"@hyperdx/api": patch
"@hyperdx/app": patch
---
fix: Ensure percentile aggregations on histograms don't create invalid SQL queries due to improperly escaped aliases.

View file

@ -82,10 +82,10 @@ exports[`renderChartConfig histogram metric queries should generate a query with
WHEN upper_bound = inf THEN point[upper_idx - 1].2
WHEN lower_bound = inf THEN point[1].2
ELSE lower_bound + (upper_bound - lower_bound) * ((rank - lower_count) / (upper_count - lower_count))
END AS Value
END AS \\"Value\\"
FROM points
WHERE length(point) > 1 AND total > 0
) 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'"
) 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'"
`;
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
WHEN upper_bound = inf THEN point[upper_idx - 1].2
WHEN lower_bound = inf THEN point[1].2
ELSE lower_bound + (upper_bound - lower_bound) * ((rank - lower_count) / (upper_count - lower_count))
END AS Value
END AS \\"Value\\"
FROM points
WHERE length(point) > 1 AND total > 0
) 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'"
) 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'"
`;
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
WHEN upper_bound = inf THEN point[upper_idx - 1].2
WHEN lower_bound = inf THEN point[1].2
ELSE lower_bound + (upper_bound - lower_bound) * ((rank - lower_count) / (upper_count - lower_count))
END AS Value
END AS \\"Value\\"
FROM points
WHERE length(point) > 1 AND total > 0
) 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'"
) 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'"
`;
exports[`renderChartConfig should generate sql for a single gauge metric 1`] = `

View file

@ -1250,13 +1250,13 @@ async function translateMetricChartConfig(
WHEN upper_bound = inf THEN point[upper_idx - 1].2
WHEN lower_bound = inf THEN point[1].2
ELSE lower_bound + (upper_bound - lower_bound) * ((rank - lower_count) / (upper_count - lower_count))
END AS ${valueAlias}
END AS "${valueAlias}"
FROM points
WHERE length(point) > 1 AND total > 0
`,
},
],
select: `\`__hdx_time_bucket\`${groupBy ? ', group' : ''}, ${valueAlias}`,
select: `\`__hdx_time_bucket\`${groupBy ? ', group' : ''}, "${valueAlias}"`,
from: {
databaseName: '',
tableName: 'metrics',