-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c87775
commit a70c301
Showing
4 changed files
with
72 additions
and
0 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,11 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
snowflake_warehouse="X_SMALL", | ||
database="equities", | ||
schema="core", | ||
alias="ez_sec_metrics", | ||
) | ||
}} | ||
|
||
select * from {{ ref("fact_sec_gov_10q_pivot") }} |
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,6 @@ | ||
sources: | ||
- name: PROD_LANDING | ||
schema: PROD_LANDING | ||
database: LANDING_DATABASE | ||
tables: | ||
- name: equities_metrics |
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,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 |
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,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 |