Fix timeseries query: use epoch-based bucketing for DateTime64 compatibility
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:
@@ -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 <= ? " +
|
||||
|
||||
Reference in New Issue
Block a user