Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: interest accrual star schema #1163

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions definitions/outputs/dim_interest_accrual_events_id.sqlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
config {
type: "table",
description: "Each row represents the unique (surrogate, natural) key pair in interest accrual.",
assertions: {
uniqueKey: ["event_key"],
nonNull: ["event_id"],
},
tags: ["current-dev"],
}

WITH distinct_entries AS (
SELECT DISTINCT
id AS event_id
FROM ${ref({name: "interest_accrual_events", schema: envs.currentImportSchema})}
)

SELECT
ROW_NUMBER() OVER (ORDER BY event_id) AS event_key
, event_id
FROM distinct_entries
20 changes: 20 additions & 0 deletions definitions/outputs/dim_interest_accrual_events_type.sqlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
config {
type: "table",
description: "Each row represents a unique event type in interest accrual event.",
assertions: {
uniqueKey: ["event_type_key"],
nonNull: ["event_type"],
},
tags: ["current-dev"],
}

WITH distinct_entries AS (
SELECT DISTINCT
event_type
FROM ${ref({name: "interest_accrual_events", schema: envs.currentImportSchema})}
)

SELECT
ROW_NUMBER() OVER (ORDER BY event_type) AS event_type_key
, event_type
FROM distinct_entries
39 changes: 39 additions & 0 deletions definitions/outputs/fct_interest_accrual_events.sqlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
config {
type: "table",
description: "Each row represents a unique event/fact of the interest accrual [interest_accrued] of the credit facility.",
assertions: {
uniqueKey: ["event_key"],
nonNull: [
"recorded_at_date_key",
"recorded_at",
"event_type_key",
"accrued_at_date_key",
"accrued_at",
"total",
],
},
tags: ["current-dev"],
}

WITH interest_accrued AS (

SELECT
event_key
, CAST(FORMAT_DATE('%Y%m%d', recorded_at) as INT64) AS recorded_at_date_key
, recorded_at
, event_type_key
, CAST(FORMAT_DATE('%Y%m%d', PARSE_TIMESTAMP('%Y-%m-%dT%H:%M:%E*SZ', JSON_VALUE(event, "$.accrued_at"), "UTC")) as INT64) AS accrued_at_date_key
, PARSE_TIMESTAMP('%Y-%m-%dT%H:%M:%E*SZ', JSON_VALUE(event, "$.accrued_at"), "UTC") AS accrued_at
, CAST(JSON_VALUE(event, "$.total") AS NUMERIC) AS total
FROM ${ref({name: "interest_accrual_events", schema: envs.currentImportSchema})} AS cfe
LEFT JOIN ${ref("dim_interest_accrual_events_id")} AS t0 ON t0.event_id = cfe.id
LEFT JOIN ${ref("dim_interest_accrual_events_type")} AS t1 ON t1.event_type = cfe.event_type
WHERE cfe.event_type = "interest_accrued"
AND JSON_VALUE(event, "$.tx_id") IS NOT NULL

)


SELECT
*
FROM interest_accrued
Loading