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

Stablecoins: make stablecoin tables incremental #474

Merged
merged 10 commits into from
Oct 1, 2024
9 changes: 8 additions & 1 deletion macros/stablecoins/stablecoin_breakdown.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@ select
, sum(case when is_wallet::number = 1 and date = date_trunc('{{granularity}}', date) then stablecoin_supply else 0 end) as p2p_stablecoin_supply
{% endif %}
from {{ ref("agg_daily_stablecoin_breakdown_silver") }}
{% if is_incremental() %}
where date >= (select dateadd('{{granularity}}', -3, max(date_granularity)) from {{ this }})
{% endif %}
{% if 'application' in breakdowns %}
where application is not null
{% if not is_incremental() %}
where application is not null
{% else %}
and application is not null
{% endif %}
{% endif %}
group by date_granularity {% for breakdown in breakdowns %}, {{ breakdown }} {% endfor %}
order by date_granularity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }}
{{ config(materialized="incremental", unique_key="unique_id", snowflake_warehouse="STABLECOIN_V2_LG") }}
select
date
, contract_address
Expand All @@ -20,4 +20,7 @@ select
, is_wallet
, unique_id
, chain
from {{ ref("agg_daily_stablecoin_breakdown_silver") }}
from {{ ref("agg_daily_stablecoin_breakdown_silver") }}
{% if is_incremental() %}
where date >= (select dateadd('day', -7, max(date)) from {{ this }})
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "application"], snowflake_warehouse="STABLECOIN_V2_LG") }}

{{ stablecoin_breakdown(["application"]) }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG_2") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "chain", "application"], snowflake_warehouse="STABLECOIN_V2_LG_2") }}

{{stablecoin_breakdown(["chain", "application"])}}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG_2") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "symbol", "application"], snowflake_warehouse="STABLECOIN_V2_LG_2") }}

{{stablecoin_breakdown(["symbol", "application"])}}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "category"], snowflake_warehouse="STABLECOIN_V2_LG") }}

{{ stablecoin_breakdown(["category"]) }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG_2") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "chain", "category"], snowflake_warehouse="STABLECOIN_V2_LG_2") }}

{{stablecoin_breakdown(["chain", "category"])}}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG_2") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "symbol", "category"], snowflake_warehouse="STABLECOIN_V2_LG") }}

{{stablecoin_breakdown(["symbol", "category"])}}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG_2") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "chain", "category", "symbol"], snowflake_warehouse="STABLECOIN_V2_LG_2") }}
{{ stablecoin_breakdown(["chain", "category", "symbol"]) }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "chain"], snowflake_warehouse="STABLECOIN_V2_LG") }}

{{ stablecoin_breakdown(["chain"]) }}
Original file line number Diff line number Diff line change
@@ -1,23 +1,71 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }}
{{ config(materialized="incremental", unique_key="unique_id", snowflake_warehouse="STABLECOIN_V2_LG") }}
with
daily_data as (
{{
dbt_utils.union_relations(
relations=[
ref("ez_base_stablecoin_metrics_by_address"),
ref("ez_arbitrum_stablecoin_metrics_by_address"),
ref("ez_optimism_stablecoin_metrics_by_address"),
ref("ez_avalanche_stablecoin_metrics_by_address"),
ref("ez_polygon_stablecoin_metrics_by_address"),
ref("ez_ethereum_stablecoin_metrics_by_address"),
ref("ez_solana_stablecoin_metrics_by_address"),
ref("ez_tron_stablecoin_metrics_by_address"),
ref("ez_bsc_stablecoin_metrics_by_address"),
ref("ez_ton_stablecoin_metrics_by_address"),
ref("ez_celo_stablecoin_metrics_by_address"),
]
)
}}
select *
from {{ref("ez_base_stablecoin_metrics_by_address")}}
{% if is_incremental() %}
where date >= (select dateadd('day', -7, max(date)) from {{ this }})
{% endif %}
union all
select *
from {{ref("ez_arbitrum_stablecoin_metrics_by_address")}}
{% if is_incremental() %}
where date >= (select dateadd('day', -7, max(date)) from {{ this }})
{% endif %}
union all
select *
from {{ref("ez_optimism_stablecoin_metrics_by_address")}}
{% if is_incremental() %}
where date >= (select dateadd('day', -7, max(date)) from {{ this }})
{% endif %}
union all
select *
from {{ref("ez_avalanche_stablecoin_metrics_by_address")}}
{% if is_incremental() %}
where date >= (select dateadd('day', -7, max(date)) from {{ this }})
{% endif %}
union all
select *
from {{ref("ez_polygon_stablecoin_metrics_by_address")}}
{% if is_incremental() %}
where date >= (select dateadd('day', -7, max(date)) from {{ this }})
{% endif %}
union all
select *
from {{ref("ez_ethereum_stablecoin_metrics_by_address")}}
{% if is_incremental() %}
where date >= (select dateadd('day', -7, max(date)) from {{ this }})
{% endif %}
union all
select *
from {{ref("ez_solana_stablecoin_metrics_by_address")}}
{% if is_incremental() %}
where date >= (select dateadd('day', -7, max(date)) from {{ this }})
{% endif %}
union all
select *
from {{ref("ez_tron_stablecoin_metrics_by_address")}}
{% if is_incremental() %}
where date >= (select dateadd('day', -7, max(date)) from {{ this }})
{% endif %}
union all
select *
from {{ref("ez_bsc_stablecoin_metrics_by_address")}}
{% if is_incremental() %}
where date >= (select dateadd('day', -7, max(date)) from {{ this }})
{% endif %}
union all
select *
from {{ref("ez_ton_stablecoin_metrics_by_address")}}
{% if is_incremental() %}
where date >= (select dateadd('day', -7, max(date)) from {{ this }})
{% endif %}
union all
select *
from {{ref("ez_celo_stablecoin_metrics_by_address")}}
{% if is_incremental() %}
where date >= (select dateadd('day', -7, max(date)) from {{ this }})
{% endif %}
)
select
date
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "symbol"], snowflake_warehouse="STABLECOIN_V2_LG") }}

