Fix timeseries query: use epoch-based bucketing for DateTime64 compatibility
All checks were successful
CI / build (push) Successful in 1m1s
CI / docker (push) Successful in 41s
CI / deploy (push) Successful in 29s

Replace toStartOfInterval with intDiv on epoch seconds, and cast
avg/quantile results to Int64 to avoid Float64 JDBC mapping issues.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-03-13 18:33:14 +01:00
parent 9e6e1b350a
commit d1940b98e5

View File

@@ -106,12 +106,13 @@ public class ClickHouseSearchEngine implements SearchEngine {
long intervalSeconds = Duration.between(from, to).getSeconds() / bucketCount;
if (intervalSeconds < 1) intervalSeconds = 1;
// Use epoch-based bucketing for DateTime64 compatibility
String sql = "SELECT " +
"toStartOfInterval(start_time, INTERVAL " + intervalSeconds + " SECOND) AS bucket, " +
"toDateTime(intDiv(toUInt32(toDateTime(start_time)), " + intervalSeconds + ") * " + intervalSeconds + ") AS bucket, " +
"count() AS total_count, " +
"countIf(status = 'FAILED') AS failed_count, " +
"avg(duration_ms) AS avg_duration_ms, " +
"quantile(0.99)(duration_ms) AS p99_duration_ms, " +
"toInt64(avg(duration_ms)) AS avg_duration_ms, " +
"toInt64(quantile(0.99)(duration_ms)) AS p99_duration_ms, " +
"countIf(status = 'RUNNING') AS active_count " +
"FROM route_executions " +
"WHERE start_time >= ? AND start_time <= ? " +