Skip to content

Commit

Permalink
Add 10Q dbt models (#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
horaceliuHL authored Nov 8, 2024
1 parent 1c87775 commit a70c301
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
11 changes: 11 additions & 0 deletions models/projects/equities/ez_sec_gov_10q.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{
config(
materialized="table",
snowflake_warehouse="X_SMALL",
database="equities",
schema="core",
alias="ez_sec_metrics",
)
}}

select * from {{ ref("fact_sec_gov_10q_pivot") }}
6 changes: 6 additions & 0 deletions models/staging/equities/__equities__source.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sources:
- name: PROD_LANDING
schema: PROD_LANDING
database: LANDING_DATABASE
tables:
- name: equities_metrics
23 changes: 23 additions & 0 deletions models/staging/equities/fact_sec_gov_10q.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{ config(materialized="table") }}
with
max_extraction as (
select max(extraction_date) as max_date
from {{ source("PROD_LANDING", "equities_metrics") }}
),
data as (
select
value:"cik"::NUMBER AS cik,
value:"adsh"::NUMBER AS adsh,
value:"company_name"::VARCHAR AS company_name,
value:"metric_name"::VARCHAR AS metric_name,
value:"metric_value"::VARCHAR AS metric_value,
value:"parent_metric"::VARCHAR AS parent_metric,
value:"time_period"::VARCHAR AS time_period,
to_date(to_timestamp(value:"date"::NUMBER / 1000)) AS date,
extraction_date
from
{{ source("PROD_LANDING", "equities_metrics") }},
lateral flatten(input => parse_json(source_json))
where extraction_date = (select max_date from max_extraction)
)
select * from data
32 changes: 32 additions & 0 deletions models/staging/equities/fact_sec_gov_10q_pivot.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{ config(materialized="table") }}

WITH RECURSIVE path_builder AS (
SELECT
cik,
adsh,
company_name,
metric_name,
metric_value,
time_period,
date,
ARRAY_CONSTRUCT(metric_name) AS col_path
FROM {{ ref("fact_sec_gov_10q") }}
WHERE parent_metric IS NULL

UNION ALL

SELECT
child.cik,
child.adsh,
child.company_name,
child.metric_name,
child.metric_value,
child.time_period,
child.date,
ARRAY_APPEND(parent.col_path, child.metric_name) AS col_path
FROM {{ ref("fact_sec_gov_10q") }} AS child
JOIN path_builder AS parent
ON child.parent_metric = parent.metric_name AND child.adsh = parent.adsh AND child.time_period = parent.time_period
)

SELECT * FROM path_builder ORDER BY metric_name

0 comments on commit a70c301

Please sign in to comment.