Skip to content

Commit

Permalink
T 12902 optimize macro instead of on run end (#1106)
Browse files Browse the repository at this point in the history
Instead of having multiple OPTIMIZE commands running on-run-end, I just implemented a macro that I attach to the weekly job, as well as the newly created "Manually Deploy New Version" job :)
<img width="1350" alt="Capture d’écran 2022-06-01 à 13 13 59" src="https://user-images.githubusercontent.com/66172107/171393092-0559e939-cf65-46c5-99dd-06cf16d64e09.png">

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
soispoke authored Jun 1, 2022
1 parent d87c372 commit 0d9922c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
7 changes: 1 addition & 6 deletions spellbook/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,4 @@ seeds:
tx_hash: string
amount: string

on-run-end:
- "OPTIMIZE transfers_ethereum.erc20_agg_hour"
- "OPTIMIZE transfers_ethereum.erc20_agg_day"
- "OPTIMIZE opensea_ethereum.trades"
- "OPTIMIZE opensea_solana.trades"
- "OPTIMIZE magiceden_solana.trades"

32 changes: 32 additions & 0 deletions spellbook/macros/optimize_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% macro optimize_tables() %}
{%- if flags.full_refresh -%}
{% set transfers_ethereum_erc20_agg_hour %}
OPTIMIZE transfers_ethereum.erc20_agg_hour;
{% endset %}

{% set transfers_ethereum_erc20_agg_day %}
OPTIMIZE transfers_ethereum.erc20_agg_day;
{% endset %}

{% set opensea_ethereum_trades %}
OPTIMIZE opensea_ethereum.trades;
{% endset %}

{% set opensea_solana_trades %}
OPTIMIZE opensea_solana.trades;
{% endset %}

{% set magiceden_solana_trades %}
OPTIMIZE magiceden_solana.trades;
{% endset %}

{% do run_query(transfers_ethereum_erc20_agg_hour) %}
{% do run_query(transfers_ethereum_erc20_agg_day) %}
{% do run_query(opensea_ethereum_trades) %}
{% do run_query(opensea_solana_trades) %}
{% do run_query(magiceden_solana_trades) %}

{% do log("Tables Optimized", info=True) %}
{%- else -%}
{%- endif -%}
{% endmacro %}

0 comments on commit 0d9922c

Please sign in to comment.