-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdbt_template_incremental_model.sql
More file actions
33 lines (31 loc) · 1.07 KB
/
dbt_template_incremental_model.sql
File metadata and controls
33 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{#
key notes on table model:
- file_format defaults to delta (TODO: confirm this is dune hive metastore setting)
- when providing file_format config to model, dbt fails on unable to support 'format' property
#}
{{ config(
schema = 'test_schema'
, alias = 'dbt_template_incremental_model'
, materialized = 'incremental'
, incremental_strategy = 'merge'
, unique_key = ['block_number', 'block_date']
, incremental_predicates = ["DBT_INTERNAL_DEST.block_date >= now() - interval '1' day"]
, on_table_exists = 'replace'
)
}}
select
block_number
, block_date
, count(1) as total_tx_per_block -- count per block
from
{{ source('ethereum', 'transactions') }}
where
1 = 1
{%- if is_incremental() %}
AND block_date >= now() - interval '1' day -- on incremental runs, we only want to process the last day of data
{%- else %}
AND block_date >= now() - interval '7' day -- on full refresh runs, we want to process all data (to expedite, keep one week's worth of data)
{%- endif %}
group by
block_number
, block_date