From 6af92f352f46c7d8cefb4aedccdba1de64d37892 Mon Sep 17 00:00:00 2001 From: Sebastian Melendez Date: Sun, 8 Sep 2024 21:36:17 -0400 Subject: [PATCH 1/8] making stablecoin breakdown incremental --- .../agg_daily_stablecoin_breakdown.sql | 7 +- .../agg_daily_stablecoin_breakdown_silver.sql | 84 +++++++++++++++---- 2 files changed, 71 insertions(+), 20 deletions(-) diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown.sql index bc414380..5d30a674 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown.sql @@ -1,4 +1,4 @@ -{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }} +{{ config(materialized="incremental", snowflake_warehouse="STABLECOIN_V2_LG") }} select date , contract_address @@ -19,4 +19,7 @@ select , stablecoin_supply , is_wallet , chain -from {{ ref("agg_daily_stablecoin_breakdown_silver") }} \ No newline at end of file +from {{ ref("agg_daily_stablecoin_breakdown_silver") }} +{% if is_incremental() %} + where date >= (select dateadd('day', -7, max(date)) from {{ this }}) +{% endif %} \ No newline at end of file diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_silver.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_silver.sql index c944fd4f..e0f209bb 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_silver.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_silver.sql @@ -1,23 +1,71 @@ -{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG") }} +{{ config(materialized="incremental", 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(block_timestamp)) from {{ this }}) + {% endif %} + union all + select * + from {{ref("ez_arbitrum_stablecoin_metrics_by_address")}} + {% if is_incremental() %} + where date >= (select dateadd('day', -7, max(block_timestamp)) from {{ this }}) + {% endif %} + union all + select * + from {{ref("ez_optimism_stablecoin_metrics_by_address")}} + {% if is_incremental() %} + where date >= (select dateadd('day', -7, max(block_timestamp)) from {{ this }}) + {% endif %} + union all + select * + from {{ref("ez_avalanche_stablecoin_metrics_by_address")}} + {% if is_incremental() %} + where date >= (select dateadd('day', -7, max(block_timestamp)) from {{ this }}) + {% endif %} + union all + select * + from {{ref("ez_polygon_stablecoin_metrics_by_address")}} + {% if is_incremental() %} + where date >= (select dateadd('day', -7, max(block_timestamp)) from {{ this }}) + {% endif %} + union all + select * + from {{ref("ez_ethereum_stablecoin_metrics_by_address")}} + {% if is_incremental() %} + where date >= (select dateadd('day', -7, max(block_timestamp)) from {{ this }}) + {% endif %} + union all + select * + from {{ref("ez_solana_stablecoin_metrics_by_address")}} + {% if is_incremental() %} + where date >= (select dateadd('day', -7, max(block_timestamp)) from {{ this }}) + {% endif %} + union all + select * + from {{ref("ez_tron_stablecoin_metrics_by_address")}} + {% if is_incremental() %} + where date >= (select dateadd('day', -7, max(block_timestamp)) from {{ this }}) + {% endif %} + union all + select * + from {{ref("ez_bsc_stablecoin_metrics_by_address")}} + {% if is_incremental() %} + where date >= (select dateadd('day', -7, max(block_timestamp)) from {{ this }}) + {% endif %} + union all + select * + from {{ref("ez_ton_stablecoin_metrics_by_address")}} + {% if is_incremental() %} + where date >= (select dateadd('day', -7, max(block_timestamp)) from {{ this }}) + {% endif %} + union all + select * + from {{ref("ez_celo_stablecoin_metrics_by_address")}} + {% if is_incremental() %} + where date >= (select dateadd('day', -7, max(block_timestamp)) from {{ this }}) + {% endif %} ) select date From b2c6956feb7f4e056c83eda745a00665270507f7 Mon Sep 17 00:00:00 2001 From: Sebastian Melendez Date: Mon, 9 Sep 2024 11:33:44 -0400 Subject: [PATCH 2/8] meging with main --- macros/generate_combinations.sql | 11 ++++++ .../agg_stablecoin_tiles_breakdown.sql | 38 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 macros/generate_combinations.sql create mode 100644 models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown.sql diff --git a/macros/generate_combinations.sql b/macros/generate_combinations.sql new file mode 100644 index 00000000..e935cc02 --- /dev/null +++ b/macros/generate_combinations.sql @@ -0,0 +1,11 @@ +{% macro generate_combinations(chains) %} + {% set all_combinations = [] %} + + {% for r in range(1, chains | length + 1) %} + {% for combination in modules.itertools.combinations(chains, r) %} + {% set all_combinations = all_combinations.append(combination) %} + {% endfor %} + {% endfor %} + + {{ return(all_combinations) }} +{% endmacro %} diff --git a/models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown.sql b/models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown.sql new file mode 100644 index 00000000..9b76cc8f --- /dev/null +++ b/models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown.sql @@ -0,0 +1,38 @@ +{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG_2") }} + + +{% set chains = dbt_utils.get_column_values(table=ref('agg_daily_stablecoin_breakdown'), column='chain') %} + +{% set symbols = dbt_utils.get_column_values(table=ref('agg_daily_stablecoin_breakdown'), column='symbol') %} + + + +{% set all_chain_combinations = generate_combinations(chains) %} + +{% set all_symbol_combinations = generate_combinations(symbols) %} + +{% set all_combinations = all_chain_combinations + all_symbol_combinations %} + +with +stablecoin_data as ( + select * + from {{ ref("agg_daily_stablecoin_breakdown") }} + where date > dateadd(day, -31, to_date(sysdate())) +) + +{% for combination in all_combinations %} + +select + '({{combination | map("string") | sort | join("-")}})' as breakdown + , sum(stablecoin_transfer_volume) as stablecoin_transfer_volume + , 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 = dateadd(day, -1, to_date(sysdate())) then stablecoin_supply end) as stablecoin_supply +from stablecoin_data +where chain in ({{ "'" + combination | map("string") | join("', '") + "'" }}) + +{% if not loop.last %} +union all +{% endif %} + +{% endfor %} \ No newline at end of file From 3d4fb489fee8accb1b964a84fc4905102eb8b5f2 Mon Sep 17 00:00:00 2001 From: Sebastian Melendez Date: Mon, 9 Sep 2024 11:36:33 -0400 Subject: [PATCH 3/8] removing jinja generate query --- macros/generate_combinations.sql | 11 ------ .../agg_stablecoin_tiles_breakdown.sql | 38 ------------------- 2 files changed, 49 deletions(-) delete mode 100644 macros/generate_combinations.sql delete mode 100644 models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown.sql diff --git a/macros/generate_combinations.sql b/macros/generate_combinations.sql deleted file mode 100644 index e935cc02..00000000 --- a/macros/generate_combinations.sql +++ /dev/null @@ -1,11 +0,0 @@ -{% macro generate_combinations(chains) %} - {% set all_combinations = [] %} - - {% for r in range(1, chains | length + 1) %} - {% for combination in modules.itertools.combinations(chains, r) %} - {% set all_combinations = all_combinations.append(combination) %} - {% endfor %} - {% endfor %} - - {{ return(all_combinations) }} -{% endmacro %} diff --git a/models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown.sql b/models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown.sql deleted file mode 100644 index 9b76cc8f..00000000 --- a/models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown.sql +++ /dev/null @@ -1,38 +0,0 @@ -{{ config(materialized="table", snowflake_warehouse="STABLECOIN_V2_LG_2") }} - - -{% set chains = dbt_utils.get_column_values(table=ref('agg_daily_stablecoin_breakdown'), column='chain') %} - -{% set symbols = dbt_utils.get_column_values(table=ref('agg_daily_stablecoin_breakdown'), column='symbol') %} - - - -{% set all_chain_combinations = generate_combinations(chains) %} - -{% set all_symbol_combinations = generate_combinations(symbols) %} - -{% set all_combinations = all_chain_combinations + all_symbol_combinations %} - -with -stablecoin_data as ( - select * - from {{ ref("agg_daily_stablecoin_breakdown") }} - where date > dateadd(day, -31, to_date(sysdate())) -) - -{% for combination in all_combinations %} - -select - '({{combination | map("string") | sort | join("-")}})' as breakdown - , sum(stablecoin_transfer_volume) as stablecoin_transfer_volume - , 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 = dateadd(day, -1, to_date(sysdate())) then stablecoin_supply end) as stablecoin_supply -from stablecoin_data -where chain in ({{ "'" + combination | map("string") | join("', '") + "'" }}) - -{% if not loop.last %} -union all -{% endif %} - -{% endfor %} \ No newline at end of file From 7b2692db221145c27f9b3dd12cbe283e9502396d Mon Sep 17 00:00:00 2001 From: Sebastian Melendez Date: Mon, 9 Sep 2024 11:38:55 -0400 Subject: [PATCH 4/8] adding unique key --- .../stablecoins/breakdowns/agg_daily_stablecoin_breakdown.sql | 2 +- .../breakdowns/agg_daily_stablecoin_breakdown_silver.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown.sql index 5d30a674..5e7dabb7 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown.sql @@ -1,4 +1,4 @@ -{{ config(materialized="incremental", snowflake_warehouse="STABLECOIN_V2_LG") }} +{{ config(materialized="incremental", unique_key="unique_id", snowflake_warehouse="STABLECOIN_V2_LG") }} select date , contract_address diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_silver.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_silver.sql index e0f209bb..fbdfc237 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_silver.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_silver.sql @@ -1,4 +1,4 @@ -{{ config(materialized="incremental", snowflake_warehouse="STABLECOIN_V2_LG") }} +{{ config(materialized="incremental", unique_key="unique_id", snowflake_warehouse="STABLECOIN_V2_LG") }} with daily_data as ( select * From 261ffaa621811bb5d16f742a8f0f7b9ee19a4da6 Mon Sep 17 00:00:00 2001 From: Sebastian Melendez Date: Mon, 9 Sep 2024 13:20:12 -0400 Subject: [PATCH 5/8] updating incremental --- .../agg_daily_stablecoin_breakdown.sql | 1 + .../agg_daily_stablecoin_breakdown_silver.sql | 22 +++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown.sql index 5e7dabb7..73899a1a 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown.sql @@ -18,6 +18,7 @@ select , p2p_stablecoin_daily_txns , stablecoin_supply , is_wallet + , unique_id , chain from {{ ref("agg_daily_stablecoin_breakdown_silver") }} {% if is_incremental() %} diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_silver.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_silver.sql index fbdfc237..4f6c0cfb 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_silver.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_silver.sql @@ -4,67 +4,67 @@ with select * from {{ref("ez_base_stablecoin_metrics_by_address")}} {% if is_incremental() %} - where date >= (select dateadd('day', -7, max(block_timestamp)) from {{ this }}) + 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(block_timestamp)) from {{ this }}) + 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(block_timestamp)) from {{ this }}) + 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(block_timestamp)) from {{ this }}) + 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(block_timestamp)) from {{ this }}) + 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(block_timestamp)) from {{ this }}) + 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(block_timestamp)) from {{ this }}) + 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(block_timestamp)) from {{ this }}) + 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(block_timestamp)) from {{ this }}) + 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(block_timestamp)) from {{ this }}) + 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(block_timestamp)) from {{ this }}) + where date >= (select dateadd('day', -7, max(date)) from {{ this }}) {% endif %} ) select From 146999344efe22be9d3bf79b57a3a8af2d298954 Mon Sep 17 00:00:00 2001 From: Sebastian Melendez Date: Mon, 30 Sep 2024 20:53:17 -0400 Subject: [PATCH 6/8] make incremental breakdowns --- macros/stablecoins/stablecoin_breakdown.sql | 9 ++++++++- .../agg_daily_stablecoin_breakdown_application.sql | 2 +- .../agg_daily_stablecoin_breakdown_application_chain.sql | 2 +- ...agg_daily_stablecoin_breakdown_application_symbol.sql | 2 +- .../agg_daily_stablecoin_breakdown_category.sql | 2 +- .../agg_daily_stablecoin_breakdown_category_chain.sql | 2 +- .../agg_daily_stablecoin_breakdown_category_symbol.sql | 2 +- ..._daily_stablecoin_breakdown_category_symbol_chain.sql | 2 +- .../breakdowns/agg_daily_stablecoin_breakdown_chain.sql | 2 +- .../breakdowns/agg_daily_stablecoin_breakdown_symbol.sql | 2 +- .../agg_daily_stablecoin_breakdown_symbol_chain.sql | 2 +- .../agg_monthly_stablecoin_breakdown_category.sql | 2 +- .../agg_monthly_stablecoin_breakdown_category_chain.sql | 2 +- .../agg_monthly_stablecoin_breakdown_category_symbol.sql | 2 +- ...onthly_stablecoin_breakdown_category_symbol_chain.sql | 2 +- .../agg_monthly_stablecoin_breakdown_chain.sql | 2 +- .../agg_monthly_stablecoin_breakdown_symbol.sql | 2 +- .../agg_monthly_stablecoin_breakdown_symbol_chain.sql | 2 +- .../agg_weekly_stablecoin_breakdown_category.sql | 2 +- .../agg_weekly_stablecoin_breakdown_category_chain.sql | 2 +- .../agg_weekly_stablecoin_breakdown_category_symbol.sql | 2 +- ...weekly_stablecoin_breakdown_category_symbol_chain.sql | 2 +- .../breakdowns/agg_weekly_stablecoin_breakdown_chain.sql | 2 +- .../agg_weekly_stablecoin_breakdown_symbol.sql | 2 +- .../agg_weekly_stablecoin_breakdown_symbol_chain.sql | 2 +- 25 files changed, 32 insertions(+), 25 deletions(-) diff --git a/macros/stablecoins/stablecoin_breakdown.sql b/macros/stablecoins/stablecoin_breakdown.sql index d876ff44..eb9d83bc 100644 --- a/macros/stablecoins/stablecoin_breakdown.sql +++ b/macros/stablecoins/stablecoin_breakdown.sql @@ -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}}', -7, 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 diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_application.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_application.sql index e47eca10..28422bfc 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_application.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_application.sql @@ -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"]) }} \ No newline at end of file diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_application_chain.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_application_chain.sql index a2ab7d20..b60d9709 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_application_chain.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_application_chain.sql @@ -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"])}} diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_application_symbol.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_application_symbol.sql index 9557b6b3..3a0b9cb3 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_application_symbol.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_application_symbol.sql @@ -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"])}} diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category.sql index eae95f8c..372a7bf9 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category.sql @@ -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"]) }} \ No newline at end of file diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category_chain.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category_chain.sql index 353e7d2b..4fae34b3 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category_chain.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category_chain.sql @@ -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"])}} diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category_symbol.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category_symbol.sql index 68195f6c..4ff1ce0c 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category_symbol.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category_symbol.sql @@ -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"])}} diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category_symbol_chain.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category_symbol_chain.sql index 1836627d..d324b3a2 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category_symbol_chain.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_category_symbol_chain.sql @@ -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"]) }} diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_chain.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_chain.sql index 544ac13f..05ef576d 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_chain.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_chain.sql @@ -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"]) }} \ No newline at end of file diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_symbol.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_symbol.sql index 4c892b40..46374263 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_symbol.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_symbol.sql @@ -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"]) }} diff --git a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_symbol_chain.sql b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_symbol_chain.sql index 4a9473fa..111901ba 100644 --- a/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_symbol_chain.sql +++ b/models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_symbol_chain.sql @@ -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"]) }} diff --git a/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category.sql b/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category.sql index b15aeaff..1726b026 100644 --- a/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category.sql +++ b/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category.sql @@ -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') }} \ No newline at end of file diff --git a/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category_chain.sql b/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category_chain.sql index 71b4d4d2..1e02eea1 100644 --- a/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category_chain.sql +++ b/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category_chain.sql @@ -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")}} diff --git a/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category_symbol.sql b/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category_symbol.sql index e43dcc93..d92705b0 100644 --- a/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category_symbol.sql +++ b/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category_symbol.sql @@ -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")}} diff --git a/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category_symbol_chain.sql b/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category_symbol_chain.sql index 20b0713f..c06fac11 100644 --- a/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category_symbol_chain.sql +++ b/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_category_symbol_chain.sql @@ -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") }} diff --git a/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_chain.sql b/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_chain.sql index d6449eb9..22d4cc03 100644 --- a/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_chain.sql +++ b/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_chain.sql @@ -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") }} \ No newline at end of file diff --git a/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_symbol.sql b/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_symbol.sql index e47a966e..952ecd0e 100644 --- a/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_symbol.sql +++ b/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_symbol.sql @@ -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") }} diff --git a/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_symbol_chain.sql b/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_symbol_chain.sql index a055836a..4627b3ad 100644 --- a/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_symbol_chain.sql +++ b/models/metrics/stablecoins/breakdowns/agg_monthly_stablecoin_breakdown_symbol_chain.sql @@ -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") }} diff --git a/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category.sql b/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category.sql index f7b2583f..ba80eace 100644 --- a/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category.sql +++ b/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category.sql @@ -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') }} \ No newline at end of file diff --git a/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category_chain.sql b/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category_chain.sql index 5c6c87c8..8e945749 100644 --- a/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category_chain.sql +++ b/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category_chain.sql @@ -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")}} diff --git a/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category_symbol.sql b/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category_symbol.sql index 2f48e83c..10436163 100644 --- a/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category_symbol.sql +++ b/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category_symbol.sql @@ -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")}} diff --git a/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category_symbol_chain.sql b/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category_symbol_chain.sql index 67145e94..8faa95de 100644 --- a/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category_symbol_chain.sql +++ b/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_category_symbol_chain.sql @@ -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") }} diff --git a/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_chain.sql b/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_chain.sql index 81d744a7..0c78dd48 100644 --- a/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_chain.sql +++ b/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_chain.sql @@ -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") }} \ No newline at end of file diff --git a/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_symbol.sql b/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_symbol.sql index 9bc959eb..795e76c2 100644 --- a/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_symbol.sql +++ b/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_symbol.sql @@ -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") }} diff --git a/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_symbol_chain.sql b/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_symbol_chain.sql index 5739fcc0..057396fa 100644 --- a/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_symbol_chain.sql +++ b/models/metrics/stablecoins/breakdowns/agg_weekly_stablecoin_breakdown_symbol_chain.sql @@ -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") }} From 1f447775670d8e1d5da2e3cc302c90ccd42b5125 Mon Sep 17 00:00:00 2001 From: Sebastian Melendez Date: Tue, 1 Oct 2024 09:39:55 -0400 Subject: [PATCH 7/8] updating lookback period --- macros/stablecoins/stablecoin_breakdown.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/stablecoins/stablecoin_breakdown.sql b/macros/stablecoins/stablecoin_breakdown.sql index eb9d83bc..d17f9cb7 100644 --- a/macros/stablecoins/stablecoin_breakdown.sql +++ b/macros/stablecoins/stablecoin_breakdown.sql @@ -35,7 +35,7 @@ select {% endif %} from {{ ref("agg_daily_stablecoin_breakdown_silver") }} {% if is_incremental() %} - where date >= (select dateadd('{{granularity}}', -7, max(date_granularity)) from {{ this }}) + where date >= (select dateadd('{{granularity}}', -3, max(date_granularity)) from {{ this }}) {% endif %} {% if 'application' in breakdowns %} {% if not is_incremental() %} From 3ce80737b95c159df73f1f938503ce8b090fc80f Mon Sep 17 00:00:00 2001 From: Sebastian Melendez Date: Tue, 1 Oct 2024 10:07:32 -0400 Subject: [PATCH 8/8] switching breakdown to look at silver table --- .../breakdowns/agg_stablecoin_tiles_breakdown_chain.sql | 4 ++-- .../breakdowns/agg_stablecoin_tiles_breakdown_symbol.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown_chain.sql b/models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown_chain.sql index 042b774d..f328e4a8 100644 --- a/models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown_chain.sql +++ b/models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown_chain.sql @@ -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 @@ -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 \ No newline at end of file diff --git a/models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown_symbol.sql b/models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown_symbol.sql index 82a32735..ed1e5a36 100644 --- a/models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown_symbol.sql +++ b/models/metrics/stablecoins/breakdowns/agg_stablecoin_tiles_breakdown_symbol.sql @@ -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 @@ -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 \ No newline at end of file