-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Payments: Add string handling, refactor modeling of Elavon data (#2957)
* refactored staging table to focus on cleaning * broke out intermediate tables to focus on billing and deposits exclusively, and deduplicate * removed cleaning steps and refactored to focus on union of billing and deposits * replace previous transactions table * broke out intermediate tables to focus on billing and deposits exclusively, and deduplicate * made parse_elavon_date macro, implemented in stg_elavon_transactions * combined import CTEs for conciseness * implement qualify for intermediate table deduplication * changed elavon fact table name back to fct_elavon__transactions for the time being * removed _deduped from elavon intermediate tables since this is now handled in staging * fixed table names downstream for renamed tables * missed some renaming downstream * removed always null columns from int_elavon__billing_transactions * moved elavon deduplication to staging table * updated dbt docs
- Loading branch information
1 parent
3a27a09
commit e0e3873
Showing
7 changed files
with
341 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% macro parse_elavon_date(column_name) %} | ||
|
||
CASE | ||
WHEN LENGTH({{ column_name }}) < 8 | ||
THEN PARSE_DATE('%m%d%Y', CONCAT(0, {{ column_name }})) | ||
ELSE PARSE_DATE('%m%d%Y', {{ column_name }}) | ||
END | ||
|
||
{% endmacro %} |
4 changes: 3 additions & 1 deletion
4
...se/models/mart/payments/elavon_littlepay__daily_history_transactions_deposits_billing.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 62 additions & 82 deletions
144
warehouse/models/mart/payments/fct_elavon__transactions.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,78 @@ | ||
{{ config(materialized='table') }} | ||
|
||
WITH stg_elavon__transactions AS ( | ||
SELECT * FROM {{ ref('stg_elavon__transactions') }} | ||
), | ||
WITH | ||
|
||
remove_special_characters AS ( | ||
SELECT | ||
int_elavon__billing_transactions AS ( | ||
SELECT * FROM {{ ref('int_elavon__billing_transactions') }} | ||
), | ||
|
||
* EXCEPT (fund_amt, batch_amt, amount, surchg_amount, convnce_amt, payment_date, transaction_date, settlement_date), | ||
int_elavon__deposit_transactions AS ( | ||
SELECT * FROM {{ ref('int_elavon__deposit_transactions') }} | ||
), | ||
|
||
CAST(REGEXP_REPLACE(fund_amt, r'\$|,', '') as NUMERIC) AS fund_amt, | ||
CAST(REGEXP_REPLACE(batch_amt, r'\$|,', '') as NUMERIC) AS batch_amt, | ||
CAST(REGEXP_REPLACE(amount, r'\$|,', '') as NUMERIC) AS amount, | ||
CAST(REGEXP_REPLACE(surchg_amount, r'\$|,', '') as NUMERIC) AS surchg_amount, | ||
CAST(REGEXP_REPLACE(convnce_amt, r'\$|,', '') as NUMERIC) AS convnce_amt, | ||
union_deposits_and_billing AS ( | ||
|
||
REGEXP_EXTRACT(payment_date, r'[^@\.]+') AS payment_date, | ||
REGEXP_EXTRACT(transaction_date, r'[^@\.]+') AS transaction_date, | ||
REGEXP_EXTRACT(settlement_date, r'[^@\.]+') AS settlement_date | ||
SELECT | ||
* | ||
FROM int_elavon__billing_transactions | ||
UNION ALL | ||
SELECT | ||
* | ||
FROM int_elavon__deposit_transactions | ||
|
||
FROM stg_elavon__transactions | ||
), | ||
|
||
fct_elavon__transactions AS ( | ||
SELECT | ||
|
||
* EXCEPT (payment_date, transaction_date, settlement_date), | ||
|
||
CASE WHEN | ||
LENGTH(payment_date) < 8 | ||
THEN PARSE_DATE('%m%d%Y', CONCAT(0, payment_date)) | ||
ELSE PARSE_DATE('%m%d%Y', payment_date) | ||
END AS payment_date, | ||
SELECT | ||
|
||
CASE WHEN | ||
LENGTH(transaction_date) < 8 | ||
THEN PARSE_DATE('%m%d%Y', CONCAT(0, transaction_date)) | ||
ELSE PARSE_DATE('%m%d%Y', transaction_date) | ||
END AS transaction_date, | ||
payment_reference, | ||
payment_date, | ||
account_number, | ||
routing_number, | ||
fund_amt, | ||
batch_reference, | ||
batch_type, | ||
customer_batch_reference, | ||
customer_name, | ||
merchant_number, | ||
external_mid, | ||
store_number, | ||
chain, | ||
batch_amt, | ||
amount, | ||
surchg_amount, | ||
convnce_amt, | ||
card_type, | ||
charge_type, | ||
charge_type_description, | ||
card_plan, | ||
card_no, | ||
chk_num, | ||
transaction_date, | ||
settlement_date, | ||
authorization_code, | ||
chargeback_control_no, | ||
roc_text, | ||
trn_aci, | ||
card_scheme_ref, | ||
trn_ref_num, | ||
settlement_method, | ||
currency_code, | ||
cb_acq_ref_id, | ||
chgbk_rsn_code, | ||
chgbk_rsn_desc, | ||
mer_ref, | ||
purch_id, | ||
cust_cod, | ||
trn_arn, | ||
term_id, | ||
ent_num, | ||
dt, | ||
execution_ts | ||
|
||
CASE WHEN | ||
LENGTH(settlement_date) < 8 | ||
THEN PARSE_DATE('%m%d%Y', CONCAT(0, settlement_date)) | ||
ELSE PARSE_DATE('%m%d%Y', settlement_date) | ||
END AS settlement_date | ||
FROM union_deposits_and_billing | ||
|
||
FROM remove_special_characters | ||
) | ||
|
||
SELECT | ||
|
||
payment_reference, | ||
payment_date, | ||
account_number, | ||
routing_number, | ||
fund_amt, | ||
batch_reference, | ||
batch_type, | ||
customer_batch_reference, | ||
customer_name, | ||
merchant_number, | ||
external_mid, | ||
store_number, | ||
chain, | ||
batch_amt, | ||
amount, | ||
surchg_amount, | ||
convnce_amt, | ||
card_type, | ||
charge_type, | ||
charge_type_description, | ||
card_plan, | ||
card_no, | ||
chk_num, | ||
transaction_date, | ||
settlement_date, | ||
authorization_code, | ||
chargeback_control_no, | ||
roc_text, | ||
trn_aci, | ||
card_scheme_ref, | ||
trn_ref_num, | ||
settlement_method, | ||
currency_code, | ||
cb_acq_ref_id, | ||
chgbk_rsn_code, | ||
chgbk_rsn_desc, | ||
mer_ref, | ||
purch_id, | ||
cust_cod, | ||
trn_arn, | ||
term_id, | ||
ent_num, | ||
dt, | ||
execution_ts | ||
|
||
FROM fct_elavon__transactions | ||
SELECT * FROM fct_elavon__transactions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
warehouse/models/staging/payments/elavon/int_elavon__billing_transactions.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{{ config(materialized='table') }} | ||
|
||
WITH | ||
|
||
billing_transactions AS ( | ||
|
||
SELECT * FROM {{ ref('stg_elavon__transactions') }} | ||
WHERE batch_type = 'B' | ||
|
||
), | ||
|
||
int_elavon__billing_transactions AS ( | ||
|
||
SELECT | ||
|
||
payment_reference, | ||
payment_date, | ||
account_number, | ||
routing_number, | ||
fund_amt, | ||
batch_reference, | ||
batch_type, | ||
customer_name, | ||
merchant_number, | ||
external_mid, | ||
chain, | ||
batch_amt, | ||
amount, | ||
card_type, | ||
charge_type, | ||
charge_type_description, | ||
card_plan, | ||
settlement_method, | ||
currency_code, | ||
ent_num, | ||
dt, | ||
execution_ts | ||
|
||
FROM billing_transactions | ||
|
||
) | ||
|
||
SELECT * FROM int_elavon__billing_transactions |
64 changes: 64 additions & 0 deletions
64
warehouse/models/staging/payments/elavon/int_elavon__deposit_transactions.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{{ config(materialized='table') }} | ||
|
||
WITH | ||
|
||
deposit_transactions AS ( | ||
|
||
SELECT * FROM {{ ref('stg_elavon__transactions') }} | ||
WHERE batch_type = 'D' | ||
|
||
), | ||
|
||
int_elavon__deposit_transactions AS ( | ||
|
||
SELECT | ||
payment_reference, | ||
payment_date, | ||
account_number, | ||
routing_number, | ||
fund_amt, | ||
batch_reference, | ||
batch_type, | ||
customer_batch_reference, | ||
customer_name, | ||
merchant_number, | ||
external_mid, | ||
store_number, | ||
chain, | ||
batch_amt, | ||
amount, | ||
surchg_amount, | ||
convnce_amt, | ||
card_type, | ||
charge_type, | ||
charge_type_description, | ||
card_plan, | ||
card_no, | ||
chk_num, | ||
transaction_date, | ||
settlement_date, | ||
authorization_code, | ||
chargeback_control_no, | ||
roc_text, | ||
trn_aci, | ||
card_scheme_ref, | ||
trn_ref_num, | ||
settlement_method, | ||
currency_code, | ||
cb_acq_ref_id, | ||
chgbk_rsn_code, | ||
chgbk_rsn_desc, | ||
mer_ref, | ||
purch_id, | ||
cust_cod, | ||
trn_arn, | ||
term_id, | ||
ent_num, | ||
dt, | ||
execution_ts | ||
|
||
FROM deposit_transactions | ||
|
||
) | ||
|
||
SELECT * FROM int_elavon__deposit_transactions |
Oops, something went wrong.