-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Optimism chain sankey dbt (#388)
- Loading branch information
Showing
1 changed file
with
38 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,38 @@ | ||
{{ | ||
config( | ||
materialized="incremental", | ||
snowflake_warehouse="OPTIMISM", | ||
unique_key=["chain", "date", "from_category"], | ||
) | ||
}} | ||
|
||
WITH category_flows as ( | ||
SELECT | ||
DATE_TRUNC('day', block_timestamp) as date, | ||
from_category, | ||
to_category, | ||
sum(amount_usd) as amount_usd | ||
FROM {{ ref("fact_optimism_labeled_transfers") }} | ||
GROUP BY from_category, to_category, date | ||
), application_flows as ( | ||
SELECT | ||
DATE_TRUNC('day', block_timestamp) as date, | ||
from_category, | ||
to_app, | ||
max(to_friendly_name) as to_friendly_name, | ||
sum(amount_usd) as amount_usd | ||
FROM {{ ref("fact_optimism_labeled_transfers") }} | ||
GROUP BY from_category, to_app, date | ||
) | ||
SELECT | ||
'optimism' as chain, | ||
cf.date, | ||
cf.from_category, | ||
cf.to_category, | ||
cf.amount_usd as category_amount_usd, | ||
af.to_app, | ||
af.to_friendly_name, | ||
af.amount_usd as application_amount_usd | ||
FROM category_flows cf | ||
left JOIN application_flows af | ||
ON cf.date = af.date AND cf.to_category = af.from_category |