diff --git a/definitions/intermediate/int_accounts.sqlx b/definitions/intermediate/int_accounts.sqlx index 67d706fcb..1028dbed3 100644 --- a/definitions/intermediate/int_accounts.sqlx +++ b/definitions/intermediate/int_accounts.sqlx @@ -23,8 +23,7 @@ WITH all_accounts AS ( ), credit_facilities AS ( - SELECT credit_facility_key, - on_balance_sheet_deposit_account_id, + SELECT DISTINCT credit_facility_key, collateral_account_id, disbursed_receivable_account_id, facility_account_id, @@ -38,49 +37,42 @@ WITH all_accounts AS ( ), credit_facility_accounts AS ( - SELECT credit_facility_key, - on_balance_sheet_deposit_account_id AS account_id, - "on_balance_sheet_deposit_account" AS account_type, - FROM credit_facilities - - UNION DISTINCT - - SELECT credit_facility_key, + SELECT DISTINCT credit_facility_key, collateral_account_id AS account_id, "collateral_account" AS account_type, FROM credit_facilities UNION DISTINCT - SELECT credit_facility_key, + SELECT DISTINCT credit_facility_key, disbursed_receivable_account_id AS account_id, "disbursed_receivable_account" AS account_type, FROM credit_facilities UNION DISTINCT - SELECT credit_facility_key, + SELECT DISTINCT credit_facility_key, facility_account_id AS account_id, "facility_account" AS account_type, FROM credit_facilities UNION DISTINCT - SELECT credit_facility_key, + SELECT DISTINCT credit_facility_key, fee_income_account_id AS account_id, "fee_income_account" AS account_type, FROM credit_facilities UNION DISTINCT - SELECT credit_facility_key, + SELECT DISTINCT credit_facility_key, interest_account_id AS account_id, "interest_account" AS account_type, FROM credit_facilities UNION DISTINCT - SELECT credit_facility_key, + SELECT DISTINCT credit_facility_key, interest_receivable_account_id AS account_id, "interest_receivable_account" AS account_type, FROM credit_facilities diff --git a/definitions/intermediate/int_approved_credit_facilities.sqlx b/definitions/intermediate/int_approved_credit_facilities.sqlx index fdca2f4bd..53fafe30a 100644 --- a/definitions/intermediate/int_approved_credit_facilities.sqlx +++ b/definitions/intermediate/int_approved_credit_facilities.sqlx @@ -79,7 +79,7 @@ WITH approved AS ( })} WHERE recorded_at < asof - AND event_type = "interest_incurred" + AND event_type = "interest_accrual_concluded" GROUP BY credit_facility_id @@ -136,7 +136,7 @@ WITH approved AS ( })} WHERE recorded_at < asof - AND event_type = "disbursement_initiated" + AND event_type = "disbursal_initiated" GROUP BY credit_facility_id diff --git a/definitions/outputs/dim_credit_facilities.sqlx b/definitions/outputs/dim_credit_facilities.sqlx index c47293493..ead916c4a 100644 --- a/definitions/outputs/dim_credit_facilities.sqlx +++ b/definitions/outputs/dim_credit_facilities.sqlx @@ -10,55 +10,6 @@ config { SELECT credit_facilities.* EXCEPT (credit_facility_id, customer_id), customer_key, - on_balance_sheet_deposit_account_key, - collateral_account_key, - disbursed_receivable_account_key, - facility_account_key, - fee_income_account_key, - interest_account_key, - interest_receivable_account_key, FROM ${ref("int_approved_credit_facilities")}(TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), DAY)) AS credit_facilities -JOIN ${ref("int_customers")} USING (customer_id, on_balance_sheet_deposit_account_id) -JOIN ( - SELECT - account_id AS on_balance_sheet_deposit_account_id, - account_key AS on_balance_sheet_deposit_account_key, - FROM ${ref("int_accounts")} - ) USING (on_balance_sheet_deposit_account_id) -JOIN ( - SELECT - account_id AS collateral_account_id, - account_key AS collateral_account_key, - FROM ${ref("int_accounts")} - ) USING (collateral_account_id) -JOIN ( - SELECT - account_id AS disbursed_receivable_account_id, - account_key AS disbursed_receivable_account_key, - FROM ${ref("int_accounts")} - ) USING (disbursed_receivable_account_id) -JOIN ( - SELECT - account_id AS facility_account_id, - account_key AS facility_account_key, - FROM ${ref("int_accounts")} - ) USING (facility_account_id) -JOIN ( - SELECT - account_id AS fee_income_account_id, - account_key AS fee_income_account_key, - FROM ${ref("int_accounts")} - ) USING (fee_income_account_id) -JOIN ( - SELECT - account_id AS interest_account_id, - account_key AS interest_account_key, - FROM ${ref("int_accounts")} - ) USING (interest_account_id) -JOIN ( - SELECT - account_id AS interest_receivable_account_id, - account_key AS interest_receivable_account_key, - FROM ${ref("int_accounts")} - ) USING (interest_receivable_account_id) +JOIN ${ref("int_customers")} USING (customer_id)