From d5f0db71fd579ab6916eba3649d0df6daa4d3b75 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Tue, 3 Dec 2024 17:29:37 +0100 Subject: [PATCH] Staging model for S&P --- .../_screen_and_protect_sources.yml | 8 + models/staging/screen_and_protect/schema.yml | 202 ++++++++++++++++++ ...een_and_protect__verification_requests.sql | 76 +++++++ 3 files changed, 286 insertions(+) create mode 100644 models/staging/screen_and_protect/_screen_and_protect_sources.yml create mode 100644 models/staging/screen_and_protect/schema.yml create mode 100644 models/staging/screen_and_protect/stg_screen_and_protect__verification_requests.sql diff --git a/models/staging/screen_and_protect/_screen_and_protect_sources.yml b/models/staging/screen_and_protect/_screen_and_protect_sources.yml new file mode 100644 index 0000000..c313bd5 --- /dev/null +++ b/models/staging/screen_and_protect/_screen_and_protect_sources.yml @@ -0,0 +1,8 @@ +version: 2 + +sources: + - name: screen_and_protect + schema: sync_cdb_screen_and_protect + tables: + - name: verificationrequests + identifier: verificationrequests diff --git a/models/staging/screen_and_protect/schema.yml b/models/staging/screen_and_protect/schema.yml new file mode 100644 index 0000000..87bcfc2 --- /dev/null +++ b/models/staging/screen_and_protect/schema.yml @@ -0,0 +1,202 @@ +version: 2 + +models: + - name: stg_screen_and_protect__verification_requests + description: | + Records of verification requests from the Screen and Protect API. The + table tracks verification requests, their outcomes, and related metadata + about guests, listings, and partners. + columns: + - name: id_verification + data_type: text + description: Unique identifier for the verification request. + tests: + - unique + - not_null + + - name: id_booking + data_type: text + description: Unique identifier for the booking associated with the verification. + tests: + - not_null + + - name: id_user_partner + data_type: text + description: Identifier for the partner user initiating the verification. + tests: + - not_null + + - name: id_accommodation + data_type: text + description: Identifier for the accommodation related to the booking. + + - name: protection_basic_amount + data_type: numeric + description: Basic protection amount for the booking. + tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + strictly: true + + - name: protection_extended_amount + data_type: numeric + description: Extended protection amount for the booking. + + - name: pet_protection + data_type: boolean + description: Indicates if pet protection was included. + + - name: verification_status + data_type: text + description: Outcome of the verification process. + tests: + - not_null + - accepted_values: + values: + - "Approved" + - "Flagged" + - "Rejected" + + - name: verification_status_reason + data_type: text + description: Reason for the verification status. + + - name: email_flag + data_type: text + description: Indicates issues with the email address, if any. + + - name: phone_flag + data_type: text + description: Indicates issues with the phone number, if any. + + - name: watch_list + data_type: text + description: Indicates if the guest was flagged on a watchlist. + tests: + - accepted_values: + values: + - "Match" + - "No Match" + + - name: channel + data_type: text + description: Booking channel or source. + + - name: checkin_date_utc + data_type: date + description: Check-in date for the booking. + + - name: checkout_date_utc + data_type: date + description: Check-out date for the booking. + + - name: is_cancelled + data_type: boolean + description: Indicates if the booking was canceled. + tests: + - not_null + + - name: cancelled_at_utc + data_type: timestamp without time zone + description: Timestamp when the booking was canceled. + tests: + - not_null: + where: is_cancelled = true + + - name: user_email + data_type: text + description: Email address of the user associated with the booking. + + - name: guest_email + data_type: text + description: Email address of the guest. + + - name: guest_last_name + data_type: text + description: Last name of the guest. + + - name: guest_first_name + data_type: text + description: First name of the guest. + + - name: guest_telephone + data_type: text + description: Telephone number of the guest. + + - name: company_name + data_type: text + description: Name of the company associated with the booking. + + - name: property_manager_name + data_type: text + description: Name of the property manager. + + - name: property_manager_email + data_type: text + description: Email address of the property manager. + + - name: listing_name + data_type: text + description: Name of the listing. + + - name: listing_address + data_type: text + description: Address of the listing. + + - name: listing_town + data_type: text + description: Town where the listing is located. + + - name: listing_country + data_type: text + description: Country code where the listing is located. + + - name: listing_postcode + data_type: text + description: Postcode of the listing. + + - name: pets_allowed + data_type: boolean + description: Indicates if pets are allowed at the listing. + + - name: status_updated_at_utc + data_type: timestamp without time zone + description: Timestamp of the last status update for the verification. + tests: + - not_null + + - name: status_updated_date_utc + data_type: date + description: Date of the last status update for the verification. + tests: + - not_null + + - name: updated_at_utc + data_type: timestamp without time zone + description: Timestamp of the last update to the record. + tests: + - not_null + + - name: updated_date_utc + data_type: date + description: Date of the last update to the record. + tests: + - not_null + + - name: created_at_utc + data_type: timestamp without time zone + description: Internal timestamp when the record was created. + tests: + - not_null + + - name: created_date_utc + data_type: date + description: Internal date when the record was created. + tests: + - not_null + + - name: cosmos_db_timestamp_utc + data_type: timestamp with time zone + description: Internal Cosmos DB timestamp of the last record update. + tests: + - not_null diff --git a/models/staging/screen_and_protect/stg_screen_and_protect__verification_requests.sql b/models/staging/screen_and_protect/stg_screen_and_protect__verification_requests.sql new file mode 100644 index 0000000..ffd5eba --- /dev/null +++ b/models/staging/screen_and_protect/stg_screen_and_protect__verification_requests.sql @@ -0,0 +1,76 @@ +with + raw_verification_requests as ( + select * from {{ source("screen_and_protect", "verificationrequests") }} + ), + deduped_verifications as ( + {{ cosmos_db_record_deduplication("raw_verification_requests", "id") }} + ), + stg_screen_and_protect__verification_requests as ( + select + {{ adapter.quote("documents") }} ->> 'id' as id_verification, + {{ adapter.quote("documents") }} ->> 'BookingId' as id_booking, + {{ adapter.quote("documents") }} ->> 'userId' as id_user_partner, + {{ adapter.quote("documents") }} ->> 'ListingId' as id_accommodation, + cast( + {{ adapter.quote("documents") }} + ->> 'ProtectionBasicAmount' as decimal(19, 4) + ) as protection_basic_amount, + cast( + {{ adapter.quote("documents") }} + ->> 'ProtectionExtendedAmount' as decimal(19, 4) + ) as protection_extended_amount, + ({{ adapter.quote("documents") }} ->> 'PetProtection')::boolean + as pet_protection, + {{ adapter.quote("documents") }} ->> 'Status' as verification_status, + {{ adapter.quote("documents") }} + ->> 'StatusReason' as verification_status_reason, + {{ adapter.quote("documents") }} ->> 'EmailFlag' as email_flag, + {{ adapter.quote("documents") }} ->> 'PhoneFlag' as phone_flag, + {{ adapter.quote("documents") }} ->> 'WatchList' as watch_list, + {{ adapter.quote("documents") }} ->> 'Channel' as channel, + ({{ adapter.quote("documents") }} ->> 'CheckIn')::date as checkin_date_utc, + ({{ adapter.quote("documents") }} ->> 'CheckOut')::date + as checkout_date_utc, + coalesce( + ({{ adapter.quote("documents") }} ->> 'IsCancelled')::boolean, false + ) as is_cancelled, + ({{ adapter.quote("documents") }} ->> 'CancellationDate')::timestamp + as cancelled_at_utc, + ({{ adapter.quote("documents") }} ->> 'CancellationDate')::date + as cancelled_date_utc, + {{ adapter.quote("documents") }} ->> 'UserEmail' as user_email, + {{ adapter.quote("documents") }} ->> 'GuestEmail' as guest_email, + {{ adapter.quote("documents") }} ->> 'GuestLastName' as guest_last_name, + {{ adapter.quote("documents") }} ->> 'GuestFirstName' as guest_first_name, + {{ adapter.quote("documents") }} ->> 'GuestTelephone' as guest_telephone, + {{ adapter.quote("documents") }} ->> 'CompanyName' as company_name, + {{ adapter.quote("documents") }} + ->> 'PropertyManagerName' as property_manager_name, + {{ adapter.quote("documents") }} + ->> 'PropertyManagerEmail' as property_manager_email, + {{ adapter.quote("documents") }} ->> 'ListingName' as listing_name, + {{ adapter.quote("documents") }} ->> 'AddressLine1' as listing_address, + {{ adapter.quote("documents") }} ->> 'Town' as listing_town, + upper({{ adapter.quote("documents") }} ->> 'CountryIso') as listing_country, + {{ adapter.quote("documents") }} ->> 'Postcode' as listing_postcode, + ({{ adapter.quote("documents") }} ->> 'PetsAllowed')::boolean + as pets_allowed, + ({{ adapter.quote("documents") }} ->> 'StatusUpdatedDate')::timestamp + as status_updated_at_utc, + ({{ adapter.quote("documents") }} ->> 'StatusUpdatedDate')::date + as status_updated_date_utc, + ({{ adapter.quote("documents") }} ->> 'UpdatedDate')::timestamp + as updated_at_utc, + ({{ adapter.quote("documents") }} ->> 'UpdatedDate')::date + as updated_date_utc, + ({{ adapter.quote("documents") }} ->> 'CreatedDate')::timestamp + as created_at_utc, + ({{ adapter.quote("documents") }} ->> 'CreationDate')::date + as created_date_utc, + to_timestamp( + (({{ adapter.quote("documents") }} ->> '_ts'))::integer + ) as cosmos_db_timestamp_utc + from deduped_verifications + ) +select * +from stg_screen_and_protect__verification_requests