Fix nan-to-int64 crash when avg/quantile runs on empty result set
ClickHouse avg() and quantile() return nan/inf on zero rows, which toInt64() cannot convert. Wrap with ifNotFinite(..., 0) to default to zero. Applied to both stats and timeseries queries. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -91,8 +91,8 @@ public class ClickHouseSearchEngine implements SearchEngine {
|
||||
public ExecutionStats stats(Instant from, Instant to) {
|
||||
String aggregateSql = "SELECT count() AS total_count, " +
|
||||
"countIf(status = 'FAILED') AS failed_count, " +
|
||||
"toInt64(avg(duration_ms)) AS avg_duration_ms, " +
|
||||
"toInt64(quantile(0.99)(duration_ms)) AS p99_duration_ms, " +
|
||||
"toInt64(ifNotFinite(avg(duration_ms), 0)) AS avg_duration_ms, " +
|
||||
"toInt64(ifNotFinite(quantile(0.99)(duration_ms), 0)) AS p99_duration_ms, " +
|
||||
"countIf(status = 'RUNNING') AS active_count " +
|
||||
"FROM route_executions WHERE start_time >= ? AND start_time <= ?";
|
||||
|
||||
@@ -143,8 +143,8 @@ public class ClickHouseSearchEngine implements SearchEngine {
|
||||
"toDateTime(intDiv(toUInt32(toDateTime(start_time)), " + intervalSeconds + ") * " + intervalSeconds + ") AS bucket, " +
|
||||
"count() AS total_count, " +
|
||||
"countIf(status = 'FAILED') AS failed_count, " +
|
||||
"toInt64(avg(duration_ms)) AS avg_duration_ms, " +
|
||||
"toInt64(quantile(0.99)(duration_ms)) AS p99_duration_ms, " +
|
||||
"toInt64(ifNotFinite(avg(duration_ms), 0)) AS avg_duration_ms, " +
|
||||
"toInt64(ifNotFinite(quantile(0.99)(duration_ms), 0)) AS p99_duration_ms, " +
|
||||
"countIf(status = 'RUNNING') AS active_count " +
|
||||
"FROM route_executions " +
|
||||
"WHERE start_time >= ? AND start_time <= ? " +
|
||||
|
||||
Reference in New Issue
Block a user