From 463226a44bf8eb1a049b014de93a63dd4ef3cc2b Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Wed, 18 Dec 2024 14:48:36 +0100 Subject: [PATCH] Staging model for all screen & protect price tables --- models/staging/core/_core_sources.yml | 8 + models/staging/core/schema.yml | 357 ++++++++++++++++++ .../core/stg_core__basic_protection.sql | 19 + .../staging/core/stg_core__damage_waiver.sql | 18 + .../core/stg_core__screen_and_protect.sql | 20 + .../core/stg_core__standalone_protection.sql | 22 ++ 6 files changed, 444 insertions(+) create mode 100644 models/staging/core/stg_core__basic_protection.sql create mode 100644 models/staging/core/stg_core__damage_waiver.sql create mode 100644 models/staging/core/stg_core__screen_and_protect.sql create mode 100644 models/staging/core/stg_core__standalone_protection.sql diff --git a/models/staging/core/_core_sources.yml b/models/staging/core/_core_sources.yml index 1f8d27a..3beec08 100644 --- a/models/staging/core/_core_sources.yml +++ b/models/staging/core/_core_sources.yml @@ -267,3 +267,11 @@ sources: identifier: ApimUser - name: ApimUserType identifier: ApimUserType + - name: BasicProtection + identifier: BasicProtection + - name: DamageWaiver + identifier: DamageWaiver + - name: ScreenAndProtect + identifier: ScreenAndProtect + - name: StandaloneProtection + identifier: StandaloneProtection diff --git a/models/staging/core/schema.yml b/models/staging/core/schema.yml index a320691..f462b61 100644 --- a/models/staging/core/schema.yml +++ b/models/staging/core/schema.yml @@ -1443,3 +1443,360 @@ models: Timestamp of when this record was extracted into DWH. tests: - not_null + + - name: stg_core__basic_protection + description: "Contains the basic protection fees and protection amounts + for different protection options and currencies." + tests: + - dbt_expectations.expect_column_pair_values_A_to_be_greater_than_B: + column_A: end_at_utc + column_B: start_at_utc + or_equal: True + columns: + - name: id_basic_protection + data_type: bigint + description: "Unique identifier of the basic protection. + Acts as the primary key for this table." + tests: + - not_null + - unique + + - name: long_stay_fee + data_type: numeric + description: "Nightly fee for long stay bookings" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 1000 + strictly: true + + - name: short_stay_fee + data_type: numeric + description: "Nightly fee for short stay bookings" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 1000 + strictly: true + + - name: id_currency + data_type: bigint + description: "Id of the currency, works as a foreign key to the + currency table" + tests: + - not_null + - relationships: + to: ref('stg_core__currency') + field: id_currency + + - name: protection_basic_amount + data_type: bigint + description: "Amount of basic protection coverage" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 1000000 + strictly: true + + - name: start_at_utc + data_type: timestamp + description: "Timestamp of when this basic protection record is active" + tests: + - not_null + + - name: start_date_utc + data_type: date + description: "Date of when this basic protection record is active" + tests: + - not_null + + - name: end_at_utc + data_type: timestamp + description: + "Timestamp of when this basic protection record is no longer active. + It can be null." + + - name: end_date_utc + data_type: date + description: + "Date of when this basic protection record is no longer active. + It can be null." + + - name: dwh_extracted_at_utc + data_type: timestamp + description: | + Timestamp of when this record was extracted into DWH. + tests: + - not_null + + - name: stg_core__damage_waiver + description: "Contains the damage waiver fees and protection amounts + for different protection options and currencies." + tests: + - dbt_expectations.expect_column_pair_values_A_to_be_greater_than_B: + column_A: end_at_utc + column_B: start_at_utc + or_equal: True + columns: + - name: id_damage_waiver + data_type: bigint + description: "Unique identifier of the damage waiver. + Acts as the primary key for this table." + tests: + - not_null + - unique + + - name: booking_fee + data_type: numeric + description: "Nightly fee for bookings" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 1000 + strictly: true + + - name: id_currency + data_type: bigint + description: "Id of the currency, works as a foreign key to the + currency table" + tests: + - not_null + - relationships: + to: ref('stg_core__currency') + field: id_currency + + - name: protection_basic_amount + data_type: bigint + description: "Amount of basic protection coverage" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 1000000 + strictly: true + + - name: start_at_utc + data_type: timestamp + description: "Timestamp of when this basic protection record is active" + tests: + - not_null + + - name: start_date_utc + data_type: date + description: "Date of when this basic protection record is active" + tests: + - not_null + + - name: end_at_utc + data_type: timestamp + description: + "Timestamp of when this basic protection record is no longer active. + It can be null." + + - name: end_date_utc + data_type: date + description: + "Date of when this basic protection record is no longer active. + It can be null." + + - name: dwh_extracted_at_utc + data_type: timestamp + description: | + Timestamp of when this record was extracted into DWH. + tests: + - not_null + + - name: stg_core__screen_and_protect + description: "Contains the screen and protect fees and protection amounts + for different protection options and currencies." + tests: + - dbt_expectations.expect_column_pair_values_A_to_be_greater_than_B: + column_A: end_at_utc + column_B: start_at_utc + or_equal: True + columns: + - name: id_screen_and_protect + data_type: bigint + description: "Unique identifier of the Screen and Protect record. + Acts as the primary key for this table." + tests: + - not_null + - unique + + - name: long_stay_fee + data_type: numeric + description: "Nightly fee for long stay bookings." + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 1000 + strictly: true + + - name: short_stay_fee + data_type: numeric + description: "Nightly fee for short stay bookings." + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 1000 + strictly: true + + - name: id_currency + data_type: bigint + description: "Id of the currency, works as a foreign key + to the currency table." + tests: + - not_null + - relationships: + to: ref('stg_core__currency') + field: id_currency + + - name: protection_basic_amount + data_type: bigint + description: "Amount of basic protection coverage." + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 1000000 + strictly: true + + - name: protection_extended_amount + data_type: bigint + description: "Amount of extended protection coverage." + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 100000000 + strictly: true + + - name: start_at_utc + data_type: timestamp without time zone + description: "Timestamp when this Screen and Protect record becomes active." + tests: + - not_null + + - name: start_date_utc + data_type: date + description: "Date when this Screen and Protect record becomes active." + tests: + - not_null + + - name: end_at_utc + data_type: timestamp without time zone + description: "Timestamp when this Screen and Protect record is no + longer active. It can be null." + + - name: end_date_utc + data_type: date + description: "Date when this Screen and Protect record is no + longer active. It can be null." + + - name: dwh_extracted_at_utc + data_type: timestamp with time zone + description: | + Timestamp of when this record was extracted into DWH. + tests: + - not_null + + - name: stg_core__standalone_protection + description: "Contains the standalone protection fees and protection amounts + for different protection options and currencies." + tests: + - dbt_expectations.expect_column_pair_values_A_to_be_greater_than_B: + column_A: end_at_utc + column_B: start_at_utc + or_equal: True + columns: + - name: id_standalone_protection + data_type: bigint + description: "Unique identifier for the standalone protection record. + Acts as the primary key for this table." + tests: + - not_null + - unique + + - name: long_stay_fee + data_type: numeric + description: "Nightly fee for long stay bookings." + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 1000 + strictly: true + + - name: short_stay_fee + data_type: numeric + description: "Nightly fee for short stay bookings." + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 1000 + strictly: true + + - name: id_currency + data_type: bigint + description: "Id of the currency, works as a foreign key + to the currency table." + tests: + - not_null + - relationships: + to: ref('stg_core__currency') + field: id_currency + + - name: protection_starting_amount + data_type: bigint + description: "Starting amount of protection coverage." + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 1000000 + strictly: true + + - name: protection_extended_amount + data_type: bigint + description: "Extended amount of protection coverage." + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 100000000 + strictly: true + + - name: start_at_utc + data_type: timestamp without time zone + description: "Timestamp when this standalone protection record becomes active." + tests: + - not_null + + - name: start_date_utc + data_type: date + description: "Date when this standalone protection record becomes active." + tests: + - not_null + + - name: end_at_utc + data_type: timestamp without time zone + description: "Timestamp when this standalone protection record is no + longer active. It can be null." + + - name: end_date_utc + data_type: date + description: "Date when this standalone protection record is no + longer active. It can be null." + + - name: dwh_extracted_at_utc + data_type: timestamp with time zone + description: "Timestamp of when this record was extracted into DWH." + tests: + - not_null diff --git a/models/staging/core/stg_core__basic_protection.sql b/models/staging/core/stg_core__basic_protection.sql new file mode 100644 index 0000000..87145e9 --- /dev/null +++ b/models/staging/core/stg_core__basic_protection.sql @@ -0,0 +1,19 @@ +with + raw_basic_protection as (select * from {{ source("core", "BasicProtection") }}), + stg_core__basic_protection as ( + select + {{ adapter.quote("Id") }} as id_basic_protection, + {{ adapter.quote("LongStay") }} as long_stay_fee, + {{ adapter.quote("ShortStay") }} as short_stay_fee, + {{ adapter.quote("CurrencyId") }} as id_currency, + {{ adapter.quote("BasicAmount") }} as protection_basic_amount, + {{ adapter.quote("StartDate") }} as start_at_utc, + cast({{ adapter.quote("StartDate") }} as date) as start_date_utc, + {{ adapter.quote("EndDate") }} as end_at_utc, + cast({{ adapter.quote("EndDate") }} as date) as end_date_utc, + {{ adapter.quote("_airbyte_extracted_at") }} as dwh_extracted_at_utc + + from raw_basic_protection + ) +select * +from stg_core__basic_protection diff --git a/models/staging/core/stg_core__damage_waiver.sql b/models/staging/core/stg_core__damage_waiver.sql new file mode 100644 index 0000000..cc0af10 --- /dev/null +++ b/models/staging/core/stg_core__damage_waiver.sql @@ -0,0 +1,18 @@ +with + raw_damage_waiver as (select * from {{ source("core", "DamageWaiver") }}), + stg_core__damage_waiver as ( + select + {{ adapter.quote("Id") }} as id_damage_waiver, + {{ adapter.quote("BookingFee") }} as booking_fee, + {{ adapter.quote("CurrencyId") }} as id_currency, + {{ adapter.quote("BasicAmount") }} as protection_basic_amount, + {{ adapter.quote("StartDate") }} as start_at_utc, + cast({{ adapter.quote("StartDate") }} as date) as start_date_utc, + {{ adapter.quote("EndDate") }} as end_at_utc, + cast({{ adapter.quote("EndDate") }} as date) as end_date_utc, + {{ adapter.quote("_airbyte_extracted_at") }} as dwh_extracted_at_utc + + from raw_damage_waiver + ) +select * +from stg_core__damage_waiver diff --git a/models/staging/core/stg_core__screen_and_protect.sql b/models/staging/core/stg_core__screen_and_protect.sql new file mode 100644 index 0000000..a04138c --- /dev/null +++ b/models/staging/core/stg_core__screen_and_protect.sql @@ -0,0 +1,20 @@ +with + raw_screen_and_protect as (select * from {{ source("core", "ScreenAndProtect") }}), + stg_core__screen_and_protect as ( + select + {{ adapter.quote("Id") }} as id_screen_and_protect, + {{ adapter.quote("LongStay") }} as long_stay_fee, + {{ adapter.quote("ShortStay") }} as short_stay_fee, + {{ adapter.quote("CurrencyId") }} as id_currency, + {{ adapter.quote("BasicAmount") }} as protection_basic_amount, + {{ adapter.quote("ExtendedAmount") }} as protection_extended_amount, + {{ adapter.quote("StartDate") }} as start_at_utc, + cast({{ adapter.quote("StartDate") }} as date) as start_date_utc, + {{ adapter.quote("EndDate") }} as end_at_utc, + cast({{ adapter.quote("EndDate") }} as date) as end_date_utc, + {{ adapter.quote("_airbyte_extracted_at") }} as dwh_extracted_at_utc + + from raw_screen_and_protect + ) +select * +from stg_core__screen_and_protect diff --git a/models/staging/core/stg_core__standalone_protection.sql b/models/staging/core/stg_core__standalone_protection.sql new file mode 100644 index 0000000..a29b419 --- /dev/null +++ b/models/staging/core/stg_core__standalone_protection.sql @@ -0,0 +1,22 @@ +with + raw_standalone_protection as ( + select * from {{ source("core", "StandaloneProtection") }} + ), + stg_core__standalone_protection as ( + select + {{ adapter.quote("Id") }} as id_standalone_protection, + {{ adapter.quote("LongStay") }} as long_stay_fee, + {{ adapter.quote("ShortStay") }} as short_stay_fee, + {{ adapter.quote("CurrencyId") }} as id_currency, + {{ adapter.quote("StartingAmount") }} as protection_starting_amount, + {{ adapter.quote("ExtendedAmount") }} as protection_extended_amount, + {{ adapter.quote("StartDate") }} as start_at_utc, + cast({{ adapter.quote("StartDate") }} as date) as start_date_utc, + {{ adapter.quote("EndDate") }} as end_at_utc, + cast({{ adapter.quote("EndDate") }} as date) as end_date_utc, + {{ adapter.quote("_airbyte_extracted_at") }} as dwh_extracted_at_utc + + from raw_standalone_protection + ) +select * +from stg_core__standalone_protection