fix: avoid alias shadowing in processor metrics -Merge query
Some checks failed
Some checks failed
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) <noreply@anthropic.com>
This commit is contained in:
@@ -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<ProcessorMetrics> 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"),
|
||||
|
||||
Reference in New Issue
Block a user