Merged PR 5353: Switch int_core__booking_summary to int_booking_summary
# Description This PR does the following: * Moves `core/int_core__booking_summary` to `cross/int_core__booking_summary` * Renames the model `cross/int_core__booking_summary` to `cross/int_booking_summary` * Same for schema entry. In the new schema, I just added in the description how to retrieve exclusively New Dash Bookings for usability purposes. Then, it adapts any dependency on `int_core__booking_summary` to `int_booking_summary` No additional changes - inclusion of Resolution Incidents data will come later in a different PR. # 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. - [X] 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: #30676
This commit is contained in:
parent
a9a1e68624
commit
d33e5ff2b2
17 changed files with 399 additions and 393 deletions
|
|
@ -1,176 +0,0 @@
|
|||
{{ config(materialized="table", unique_key=["id_booking"]) }}
|
||||
with
|
||||
int_core__booking_to_service as (
|
||||
select * from {{ ref("int_core__booking_to_service") }}
|
||||
),
|
||||
int_core__booking_service_detail as (
|
||||
select * from {{ ref("int_core__booking_service_detail") }}
|
||||
)
|
||||
|
||||
select
|
||||
bts.id_booking,
|
||||
bts.id_verification_request,
|
||||
bts.id_accommodation,
|
||||
bts.id_user_product_bundle,
|
||||
bts.id_deal,
|
||||
bts.id_user_host,
|
||||
bts.id_user_guest,
|
||||
bts.booking_status,
|
||||
bts.program_name,
|
||||
bts.booking_created_at_utc,
|
||||
bts.booking_created_date_utc,
|
||||
bts.booking_updated_at_utc,
|
||||
bts.booking_updated_date_utc,
|
||||
bts.booking_check_in_at_utc,
|
||||
bts.booking_check_in_date_utc,
|
||||
bts.booking_check_out_at_utc,
|
||||
bts.booking_check_out_date_utc,
|
||||
bts.booking_number_of_nights,
|
||||
bts.host_currency_code,
|
||||
bts.is_user_in_new_dash,
|
||||
bts.new_dash_version,
|
||||
bts.user_in_new_dash_since_timestamp_at_utc,
|
||||
sum(bsd.service_total_price_in_gbp) as booking_total_price_in_gbp,
|
||||
min(bsd.service_first_chargeable_date_utc) as service_first_chargeable_date_utc,
|
||||
max(bsd.service_last_chargeable_date_utc) as service_last_chargeable_date_utc,
|
||||
min(bsd.service_first_billable_date_utc) as service_first_billable_date_utc,
|
||||
max(bsd.service_last_billable_date_utc) as service_last_billable_date_utc,
|
||||
min(bsd.service_detail_created_at_utc) as service_first_created_at_utc,
|
||||
max(bsd.service_detail_created_at_utc) as service_last_created_at_utc,
|
||||
max(bsd.service_detail_updated_at_utc) as service_last_updated_at_utc,
|
||||
count(distinct bsd.id_booking_service_detail) as number_of_applied_services,
|
||||
count(
|
||||
distinct case
|
||||
when bsd.is_paid_service then bsd.id_booking_service_detail else null
|
||||
end
|
||||
) as number_of_applied_paid_services,
|
||||
count(
|
||||
distinct case
|
||||
when bsd.is_upgraded_service then bsd.id_booking_service_detail else null
|
||||
end
|
||||
) as number_of_applied_upgraded_services,
|
||||
count(
|
||||
distinct case
|
||||
when bsd.is_billable_service then bsd.id_booking_service_detail else null
|
||||
end
|
||||
) as number_of_applied_billable_services,
|
||||
case
|
||||
when
|
||||
sum(bsd.service_total_price_in_gbp) > 0
|
||||
and min(bsd.service_first_chargeable_date_utc) is not null
|
||||
then true
|
||||
else false
|
||||
end as is_booking_chargeable,
|
||||
case
|
||||
when
|
||||
sum(
|
||||
case
|
||||
when bsd.is_billable_service
|
||||
then bsd.service_total_price_in_gbp
|
||||
else 0
|
||||
end
|
||||
)
|
||||
> 0
|
||||
and min(bsd.service_first_billable_date_utc) is not null
|
||||
then true
|
||||
else false
|
||||
end as is_booking_billable,
|
||||
case
|
||||
when sum(case when bsd.is_missing_currency_code then 1 else 0 end) > 0
|
||||
then true
|
||||
else false
|
||||
end as is_missing_currency_code_in_service_detail,
|
||||
case
|
||||
when sum(case when bsd.is_booking_cancelled then 1 else 0 end) > 0
|
||||
then true
|
||||
else false
|
||||
end as is_booking_cancelled,
|
||||
case
|
||||
when bts.id_verification_request is null then false else true
|
||||
end as has_verification_request,
|
||||
case
|
||||
when sum(case when bsd.is_paid_service then 1 else 0 end) > 0
|
||||
then true
|
||||
else false
|
||||
end as has_paid_services,
|
||||
case
|
||||
when sum(case when bsd.is_upgraded_service then 1 else 0 end) > 0
|
||||
then true
|
||||
else false
|
||||
end as has_upgraded_services,
|
||||
case
|
||||
when sum(case when bsd.is_billable_service then 1 else 0 end) > 0
|
||||
then true
|
||||
else false
|
||||
end as has_billable_services,
|
||||
case
|
||||
when
|
||||
sum(case when bsd.service_business_type = 'SCREENING' then 1 else 0 end) > 0
|
||||
then true
|
||||
else false
|
||||
end as has_screening_service_business_type,
|
||||
case
|
||||
when
|
||||
sum(
|
||||
case
|
||||
when
|
||||
bsd.service_business_type = 'SCREENING'
|
||||
and bsd.service_name <> {{ var("default_service") }}
|
||||
then 1
|
||||
else 0
|
||||
end
|
||||
)
|
||||
> 0
|
||||
then true
|
||||
else false
|
||||
end as has_upgraded_screening_service_business_type,
|
||||
case
|
||||
when
|
||||
sum(
|
||||
case
|
||||
when bsd.service_business_type = 'DEPOSIT_MANAGEMENT' then 1 else 0
|
||||
end
|
||||
)
|
||||
> 0
|
||||
then true
|
||||
else false
|
||||
end as has_deposit_management_service_business_type,
|
||||
case
|
||||
when
|
||||
sum(case when bsd.service_business_type = 'PROTECTION' then 1 else 0 end)
|
||||
> 0
|
||||
then true
|
||||
else false
|
||||
end as has_protection_service_business_type,
|
||||
bts.is_missing_id_deal,
|
||||
case
|
||||
when bts.host_currency_code is null then true else false
|
||||
end as is_missing_host_currency_code
|
||||
from int_core__booking_to_service bts
|
||||
inner join
|
||||
int_core__booking_service_detail bsd
|
||||
on bts.id_booking_service_detail = bsd.id_booking_service_detail
|
||||
group by
|
||||
bts.id_booking,
|
||||
bts.id_verification_request,
|
||||
bts.id_accommodation,
|
||||
bts.id_user_product_bundle,
|
||||
bts.id_deal,
|
||||
bts.id_user_host,
|
||||
bts.id_user_guest,
|
||||
bts.booking_status,
|
||||
bts.program_name,
|
||||
bts.booking_created_at_utc,
|
||||
bts.booking_created_date_utc,
|
||||
bts.booking_updated_at_utc,
|
||||
bts.booking_updated_date_utc,
|
||||
bts.booking_check_in_at_utc,
|
||||
bts.booking_check_in_date_utc,
|
||||
bts.booking_check_out_at_utc,
|
||||
bts.booking_check_out_date_utc,
|
||||
bts.booking_number_of_nights,
|
||||
bts.host_currency_code,
|
||||
bts.is_missing_id_deal,
|
||||
bts.is_user_in_new_dash,
|
||||
bts.new_dash_version,
|
||||
bts.user_in_new_dash_since_timestamp_at_utc
|
||||
|
|
@ -3801,381 +3801,6 @@ models:
|
|||
fields will contain different dates. It can be null, thus meaning
|
||||
there's no chargeable date at all.
|
||||
|
||||
- name: int_core__booking_summary
|
||||
description: |
|
||||
This model contains enriched information aggregated at Booking level regarding
|
||||
the services that are applied within a Booking.
|
||||
Specifically, contains both Booking and Services attributes (aggregated), as well
|
||||
as the total price in GBP at this specific moment in time. In other words,
|
||||
it's the snapshot of the current status of the Booking.
|
||||
It's a subset of all bookings since it only applies to bookings that come from
|
||||
hosts that have been migrated into the New Dash or New Pricing.
|
||||
data_tests:
|
||||
- dbt_expectations.expect_column_pair_values_A_to_be_greater_than_B:
|
||||
column_A: booking_check_out_at_utc
|
||||
column_B: booking_check_in_at_utc
|
||||
or_equal: True
|
||||
- dbt_expectations.expect_column_pair_values_A_to_be_greater_than_B:
|
||||
column_A: number_of_applied_services
|
||||
column_B: number_of_applied_paid_services
|
||||
or_equal: True
|
||||
- dbt_expectations.expect_column_pair_values_A_to_be_greater_than_B:
|
||||
column_A: number_of_applied_services
|
||||
column_B: number_of_applied_upgraded_services
|
||||
or_equal: True
|
||||
|
||||
columns:
|
||||
- name: id_booking
|
||||
data_type: bigint
|
||||
description: |
|
||||
The identifier of the booking. Acts as Primary Key to this table.
|
||||
Cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
- unique
|
||||
|
||||
- name: id_verification_request
|
||||
data_type: bigint
|
||||
description:
|
||||
The identifier of the verification request. It acts as Foreign Key to
|
||||
Verification Request table. It can be null.
|
||||
|
||||
- name: id_accommodation
|
||||
data_type: bigint
|
||||
description:
|
||||
The identifier of the accommodation or listing. It acts as Foreign Key
|
||||
to the Accommodation table. It cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: id_user_product_bundle
|
||||
data_type: bigint
|
||||
description:
|
||||
The identifier of the Product Bundle, or program, that a User has applied
|
||||
to the Booking. It acts as Foreign Key to the User Product Bundle table.
|
||||
It cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: id_deal
|
||||
data_type: string
|
||||
description: |
|
||||
Unique identifier of the account. It can be null.
|
||||
|
||||
- name: id_user_host
|
||||
data_type: string
|
||||
description: |
|
||||
Unique identifier of the user that acts as a Host. Cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: id_user_guest
|
||||
data_type: string
|
||||
description: |
|
||||
Unique identifier of the user that acts as a Guest.
|
||||
Can be null if Superhog does not interact with the Guest.
|
||||
|
||||
- name: booking_status
|
||||
data_type: string
|
||||
description: |
|
||||
The current status of the booking. Cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: program_name
|
||||
data_type: string
|
||||
description: |
|
||||
The name of the program, or product bundle, applied to the booking.
|
||||
Cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: booking_created_at_utc
|
||||
data_type: timestamp
|
||||
description: |
|
||||
Timestamp of when the Booking record was created in the Backend.
|
||||
Cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: booking_created_date_utc
|
||||
data_type: date
|
||||
description: |
|
||||
Date of when the Booking record was created in the Backend.
|
||||
Cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: booking_updated_at_utc
|
||||
data_type: timestamp
|
||||
description: |
|
||||
Timestamp of when the Booking record was last updated in the Backend.
|
||||
Cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: booking_updated_date_utc
|
||||
data_type: date
|
||||
description: |
|
||||
Date of when the Booking record was last updated in the Backend.
|
||||
Cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: booking_check_in_at_utc
|
||||
data_type: timestamp
|
||||
description: |
|
||||
Timestamp of the Check-in of the Booking.
|
||||
Cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: booking_check_in_date_utc
|
||||
data_type: timestamp
|
||||
description: |
|
||||
Date of the Check-in of the Booking.
|
||||
Cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: booking_check_out_at_utc
|
||||
data_type: timestamp
|
||||
description: |
|
||||
Timestamp of the Check-out of the Booking.
|
||||
Cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: booking_check_out_date_utc
|
||||
data_type: date
|
||||
description: |
|
||||
Date of the Check-out of the Booking.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: booking_number_of_nights
|
||||
data_type: integer
|
||||
description: |
|
||||
Number of nights between Check-in date and Check-out date.
|
||||
|
||||
- name: host_currency_code
|
||||
data_type: string
|
||||
description: |
|
||||
Iso 4217 currency code for the account of the Host.
|
||||
It can be null.
|
||||
|
||||
- name: is_user_in_new_dash
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to determine if this user host is in New Dash or not.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: new_dash_version
|
||||
data_type: string
|
||||
description: |
|
||||
For users that are in New Dash, specifies the New Dash Version
|
||||
in which these users were moved or joined. It can be null if
|
||||
the user is not in new dash.
|
||||
|
||||
- name: user_in_new_dash_since_timestamp_at_utc
|
||||
data_type: timestamp
|
||||
description: |
|
||||
For users that are in New Dash, the effective date since
|
||||
these users can be considered in New Dash. If the user
|
||||
has moved from Old Dash, it will be the new_dash_move_at_utc.
|
||||
If not, it will correspond to the joined_at_utc. It can be null
|
||||
if the user is not in new dash.
|
||||
|
||||
- name: booking_total_price_in_gbp
|
||||
data_type: decimal
|
||||
description: |
|
||||
Identifies the current total price of the booking by adding up the
|
||||
prices of each service applied to this booking, converted in GBP.
|
||||
Can be null. Can vary over time depending on the service status,
|
||||
payments, etc, as well as it can vary over time until the chargeable
|
||||
date due to the currency rate estimation in the future.
|
||||
|
||||
- name: service_first_chargeable_date_utc
|
||||
data_type: date
|
||||
description: |
|
||||
Identifies the first moment in time in which the first
|
||||
service applied to this booking is supposed to be charged.
|
||||
|
||||
- name: service_last_chargeable_date_utc
|
||||
data_type: date
|
||||
description: |
|
||||
Identifies the last moment in time in which the last
|
||||
service applied to this booking is supposed to be charged.
|
||||
|
||||
- name: service_first_billable_date_utc
|
||||
data_type: date
|
||||
description: |
|
||||
Identifies the first moment in time in which the first
|
||||
service applied to this booking is supposed to be billed.
|
||||
This excludes Guest Payments, and only includes services to
|
||||
be invoiced to the Host.
|
||||
|
||||
- name: service_last_billable_date_utc
|
||||
data_type: date
|
||||
description: |
|
||||
Identifies the last moment in time in which the last
|
||||
service applied to this booking is supposed to be billed.
|
||||
This excludes Guest Payments, and only includes services to
|
||||
be invoiced to the Host.
|
||||
|
||||
- name: service_first_created_at_utc
|
||||
data_type: timestamp
|
||||
description: |
|
||||
Timestamp corresponding to the first creation of a Service
|
||||
record applied to this Booking, according to the Backend.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: service_last_created_at_utc
|
||||
data_type: timestamp
|
||||
description: |
|
||||
Timestamp corresponding to the latest creation of a Service
|
||||
record applied to this Booking, according to the Backend.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: service_last_updated_at_utc
|
||||
data_type: timestamp
|
||||
description: |
|
||||
Timestamp corresponding to the latest update on any Service
|
||||
record applied to this Booking, according to the Backend.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: number_of_applied_services
|
||||
data_type: integer
|
||||
description: |
|
||||
Total number of Services applied to this Booking.
|
||||
|
||||
- name: number_of_applied_paid_services
|
||||
data_type: integer
|
||||
description: |
|
||||
Total number of Services that require a monetary
|
||||
income to Superhog applied to this Booking.
|
||||
|
||||
- name: number_of_applied_upgraded_services
|
||||
data_type: integer
|
||||
description: |
|
||||
Total number of Services different from Basic Screening
|
||||
applied to this Booking.
|
||||
|
||||
- name: number_of_applied_billable_services
|
||||
data_type: integer
|
||||
description: |
|
||||
Total number of Services that require an invoice to the Host
|
||||
to the Host, that are applied to this Booking.
|
||||
|
||||
- name: is_booking_chargeable
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to identify it the Booking is chargeable or not.
|
||||
In essence, it solves the question: are we supposed to get
|
||||
money out of this booking, or not?
|
||||
To be considered as chargeable, a chargeable date needs to exist
|
||||
as well as the total price converted to GBP needs to be strictly
|
||||
greater than 0. The fact that a booking is not chargeable does
|
||||
not necessarily mean that it won't be in the future. Similarly, if
|
||||
the booking is chargeable it does not necessarily mean that is actually
|
||||
charged. It cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: is_booking_billable
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to identify it the Booking is billable or not.
|
||||
In essence, it solves the question: are we supposed to invoice
|
||||
a certain amount to the host to get money out of this booking, or not?
|
||||
To be considered as billable, a billable date needs to exist
|
||||
as well as the total price of billable services, converted to GBP,
|
||||
need to be strictly greater than 0.
|
||||
The fact that a booking is not billable does not necessarily mean that
|
||||
it won't be in the future.
|
||||
The fact that a booking is not billable does not necessarily mean that
|
||||
it's not chargeable, since Guest Payments could still apply.
|
||||
Similarly, if the booking is billable it does not necessarily mean that
|
||||
is actually billed.
|
||||
It cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: is_missing_currency_code_in_service_detail
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to identify if the currency code is missing in any
|
||||
Booking Service Detail record for this Booking.
|
||||
|
||||
- name: is_booking_cancelled
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to identify if the booking has been cancelled or not.
|
||||
|
||||
- name: has_verification_request
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to identify if the booking has a verification request or not.
|
||||
Cannot be null.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: has_paid_services
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to identify if the booking has any paid service or not.
|
||||
|
||||
- name: has_upgraded_services
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to identify if the booking has any service different from
|
||||
Basic Screening or not.
|
||||
|
||||
- name: has_billable_services
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to identify if the booking has any billable service or not.
|
||||
|
||||
- name: has_screening_service_business_type
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to identify if the booking contains any Screening service
|
||||
or not.
|
||||
|
||||
- name: has_upgraded_screening_service_business_type
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to identify if the booking contains any Screening services
|
||||
different from Basic Screening.
|
||||
|
||||
- name: has_deposit_management_service_business_type
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to identify if the booking contains any Deposit
|
||||
Management service or not.
|
||||
|
||||
- name: has_protection_service_business_type
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to identify if the booking contains any Protection
|
||||
service or not.
|
||||
|
||||
- name: is_missing_id_deal
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to identify if the Host for this booking is missing
|
||||
the Id Deal or not.
|
||||
|
||||
- name: is_missing_host_currency_code
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag to identify if the Host for this booking is missing
|
||||
the currency code or not.
|
||||
|
||||
- name: int_core__product_service_billing_item
|
||||
description: |
|
||||
Provides the Billing Items for Product Services in the scope of
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue