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"]) }}
|
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
|
||||||
|
|
||||||
with
|
with
|
||||||
|
/*
|
||||||
int_core__bookings as (select * from {{ ref("int_core__bookings") }}),
|
int_core__bookings as (select * from {{ ref("int_core__bookings") }}),
|
||||||
int_core__user_host as (select * from {{ ref("int_core__user_host") }}),
|
int_core__user_host as (select * from {{ ref("int_core__user_host") }}),
|
||||||
int_core__mtd_accommodation_segmentation as (
|
int_core__mtd_accommodation_segmentation as (
|
||||||
|
|
@ -18,8 +19,7 @@ with
|
||||||
int_dates_mtd as (select * from {{ ref("int_dates_mtd") }}),
|
int_dates_mtd as (select * from {{ ref("int_dates_mtd") }}),
|
||||||
int_dates_mtd_by_dimension as (
|
int_dates_mtd_by_dimension as (
|
||||||
select * from {{ ref("int_dates_mtd_by_dimension") }}
|
select * from {{ ref("int_dates_mtd_by_dimension") }}
|
||||||
),
|
),*/
|
||||||
|
|
||||||
-- Created Bookings MTD --
|
-- Created Bookings MTD --
|
||||||
created_year_month as (
|
created_year_month as (
|
||||||
{% for dimension in dimensions %}
|
{% for dimension in dimensions %}
|
||||||
|
|
@ -28,20 +28,22 @@ with
|
||||||
{{ dimension.dimension }} as dimension,
|
{{ dimension.dimension }} as dimension,
|
||||||
{{ dimension.dimension_value }} as dimension_value,
|
{{ dimension.dimension_value }} as dimension_value,
|
||||||
count(b.id_booking) as created_bookings
|
count(b.id_booking) as created_bookings
|
||||||
from int_dates_mtd d
|
from {{ ref("int_dates_mtd") }} d
|
||||||
inner join
|
inner join
|
||||||
int_core__bookings b
|
{{ ref("int_core__bookings") }} b
|
||||||
on date_trunc('month', b.created_date_utc)::date = d.first_day_month
|
on date_trunc('month', b.created_date_utc)::date = d.first_day_month
|
||||||
and extract(day from b.created_date_utc) <= d.day
|
and extract(day from b.created_date_utc) <= d.day
|
||||||
{% if dimension.dimension == "'by_number_of_listings'" %}
|
{% 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
|
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
|
on u.id_deal = mas.id_deal
|
||||||
and d.date = mas.date
|
and d.date = mas.date
|
||||||
{% elif dimension.dimension == "'by_billing_country'" %}
|
{% elif dimension.dimension == "'by_billing_country'" %}
|
||||||
inner join
|
inner join
|
||||||
int_core__user_host u
|
{{ ref("int_core__user_host") }} u
|
||||||
on b.id_user_host = u.id_user_host
|
on b.id_user_host = u.id_user_host
|
||||||
and u.main_billing_country_iso_3_per_deal is not null
|
and u.main_billing_country_iso_3_per_deal is not null
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
@ -59,20 +61,22 @@ with
|
||||||
{{ dimension.dimension }} as dimension,
|
{{ dimension.dimension }} as dimension,
|
||||||
{{ dimension.dimension_value }} as dimension_value,
|
{{ dimension.dimension_value }} as dimension_value,
|
||||||
count(b.id_booking) as check_out_bookings
|
count(b.id_booking) as check_out_bookings
|
||||||
from int_dates_mtd d
|
from {{ ref("int_dates_mtd") }} d
|
||||||
inner join
|
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
|
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
|
and extract(day from b.check_out_date_utc) <= d.day
|
||||||
{% if dimension.dimension == "'by_number_of_listings'" %}
|
{% 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
|
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
|
on u.id_deal = mas.id_deal
|
||||||
and d.date = mas.date
|
and d.date = mas.date
|
||||||
{% elif dimension.dimension == "'by_billing_country'" %}
|
{% elif dimension.dimension == "'by_billing_country'" %}
|
||||||
inner join
|
inner join
|
||||||
int_core__user_host u
|
{{ ref("int_core__user_host") }} u
|
||||||
on b.id_user_host = u.id_user_host
|
on b.id_user_host = u.id_user_host
|
||||||
and u.main_billing_country_iso_3_per_deal is not null
|
and u.main_billing_country_iso_3_per_deal is not null
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
@ -90,21 +94,23 @@ with
|
||||||
{{ dimension.dimension }} as dimension,
|
{{ dimension.dimension }} as dimension,
|
||||||
{{ dimension.dimension_value }} as dimension_value,
|
{{ dimension.dimension_value }} as dimension_value,
|
||||||
count(b.id_booking) as cancelled_bookings
|
count(b.id_booking) as cancelled_bookings
|
||||||
from int_dates_mtd d
|
from {{ ref("int_dates_mtd") }} d
|
||||||
inner join
|
inner join
|
||||||
int_core__bookings b
|
{{ ref("int_core__bookings") }} b
|
||||||
on date_trunc('month', b.updated_date_utc)::date = d.first_day_month
|
on date_trunc('month', b.updated_date_utc)::date = d.first_day_month
|
||||||
and extract(day from b.updated_date_utc) <= d.day
|
and extract(day from b.updated_date_utc) <= d.day
|
||||||
and upper(b.booking_state) = {{ var("cancelled_booking_state") }}
|
and upper(b.booking_state) = {{ var("cancelled_booking_state") }}
|
||||||
{% if dimension.dimension == "'by_number_of_listings'" %}
|
{% 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
|
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
|
on u.id_deal = mas.id_deal
|
||||||
and d.date = mas.date
|
and d.date = mas.date
|
||||||
{% elif dimension.dimension == "'by_billing_country'" %}
|
{% elif dimension.dimension == "'by_billing_country'" %}
|
||||||
inner join
|
inner join
|
||||||
int_core__user_host u
|
{{ ref("int_core__user_host") }} u
|
||||||
on b.id_user_host = u.id_user_host
|
on b.id_user_host = u.id_user_host
|
||||||
and u.main_billing_country_iso_3_per_deal is not null
|
and u.main_billing_country_iso_3_per_deal is not null
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
@ -122,23 +128,27 @@ with
|
||||||
{{ dimension.dimension }} as dimension,
|
{{ dimension.dimension }} as dimension,
|
||||||
{{ dimension.dimension_value }} as dimension_value,
|
{{ dimension.dimension_value }} as dimension_value,
|
||||||
count(bce.id_booking) as billable_bookings
|
count(bce.id_booking) as billable_bookings
|
||||||
from int_dates_mtd d
|
from {{ ref("int_dates_mtd") }} d
|
||||||
inner join
|
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
|
on date_trunc('month', bce.booking_fee_charge_date_utc)::date
|
||||||
= d.first_day_month
|
= d.first_day_month
|
||||||
and extract(day from bce.booking_fee_charge_date_utc) <= d.day
|
and extract(day from bce.booking_fee_charge_date_utc) <= d.day
|
||||||
{% if dimension.dimension == "'by_number_of_listings'" %}
|
{% 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
|
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
|
on u.id_deal = mas.id_deal
|
||||||
and d.date = mas.date
|
and d.date = mas.date
|
||||||
{% elif dimension.dimension == "'by_billing_country'" %}
|
{% elif dimension.dimension == "'by_billing_country'" %}
|
||||||
inner join int_core__bookings b on b.id_booking = bce.id_booking
|
|
||||||
inner join
|
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
|
on b.id_user_host = u.id_user_host
|
||||||
and u.main_billing_country_iso_3_per_deal is not null
|
and u.main_billing_country_iso_3_per_deal is not null
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
@ -163,7 +173,7 @@ select
|
||||||
coym.check_out_bookings,
|
coym.check_out_bookings,
|
||||||
caym.cancelled_bookings,
|
caym.cancelled_bookings,
|
||||||
biym.billable_bookings
|
biym.billable_bookings
|
||||||
from int_dates_mtd_by_dimension d
|
from {{ ref("int_dates_mtd_by_dimension") }} d
|
||||||
left join
|
left join
|
||||||
created_year_month crym
|
created_year_month crym
|
||||||
on crym.date = d.date
|
on crym.date = d.date
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue