From 068a7105383f307c80e2b40221ccac899ad26d4f Mon Sep 17 00:00:00 2001 From: jeff-dude Date: Fri, 26 Jul 2024 13:21:34 -0400 Subject: [PATCH] reformat and finalize spell --- ...alances.sql => safe_ethereum_balances.sql} | 63 +++++++++++-------- .../_subprojects_outputs/tokens/balances.yml | 5 ++ 2 files changed, 41 insertions(+), 27 deletions(-) rename dbt_subprojects/hourly_spellbook/models/_project/safe/ethereum/{safe_eth_balances.sql => safe_ethereum_balances.sql} (52%) create mode 100644 sources/_subprojects_outputs/tokens/balances.yml diff --git a/dbt_subprojects/hourly_spellbook/models/_project/safe/ethereum/safe_eth_balances.sql b/dbt_subprojects/hourly_spellbook/models/_project/safe/ethereum/safe_ethereum_balances.sql similarity index 52% rename from dbt_subprojects/hourly_spellbook/models/_project/safe/ethereum/safe_eth_balances.sql rename to dbt_subprojects/hourly_spellbook/models/_project/safe/ethereum/safe_ethereum_balances.sql index 8249b12f2ae..715b8f72fac 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/safe/ethereum/safe_eth_balances.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/safe/ethereum/safe_ethereum_balances.sql @@ -1,17 +1,17 @@ {{ config( - materialized='incremental', - alias='eth_safes_balances', - partition_by=['day'], - unique_key=['day', 'blockchain', 'address', 'balance', 'token_address'], - on_schema_change='sync_all_columns', - file_format='delta', - incremental_strategy='merge', - post_hook="{{ expose_spells( - '[\"ethereum\"]', - 'project', - 'safe', - '[\"safeintern\"]') }}" + schema = 'safe_ethereum', + alias = 'balances', + partition_by = ['day'], + materialized = 'incremental', + incremental_strategy = 'merge', + file_format = 'delta', + unique_key = ['day', 'blockchain', 'address', 'balance', 'token_address'], + on_schema_change = 'sync_all_columns', + post_hook = '{{ expose_spells(\'["ethereum"]\', + "project", + "safe", + \'["safeintern"]\') }}' ) }} @@ -26,17 +26,19 @@ with changed_balances as ( token_id, balance, lead(cast(day as timestamp)) over (partition by token_address, a.address, token_id order by day asc) as next_update_day - from {{ ref('tokens_ethereum_balances_daily_agg') }} a + from {{ source('tokens_ethereum', 'balances_daily_agg') }} a join ( select - address, blockchain + address + , blockchain from {{ ref('safe_ethereum_safes') }} s where blockchain = 'ethereum' ) q on q.address = a.address - where day >= date('2021-07-01') and token_standard in ('native', 'erc20') - {% if is_incremental() %} + where day >= date('2021-07-01') + and token_standard in ('native', 'erc20') + {% if is_incremental() %} and {{ incremental_predicate('day') }} - {% endif %} + {% endif %} ), days as ( select * @@ -59,6 +61,9 @@ forward_fill as ( on d.day >= b.day and (b.next_update_day is null OR d.day < b.next_update_day) where d.day >= cast('2021-07-01' as date) + {% if is_incremental() %} + and {{ incremental_predicate('d.day') }} + {% endif %} ) select b.day, @@ -75,13 +80,17 @@ from ( where balance > 0 ) b left join {{ ref('prices_usd_daily') }} p - on (token_standard = 'erc20' - and b.blockchain = p.blockchain - and b.token_address = p.contract_address - and b.day = p.day) - or (token_standard = 'native' - and p.blockchain is null - and p.contract_address is null - and p.symbol = 'ETH' - and b.day = p.day) -group by 1, 2, 3, 4, 5, 6, 7 + on ( + token_standard = 'erc20' + and b.blockchain = p.blockchain + and b.token_address = p.contract_address + and b.day = p.day + ) + or ( + token_standard = 'native' + and p.blockchain is null + and p.contract_address is null + and p.symbol = 'ETH' + and b.day = p.day + ) +group by 1, 2, 3, 4, 5, 6, 7 \ No newline at end of file diff --git a/sources/_subprojects_outputs/tokens/balances.yml b/sources/_subprojects_outputs/tokens/balances.yml new file mode 100644 index 00000000000..fd1be50a09c --- /dev/null +++ b/sources/_subprojects_outputs/tokens/balances.yml @@ -0,0 +1,5 @@ +version: 2 +sources: + - name: tokens_ethereum + tables: + - name: balances_daily_agg \ No newline at end of file