inline the CTEs of the model
This commit is contained in:
parent
1e89966153
commit
c22a840084
1 changed files with 35 additions and 25 deletions
|
|
@ -7,6 +7,7 @@ This model provides Month-To-Date (MTD) based on Booking metrics.
|
|||
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
|
||||
|
||||
with
|
||||
/*
|
||||
int_core__bookings as (select * from {{ ref("int_core__bookings") }}),
|
||||
int_core__user_host as (select * from {{ ref("int_core__user_host") }}),
|
||||
int_core__mtd_accommodation_segmentation as (
|
||||
|
|
@ -18,8 +19,7 @@ with
|
|||
int_dates_mtd as (select * from {{ ref("int_dates_mtd") }}),
|
||||
int_dates_mtd_by_dimension as (
|
||||
select * from {{ ref("int_dates_mtd_by_dimension") }}
|
||||
),
|
||||
|
||||
),*/
|
||||
-- Created Bookings MTD --
|
||||
created_year_month as (
|
||||
{% for dimension in dimensions %}
|
||||
|
|
@ -28,20 +28,22 @@ with
|
|||
{{ dimension.dimension }} as dimension,
|
||||
{{ dimension.dimension_value }} as dimension_value,
|
||||
count(b.id_booking) as created_bookings
|
||||
from int_dates_mtd d
|
||||
from {{ ref("int_dates_mtd") }} d
|
||||
inner join
|
||||
int_core__bookings b
|
||||
{{ ref("int_core__bookings") }} b
|
||||
on date_trunc('month', b.created_date_utc)::date = d.first_day_month
|
||||
and extract(day from b.created_date_utc) <= d.day
|
||||
{% if dimension.dimension == "'by_number_of_listings'" %}
|
||||
inner join int_core__user_host u on b.id_user_host = u.id_user_host
|
||||
inner join
|
||||
int_core__mtd_accommodation_segmentation mas
|
||||
{{ ref("int_core__user_host") }} u
|
||||
on b.id_user_host = u.id_user_host
|
||||
inner join
|
||||
{{ ref("int_core__mtd_accommodation_segmentation") }} mas
|
||||
on u.id_deal = mas.id_deal
|
||||
and d.date = mas.date
|
||||
{% elif dimension.dimension == "'by_billing_country'" %}
|
||||
inner join
|
||||
int_core__user_host u
|
||||
{{ ref("int_core__user_host") }} u
|
||||
on b.id_user_host = u.id_user_host
|
||||
and u.main_billing_country_iso_3_per_deal is not null
|
||||
{% endif %}
|
||||
|
|
@ -59,20 +61,22 @@ with
|
|||
{{ dimension.dimension }} as dimension,
|
||||
{{ dimension.dimension_value }} as dimension_value,
|
||||
count(b.id_booking) as check_out_bookings
|
||||
from int_dates_mtd d
|
||||
from {{ ref("int_dates_mtd") }} d
|
||||
inner join
|
||||
int_core__bookings b
|
||||
{{ ref("int_core__bookings") }} b
|
||||
on date_trunc('month', b.check_out_date_utc)::date = d.first_day_month
|
||||
and extract(day from b.check_out_date_utc) <= d.day
|
||||
{% if dimension.dimension == "'by_number_of_listings'" %}
|
||||
inner join int_core__user_host u on b.id_user_host = u.id_user_host
|
||||
inner join
|
||||
int_core__mtd_accommodation_segmentation mas
|
||||
{{ ref("int_core__user_host") }} u
|
||||
on b.id_user_host = u.id_user_host
|
||||
inner join
|
||||
{{ ref("int_core__mtd_accommodation_segmentation") }} mas
|
||||
on u.id_deal = mas.id_deal
|
||||
and d.date = mas.date
|
||||
{% elif dimension.dimension == "'by_billing_country'" %}
|
||||
inner join
|
||||
int_core__user_host u
|
||||
{{ ref("int_core__user_host") }} u
|
||||
on b.id_user_host = u.id_user_host
|
||||
and u.main_billing_country_iso_3_per_deal is not null
|
||||
{% endif %}
|
||||
|
|
@ -90,21 +94,23 @@ with
|
|||
{{ dimension.dimension }} as dimension,
|
||||
{{ dimension.dimension_value }} as dimension_value,
|
||||
count(b.id_booking) as cancelled_bookings
|
||||
from int_dates_mtd d
|
||||
from {{ ref("int_dates_mtd") }} d
|
||||
inner join
|
||||
int_core__bookings b
|
||||
{{ ref("int_core__bookings") }} b
|
||||
on date_trunc('month', b.updated_date_utc)::date = d.first_day_month
|
||||
and extract(day from b.updated_date_utc) <= d.day
|
||||
and upper(b.booking_state) = {{ var("cancelled_booking_state") }}
|
||||
{% if dimension.dimension == "'by_number_of_listings'" %}
|
||||
inner join int_core__user_host u on b.id_user_host = u.id_user_host
|
||||
inner join
|
||||
int_core__mtd_accommodation_segmentation mas
|
||||
{{ ref("int_core__user_host") }} u
|
||||
on b.id_user_host = u.id_user_host
|
||||
inner join
|
||||
{{ ref("int_core__mtd_accommodation_segmentation") }} mas
|
||||
on u.id_deal = mas.id_deal
|
||||
and d.date = mas.date
|
||||
{% elif dimension.dimension == "'by_billing_country'" %}
|
||||
inner join
|
||||
int_core__user_host u
|
||||
{{ ref("int_core__user_host") }} u
|
||||
on b.id_user_host = u.id_user_host
|
||||
and u.main_billing_country_iso_3_per_deal is not null
|
||||
{% endif %}
|
||||
|
|
@ -122,23 +128,27 @@ with
|
|||
{{ dimension.dimension }} as dimension,
|
||||
{{ dimension.dimension_value }} as dimension_value,
|
||||
count(bce.id_booking) as billable_bookings
|
||||
from int_dates_mtd d
|
||||
from {{ ref("int_dates_mtd") }} d
|
||||
inner join
|
||||
int_core__booking_charge_events bce
|
||||
{{ ref("int_core__booking_charge_events") }} bce
|
||||
on date_trunc('month', bce.booking_fee_charge_date_utc)::date
|
||||
= d.first_day_month
|
||||
and extract(day from bce.booking_fee_charge_date_utc) <= d.day
|
||||
{% if dimension.dimension == "'by_number_of_listings'" %}
|
||||
inner join int_core__bookings b on b.id_booking = bce.id_booking
|
||||
inner join int_core__user_host u on b.id_user_host = u.id_user_host
|
||||
inner join
|
||||
int_core__mtd_accommodation_segmentation mas
|
||||
{{ ref("int_core__bookings") }} b on b.id_booking = bce.id_booking
|
||||
inner join
|
||||
{{ ref("int_core__user_host") }} u
|
||||
on b.id_user_host = u.id_user_host
|
||||
inner join
|
||||
{{ ref("int_core__mtd_accommodation_segmentation") }} mas
|
||||
on u.id_deal = mas.id_deal
|
||||
and d.date = mas.date
|
||||
{% elif dimension.dimension == "'by_billing_country'" %}
|
||||
inner join int_core__bookings b on b.id_booking = bce.id_booking
|
||||
inner join
|
||||
int_core__user_host u
|
||||
{{ ref("int_core__bookings") }} b on b.id_booking = bce.id_booking
|
||||
inner join
|
||||
{{ ref("int_core__user_host") }} u
|
||||
on b.id_user_host = u.id_user_host
|
||||
and u.main_billing_country_iso_3_per_deal is not null
|
||||
{% endif %}
|
||||
|
|
@ -163,7 +173,7 @@ select
|
|||
coym.check_out_bookings,
|
||||
caym.cancelled_bookings,
|
||||
biym.billable_bookings
|
||||
from int_dates_mtd_by_dimension d
|
||||
from {{ ref("int_dates_mtd_by_dimension") }} d
|
||||
left join
|
||||
created_year_month crym
|
||||
on crym.date = d.date
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue