split staging layer
This commit is contained in:
parent
761cf409c6
commit
67dcc8b237
3 changed files with 100 additions and 5 deletions
10
models/staging/athena/_athena_sources.yml
Normal file
10
models/staging/athena/_athena_sources.yml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
version: 2
|
||||
|
||||
sources:
|
||||
- name: athena
|
||||
# This will have to change to the Athena sync schema once the
|
||||
# Athena/Edeposit database split happens.
|
||||
schema: sync_cdb_edeposit
|
||||
tables:
|
||||
- name: verifications
|
||||
identifier: verifications
|
||||
88
models/staging/athena/stg_athena__verifications.sql
Normal file
88
models/staging/athena/stg_athena__verifications.sql
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
with
|
||||
raw_verifications as (select * from {{ source("athena", "verifications") }}),
|
||||
deduped_verifications as (
|
||||
{{ cosmos_db_record_deduplication("raw_verifications", "id") }}
|
||||
),
|
||||
stg_athena__verifications 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,
|
||||
|
||||
{{ adapter.quote("documents") }} ->> 'Version' as "version",
|
||||
|
||||
cast(
|
||||
{{ adapter.quote("documents") }} ->> 'NightlyFee' as decimal(19, 4)
|
||||
) as "nightly_fee_local",
|
||||
|
||||
{{ 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')::timestamp
|
||||
as checkin_at_utc,
|
||||
({{ adapter.quote("documents") }} ->> 'CheckOut')::timestamp
|
||||
as checkout_at_utc,
|
||||
coalesce(
|
||||
({{ adapter.quote("documents") }} ->> 'Cancelled')::boolean, false
|
||||
) as is_cancelled,
|
||||
({{ adapter.quote("documents") }} ->> 'CancellationDate')::timestamp
|
||||
as cancelled_at_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") }} ->> 'ListingTown' as listing_town,
|
||||
|
||||
{{ adapter.quote("documents") }} ->> 'ListingAddress' as listing_address,
|
||||
{{ adapter.quote("documents") }} ->> 'ListingCountry' as listing_country,
|
||||
{{ adapter.quote("documents") }} ->> 'ListingPostcode' as listing_postcode,
|
||||
({{ adapter.quote("documents") }} ->> 'PetsAllowed')::boolean
|
||||
as pets_allowed,
|
||||
|
||||
({{ adapter.quote("documents") }} ->> 'LevelOfProtectionAmount')::float
|
||||
::integer as level_of_protection_amount,
|
||||
(
|
||||
{{ adapter.quote("documents") }} ->> 'LevelOfProtectionCurrency'
|
||||
) as level_of_protection_currency,
|
||||
|
||||
{{ adapter.quote("documents") }} ->> '_attachments' as attachments,
|
||||
|
||||
({{ 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") }} ->> 'CreationDate')::timestamp
|
||||
as athena_creation_at_utc,
|
||||
({{ adapter.quote("documents") }} ->> 'CreationDate')::date
|
||||
as athena_creation_date_utc,
|
||||
({{ adapter.quote("documents") }} ->> 'CreatedDate')::timestamp
|
||||
as created_at_utc,
|
||||
({{ adapter.quote("documents") }} ->> 'CreatedDate')::date
|
||||
as created_date_utc,
|
||||
to_timestamp(
|
||||
(({{ adapter.quote("documents") }} ->> '_ts'))::integer
|
||||
) as cosmos_db_timestamp_utc
|
||||
from deduped_verifications
|
||||
)
|
||||
select *
|
||||
from stg_athena__verifications
|
||||
Loading…
Add table
Add a link
Reference in a new issue