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>