0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Updated KPI pipe to fill missing data

closes https://linear.app/tryghost/issue/ANAL-77/na-data-should-be-zero
ref https://www.tinybird.co/blog-posts/tips-9-filling-gaps-in-time-series-on-clickhouse

- Sometimes we have no matching data for a particular date/date range, which makes our charts look super janky
- Clickhouse has a feature to fill these in called WITH FILL, which makes it really easy to fix this!
- WITH FILL works except for on bounce rate. That seems to be due to the column being marked as nullable and so WITH FILL fills missing data with NULL instead of 0
- To fix that, I've updated the code that generates the bounce rate so that it doesn't generate nulls, and that seems to result in a not-nullable column, which then works with WITH FILL
This commit is contained in:
Hannah Wolfe 2024-09-18 14:34:40 +01:00
parent 7c465a5fb5
commit 1c8513d94b

View file

@ -117,7 +117,7 @@ SQL >
member_status,
uniq(session_id) as visits,
sum(pageviews) as pageviews,
sum(case when latest_hit_aux = first_hit_aux then 1 end) / visits as bounce_rate,
sum(case when latest_hit_aux = first_hit_aux then 1 else 0 end) / visits as bounce_rate,
avg(latest_hit_aux - first_hit_aux) as avg_session_sec
from hits
group by date, site_uuid, member_status
@ -142,3 +142,4 @@ SQL >
and member_status IN {{ Array(member_status) }}
{% end %}
group by date
order by date WITH FILL STEP 1