From a52751da1bd253867ae92b9231e58f196cae093f Mon Sep 17 00:00:00 2001 From: hsiegeln <37154749+hsiegeln@users.noreply.github.com> Date: Wed, 1 Apr 2026 22:24:50 +0200 Subject: [PATCH] fix: avoid alias shadowing in processor metrics -Merge query ClickHouse 24.12 new query analyzer resolves countMerge(total_count) in the CASE WHEN to the SELECT alias (UInt64) instead of the original AggregateFunction column when the alias has the same name. Renamed aliases to tc/fc to avoid the collision. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../app/controller/RouteMetricsController.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cameleer3-server-app/src/main/java/com/cameleer3/server/app/controller/RouteMetricsController.java b/cameleer3-server-app/src/main/java/com/cameleer3/server/app/controller/RouteMetricsController.java index 08dd677c..41ac7a99 100644 --- a/cameleer3-server-app/src/main/java/com/cameleer3/server/app/controller/RouteMetricsController.java +++ b/cameleer3-server-app/src/main/java/com/cameleer3/server/app/controller/RouteMetricsController.java @@ -149,11 +149,14 @@ public class RouteMetricsController { Instant toInstant = to != null ? to : Instant.now(); Instant fromInstant = from != null ? from : toInstant.minus(24, ChronoUnit.HOURS); - // Literal SQL for AggregatingMergeTree -Merge combinators + // Literal SQL for AggregatingMergeTree -Merge combinators. + // Aliases (tc, fc) must NOT shadow column names (total_count, failed_count) — + // ClickHouse 24.12 new analyzer resolves subsequent countMerge(total_count) + // to the alias (UInt64) instead of the AggregateFunction column. var sql = new StringBuilder( "SELECT processor_id, processor_type, route_id, application_id, " + - "countMerge(total_count) AS total_count, " + - "countIfMerge(failed_count) AS failed_count, " + + "countMerge(total_count) AS tc, " + + "countIfMerge(failed_count) AS fc, " + "CASE WHEN countMerge(total_count) > 0 THEN toFloat64(sumMerge(duration_sum)) / countMerge(total_count) ELSE 0 END AS avg_duration_ms, " + "quantileMerge(0.99)(p99_duration) AS p99_duration_ms " + "FROM stats_1m_processor_detail " + @@ -164,11 +167,11 @@ public class RouteMetricsController { sql.append(" AND application_id = " + lit(appId)); } sql.append(" GROUP BY processor_id, processor_type, route_id, application_id"); - sql.append(" ORDER BY total_count DESC"); + sql.append(" ORDER BY tc DESC"); List metrics = jdbc.query(sql.toString(), (rs, rowNum) -> { - long totalCount = rs.getLong("total_count"); - long failedCount = rs.getLong("failed_count"); + long totalCount = rs.getLong("tc"); + long failedCount = rs.getLong("fc"); double errorRate = failedCount > 0 ? (double) failedCount / totalCount : 0.0; return new ProcessorMetrics( rs.getString("processor_id"),