From 8b62519828ad35edfe9df2e447ac30117b034b95 Mon Sep 17 00:00:00 2001 From: rlsalcido24 Date: Wed, 2 Aug 2023 09:51:43 -0700 Subject: [PATCH] Update CustomerMgmtView.sql --- models/snowflake/base/CustomerMgmtView.sql | 56 ++++++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/models/snowflake/base/CustomerMgmtView.sql b/models/snowflake/base/CustomerMgmtView.sql index 48c120df..55cbc5de 100644 --- a/models/snowflake/base/CustomerMgmtView.sql +++ b/models/snowflake/base/CustomerMgmtView.sql @@ -3,8 +3,56 @@ materialized = 'view' ) }} -select - * -from - {{ source('tpcdi', 'CustomerMgmt') }} + + SELECT + get(xmlget($1, 'Customer'), '@C_ID')::BIGINT as customerid, + get(xmlget(xmlget($1, 'Customer'), 'Account'), '@CA_ID')::BIGINT as accountid, + get(xmlget(xmlget(xmlget($1, 'Customer'), 'Account'), 'CA_B_ID'), '$')::BIGINT as brokerid, + nullif(get(xmlget($1, 'Customer'), '@C_TAX_ID'), '') as taxid, + nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Account'), 'CA_NAME'), '$'), '') as accountdesc, + get(xmlget(xmlget($1, 'Customer'), 'Account'), '@CA_TAX_ST')::TINYINT as taxstatus, + decode(get($1, '@ActionType'), 'NEW','Active', 'ADDACCT','Active', 'UPDACCT','Active', 'UPDCUST','Active', 'CLOSEACCT','Inactive', 'INACT','Inactive') as status, + nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Name'), 'C_L_NAME'), '$'), '') as lastname, + nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Name'), 'C_F_NAME'), '$'), '') as firstname, + nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Name'), 'C_M_NAME'), '$'), '') as middleinitial, + nullif(upper(get(xmlget($1, 'Customer'), '@C_GNDR')), '') as gender, + nullif(get(xmlget($1, 'Customer'), '@C_TIER'), '') as tier, + get(xmlget($1, 'Customer'), '@C_DOB')::DATE as dob, + nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Address'), 'C_ADLINE1'), '$'), '') as addressline1, + nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Address'), 'C_ADLINE2'), '$'), '') as addressline2, + nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Address'), 'C_ZIPCODE'), '$'), '') as postalcode, + nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Address'), 'C_CITY'), '$'), '') as city, + nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Address'), 'C_STATE_PROV'), '$'), '') as stateprov, + nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Address'), 'C_CTRY'), '$'), '') as country, + nvl2( + nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_1'), 'C_LOCAL'), '$'), ''), + concat( + nvl2(nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_1'), 'C_CTRY_CODE'), '$'), ''), '+' || get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_1'), 'CTRY_CODE'), '$') || ' ', ''), + nvl2(nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_1'), 'C_AREA_CODE'), '$'), ''), '(' || get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_1'), 'C_AREA_CODE'), '$') || ') ', ''), + get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_1'), 'C_LOCAL'), '$'), + nvl(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_1'), 'C_EXT'), '$'), '')), + cast(null as string)) phone1, + nvl2( + nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_2'), 'C_LOCAL'), '$'), ''), + concat( + nvl2(nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_2'), 'C_CTRY_CODE'), '$'), ''), '+' || get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_2'), 'CTRY_CODE'), '$') || ' ', ''), + nvl2(nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_2'), 'C_AREA_CODE'), '$'), ''), '(' || get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_2'), 'C_AREA_CODE'), '$') || ') ', ''), + get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_2'), 'C_LOCAL'), '$'), + nvl(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_2'), 'C_EXT'), '$'), '')), + cast(null as string)) phone2, + nvl2( + nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_3'), 'C_LOCAL'), '$'), ''), + concat( + nvl2(nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_3'), 'C_CTRY_CODE'), '$'), ''), '+' || get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_3'), 'CTRY_CODE'), '$') || ' ', ''), + nvl2(nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_3'), 'C_AREA_CODE'), '$'), ''), '(' || get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_3'), 'C_AREA_CODE'), '$') || ') ', ''), + get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_3'), 'C_LOCAL'), '$'), + nvl(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_3'), 'C_EXT'), '$'), '')), + cast(null as string)) phone3, + nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PRIM_EMAIL'), '$'), '') as email1, + nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_ALT_EMAIL'), '$'), '') as email2, + nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'TaxInfo'), 'C_LCL_TX_ID'), '$'), '') as lcl_tx_id, + nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'TaxInfo'), 'C_NAT_TX_ID'), '$'), '') as nat_tx_id, + to_timestamp(get($1, '@ActionTS')) as update_ts, + get($1, '@ActionType') as ActionType + FROM @{{var('stage')}}/Batch1 (FILE_FORMAT => 'XML', PATTERN => '.*CustomerMgmt[.]xml.*')