-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change materialization strategy for uniswap and nft trades (#1160)
This one should work ! I made sure the macros were updated as well, this should improve performance in terms of run/query time. I've checked that: * [ ] I tested the query on dune.com after compiling the model with dbt compile (compiled queries are written to the target directory) * [ ] I used "refs" to reference other models in this repo and "sources" to reference raw or decoded tables * [ ] the directory tree matches the pattern /sector/blockchain/ e.g. /tokens/ethereum * [ ] if adding a new model, I added a test * [ ] the filename is unique and ends with .sql * [ ] each file has only one view, table or function defined * [ ] column names are `lowercase_snake_cased`
- Loading branch information
Showing
11 changed files
with
73 additions
and
65 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
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
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 |
---|---|---|
@@ -1,10 +1,18 @@ | ||
{{ config( | ||
alias='trades' | ||
alias='trades', | ||
materialized ='incremental', | ||
file_format ='delta', | ||
incremental_strategy='merge', | ||
unique_key='unique_trade_id' | ||
) | ||
}} | ||
|
||
SELECT blockchain, 'magiceden' as project, '' as version, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, trade_id FROM | ||
SELECT blockchain, 'magiceden' as project, '' as version, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, unique_trade_id FROM | ||
( | ||
SELECT blockchain, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, trade_id | ||
SELECT blockchain, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, unique_trade_id | ||
FROM {{ ref('magiceden_solana_trades') }} | ||
) | ||
) | ||
{% if is_incremental() %} | ||
-- this filter will only be applied on an incremental run | ||
WHERE block_time > now() - interval 2 days | ||
{% endif %} |
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
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 |
---|---|---|
@@ -1,13 +1,17 @@ | ||
{{ config( | ||
alias='trades' | ||
alias='trades', | ||
materialized ='incremental', | ||
file_format ='delta', | ||
incremental_strategy='merge', | ||
unique_key='unique_trade_id' | ||
) | ||
}} | ||
|
||
SELECT blockchain, project, version, tx_hash, block_time, amount_usd, amount, token_symbol, token_address,trade_id FROM | ||
(SELECT blockchain, project, version, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, trade_id FROM {{ ref('opensea_trades') }} | ||
SELECT blockchain, project, version, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, unique_trade_id FROM | ||
(SELECT blockchain, project, version, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, unique_trade_id FROM {{ ref('opensea_trades') }} | ||
UNION ALL | ||
SELECT blockchain, project, version, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, trade_id FROM {{ ref('magiceden_trades') }}) | ||
SELECT blockchain, project, version, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, unique_trade_id FROM {{ ref('magiceden_trades') }}) | ||
{% if is_incremental() %} | ||
-- this filter will only be applied on an incremental run | ||
where block_time > (select max(block_time) from {{ this }}) | ||
WHERE block_time > now() - interval 2 days | ||
{% endif %} |
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
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 |
---|---|---|
@@ -1,9 +1,18 @@ | ||
{{ config( | ||
alias='trades' | ||
alias='trades', | ||
materialized ='incremental', | ||
file_format ='delta', | ||
incremental_strategy='merge', | ||
unique_key='unique_trade_id' | ||
) | ||
}} | ||
|
||
SELECT blockchain, 'opensea' as project, 'v1' as version, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, trade_id FROM | ||
(SELECT blockchain, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, trade_id FROM {{ ref('opensea_ethereum_trades') }} | ||
SELECT blockchain, 'opensea' as project, 'v1' as version, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, unique_trade_id FROM | ||
(SELECT blockchain, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, unique_trade_id FROM {{ ref('opensea_ethereum_trades') }} | ||
UNION ALL | ||
SELECT blockchain, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, trade_id FROM {{ ref('opensea_solana_trades') }}) | ||
SELECT blockchain, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, unique_trade_id FROM {{ ref('opensea_solana_trades') }}) | ||
{% if is_incremental() %} | ||
-- this filter will only be applied on an incremental run | ||
WHERE block_time > now() - interval 2 days | ||
{% endif %} | ||
|
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
12 changes: 10 additions & 2 deletions
12
spellbook/models/uniswap/ethereum/uniswap_ethereum_trades.sql
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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
{{ | ||
config( | ||
alias='trades' | ||
alias='trades', | ||
materialized ='incremental', | ||
file_format ='delta', | ||
incremental_strategy='merge', | ||
unique_key='unique_trade_id' | ||
) | ||
}} | ||
|
||
SELECT blockchain, project, version, block_time, token_a_symbol, token_b_symbol, | ||
token_a_amount, token_b_amount, trader_a, trader_b, usd_amount, token_a_address, | ||
token_b_address, exchange_contract_address, tx_hash, tx_from, tx_to, trade_id | ||
token_b_address, exchange_contract_address, tx_hash, tx_from, tx_to, unique_trade_id | ||
FROM (SELECT * FROM {{ ref('uniswap_v2_ethereum_trades') }} | ||
UNION ALL | ||
SELECT * FROM {{ ref('uniswap_v3_ethereum_trades') }}) | ||
{% if is_incremental() %} | ||
-- this filter will only be applied on an incremental run | ||
WHERE block_time > now() - interval 2 days | ||
{% endif %} |
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
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