{{ stablecoin_breakdown(["symbol"]) }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG_2") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "symbol", "chain"], snowflake_warehouse="STABLECOIN_V2_LG_2") }}

{{ stablecoin_breakdown(["symbol", "chain"]) }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG_2") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "category"], snowflake_warehouse="STABLECOIN_V2_LG_2") }}

{{ stablecoin_breakdown(["category"], 'month') }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "chain", "category"], snowflake_warehouse="STABLECOIN_V2_LG") }}

{{stablecoin_breakdown(["chain", "category"], "month")}}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "symbol", "category"], snowflake_warehouse="STABLECOIN_V2_LG") }}

{{stablecoin_breakdown(["symbol", "category"], "month")}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "symbol", "chain", "category"], snowflake_warehouse="STABLECOIN_V2_LG") }}

{{ stablecoin_breakdown(["chain", "category", "symbol"], "month") }}

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "chain"], snowflake_warehouse="STABLECOIN_V2_LG") }}

{{ stablecoin_breakdown(["chain"], "month") }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG_2") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "symbol"], snowflake_warehouse="STABLECOIN_V2_LG_2") }}

{{ stablecoin_breakdown(["symbol"], "month") }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG_2") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "symbol", "chain"], snowflake_warehouse="STABLECOIN_V2_LG_2") }}

{{ stablecoin_breakdown(["symbol", "chain"], "month") }}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with
max_date as (
select max(date) as date
from {{ ref("agg_daily_stablecoin_breakdown") }}
from {{ ref("agg_daily_stablecoin_breakdown_silver") }}
)

select
Expand All @@ -12,6 +12,6 @@ select
, sum(stablecoin_daily_txns) as stablecoin_daily_txns
, count(distinct case when stablecoin_transfer_volume > 0 then from_address end) as stablecoin_dau
, sum(case when date = (select date from max_date) then stablecoin_supply end) as stablecoin_supply
from {{ ref("agg_daily_stablecoin_breakdown") }}
from {{ ref("agg_daily_stablecoin_breakdown_silver") }}
where date >= dateadd(day, -31, to_date(sysdate()))
group by chain
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with
max_date as (
select max(date) as date
from {{ ref("agg_daily_stablecoin_breakdown") }}
from {{ ref("agg_daily_stablecoin_breakdown_silver") }}
)

select
Expand All @@ -12,6 +12,6 @@ select
, sum(stablecoin_daily_txns) as stablecoin_daily_txns
, count(distinct case when stablecoin_transfer_volume > 0 then from_address end) as stablecoin_dau
, sum(case when date = (select date from max_date) then stablecoin_supply end) as stablecoin_supply
from {{ ref("agg_daily_stablecoin_breakdown") }}
from {{ ref("agg_daily_stablecoin_breakdown_silver") }}
where date >= dateadd(day, -31, to_date(sysdate()))
group by symbol
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG_2") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "category"], snowflake_warehouse="STABLECOIN_V2_LG_2") }}

{{ stablecoin_breakdown(["category"], 'week') }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }}
{{ config(materialized="incremental", unique_key=["date_granularity" "category"], snowflake_warehouse="STABLECOIN_V2_LG") }}

{{stablecoin_breakdown(["chain", "category"], "week")}}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "symbol", "category"], snowflake_warehouse="STABLECOIN_V2_LG") }}

{{stablecoin_breakdown(["symbol", "category"], "week")}}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "symbol", "category", "chain"], snowflake_warehouse="STABLECOIN_V2_LG") }}

{{ stablecoin_breakdown(["chain", "category", "symbol"], "week") }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "chain"], snowflake_warehouse="STABLECOIN_V2_LG") }}

{{ stablecoin_breakdown(["chain"], "week") }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG_2") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "symbol"], snowflake_warehouse="STABLECOIN_V2_LG_2") }}

{{ stablecoin_breakdown(["symbol"], "week") }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG_2") }}
{{ config(materialized="incremental", unique_key=["date_granularity", "symbol", "chain"], snowflake_warehouse="STABLECOIN_V2_LG_2") }}

{{ stablecoin_breakdown(["symbol", "chain"], "week") }}
Loading