Nickel Fang
02/03/2023, 9:48 AMselect region, clock,
cast(sum(error_count)/sum(request_count)>=0.2 as int) as "critical_status",
cast(sum(error_count)/sum(request_count) between 0.1 and 0.2 as int) as "warning_status"
from system_health where
clock>=1675239600000 and clock<1675240200000
group by region, clock limit 500000
if I want to define the threshold of “sum(error_count)/sum(request_count)>=0.2” or “sum(error_count)>=5" as “critical_status”, how can I get the correct sql.
cast(sum(error_count)/sum(request_count)>=0.2 or sum(error_count)>=5 as int) as "critical_status"
it doesn’t work.
Thanks!robert zych
02/03/2023, 3:38 PMEvan Galpin
02/03/2023, 8:18 PMHAVING clause, where having is used for post-aggregation filtering:
select region, clock,
cast(sum(error_count)/sum(request_count) as int) as "critical_status"
from system_health where
clock>=1675239600000 and clock<1675240200000
group by region, clock
HAVING sum(request_count)>=0.2 or sum(error_count)>=5
limit 500000Evan Galpin
02/03/2023, 10:22 PMFILTER expressions very useful, which can often be faster than case statements because they can make use of indexes:
select region, clock,
cast(sum(error_count)/sum(request_count) FILTER (WHERE request_count >=0.2) as int) as "critical_status",
cast(sum(error_count)/sum(request_count) FILTER (WHERE request_count between 0.1 and 0.2) as int) as "warning_status"
from system_health where
clock>=1675239600000 and clock<1675240200000
group by region, clock limit 500000
FILTER expressions with GROUP BY is only supported in Pinot version ≥0.12robert zych
02/03/2023, 10:26 PMEvan Galpin
02/03/2023, 10:28 PMrobert zych
02/03/2023, 10:29 PMrobert zych
02/03/2023, 10:33 PMrobert zych
02/03/2023, 10:34 PMEvan Galpin
02/03/2023, 10:36 PMrobert zych
02/03/2023, 10:53 PMselect region, sum(error_count) / sum(request_count) as error_rate
from system_health
where clock >= 1675239600000 and clock < 1675240200000
group by region
having error_rate >= 0.1Nickel Fang
02/04/2023, 2:21 PM(case when (sum(error_count)/sum(request_count)>=0.2 or sum(error_count)>=5) then 1 else 0 end) as "critical_status"Nickel Fang
02/04/2023, 2:24 PMrobert zych
02/04/2023, 5:57 PM