Merged PR 3391: Adds Check-Out, Cancelled and Billable Bookings

# Description

Adds Check-Out, Cancelled and Billable Bookings in the new KPI flow.

For each of these metrics, it includes:
* Daily model
* Monthly/MTD without dimension aggregates
* Monthly/MTD with dimension aggregates
* Schema entries for the abovementioned 5 models
* Temporary test to compare the different metrics against current production KPIs

I also implemented a quick performance fix that removes the dependency of Billable Bookings from Booking Charge Events, since Bookings table already contains the needed information.

# Checklist

- [X] The edited models and dependants run properly with production data.
- [X] The edited models are sufficiently documented.
- [X] The edited models contain PK tests, and I've ran and passed them.
- [NA] I have checked for DRY opportunities with other models and docs.
- [X] I've picked the right materialization for the affected models.

# Other

- [ ] Check if a full-refresh is required after this PR is merged.

Related work items: #23454
This commit is contained in:
Oriol Roqué Paniagua 2024-10-31 14:31:19 +00:00
parent 3ecbcb2c49
commit bf2310301a
19 changed files with 1444 additions and 0 deletions

View file

@ -0,0 +1,52 @@
{% set min_date = "2022-01-01" %}
{% set dimensions = ("global", "by_billing_country") %}
-- "by_number_of_listings" excluded on purpose - there's differences because of daily
-- segmentation
with
new_mtd_billable_bookings as (
select end_date as date, dimension, dimension_value, billable_bookings
from {{ ref("int_kpis__aggregated_mtd_billable_bookings") }}
where
end_date >= '{{ min_date }}'
and dimension in {{ dimensions }}
and dimension_value <> 'UNSET'
),
new_monthly_billable_bookings as (
select end_date as date, dimension, dimension_value, billable_bookings
from {{ ref("int_kpis__aggregated_monthly_billable_bookings") }}
where
end_date >= '{{ min_date }}'
and dimension in {{ dimensions }}
and dimension_value <> 'UNSET'
),
new_billable_bookings as (
select *
from new_mtd_billable_bookings
union all
select *
from new_monthly_billable_bookings
),
old_billable_bookings as (
select date, dimension, dimension_value, billable_bookings
from {{ ref("int_core__mtd_billable_bookings_metric") }}
where date >= '{{ min_date }}' and dimension in {{ dimensions }}
),
comparison as (
select
coalesce(o.date, n.date) as date,
coalesce(o.dimension, n.dimension) as dimension,
coalesce(o.dimension_value, n.dimension_value) as dimension_value,
o.billable_bookings as old_billable_bookings,
n.billable_bookings as new_billable_bookings,
coalesce(o.billable_bookings, 0) - coalesce(n.billable_bookings, 0) as diff
from old_billable_bookings o
full outer join
new_billable_bookings n
on o.date = n.date
and o.dimension = n.dimension
and o.dimension_value = n.dimension_value
)
select *
from comparison
where diff <> 0
order by date desc, abs(diff) desc

View file

@ -0,0 +1,53 @@
{% set min_date = "2022-01-01" %}
{% set dimensions = ("global", "by_billing_country") %}
-- "by_number_of_listings" excluded on purpose - there's differences because of daily
-- segmentation
with
new_mtd_cancelled_bookings as (
select end_date as date, dimension, dimension_value, cancelled_bookings
from {{ ref("int_kpis__aggregated_mtd_cancelled_bookings") }}
where
end_date >= '{{ min_date }}'
and dimension in {{ dimensions }}
and dimension_value <> 'UNSET'
),
new_monthly_cancelled_bookings as (
select end_date as date, dimension, dimension_value, cancelled_bookings
from {{ ref("int_kpis__aggregated_monthly_cancelled_bookings") }}
where
end_date >= '{{ min_date }}'
and dimension in {{ dimensions }}
and dimension_value <> 'UNSET'
),
new_cancelled_bookings as (
select *
from new_mtd_cancelled_bookings
union all
select *
from new_monthly_cancelled_bookings
),
old_cancelled_bookings as (
select date, dimension, dimension_value, cancelled_bookings
from {{ ref("int_core__mtd_cancelled_bookings_metric") }}
where date >= '{{ min_date }}' and dimension in {{ dimensions }}
),
comparison as (
select
coalesce(o.date, n.date) as date,
coalesce(o.dimension, n.dimension) as dimension,
coalesce(o.dimension_value, n.dimension_value) as dimension_value,
o.cancelled_bookings as old_cancelled_bookings,
n.cancelled_bookings as new_cancelled_bookings,
coalesce(o.cancelled_bookings, 0)
- coalesce(n.cancelled_bookings, 0) as diff
from old_cancelled_bookings o
full outer join
new_cancelled_bookings n
on o.date = n.date
and o.dimension = n.dimension
and o.dimension_value = n.dimension_value
)
select *
from comparison
where diff <> 0
order by date desc, abs(diff) desc

View file

@ -0,0 +1,53 @@
{% set min_date = "2022-01-01" %}
{% set dimensions = ("global", "by_billing_country") %}
-- "by_number_of_listings" excluded on purpose - there's differences because of daily
-- segmentation
with
new_mtd_check_out_bookings as (
select end_date as date, dimension, dimension_value, check_out_bookings
from {{ ref("int_kpis__aggregated_mtd_check_out_bookings") }}
where
end_date >= '{{ min_date }}'
and dimension in {{ dimensions }}
and dimension_value <> 'UNSET'
),
new_monthly_check_out_bookings as (
select end_date as date, dimension, dimension_value, check_out_bookings
from {{ ref("int_kpis__aggregated_monthly_check_out_bookings") }}
where
end_date >= '{{ min_date }}'
and dimension in {{ dimensions }}
and dimension_value <> 'UNSET'
),
new_check_out_bookings as (
select *
from new_mtd_check_out_bookings
union all
select *
from new_monthly_check_out_bookings
),
old_check_out_bookings as (
select date, dimension, dimension_value, check_out_bookings
from {{ ref("int_core__mtd_check_out_bookings_metric") }}
where date >= '{{ min_date }}' and dimension in {{ dimensions }}
),
comparison as (
select
coalesce(o.date, n.date) as date,
coalesce(o.dimension, n.dimension) as dimension,
coalesce(o.dimension_value, n.dimension_value) as dimension_value,
o.check_out_bookings as old_check_out_bookings,
n.check_out_bookings as new_check_out_bookings,
coalesce(o.check_out_bookings, 0)
- coalesce(n.check_out_bookings, 0) as diff
from old_check_out_bookings o
full outer join
new_check_out_bookings n
on o.date = n.date
and o.dimension = n.dimension
and o.dimension_value = n.dimension_value
)
select *
from comparison
where diff <> 0
order by date desc, abs(diff) desc