-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathlambda_union_by_date.sql
More file actions
51 lines (29 loc) · 824 Bytes
/
lambda_union_by_date.sql
File metadata and controls
51 lines (29 loc) · 824 Bytes
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{% macro lambda_union_by_date(historical_relation, model_sql,tgt_timestamp_column) %}
{% set unique_key = config.get('unique_key', none) %}
with historical as (
select *
{# ,'dw' as _dbt_lambda_view_source, #}
{# ({{ get_max_timestamp(historical_relation,tgt_timestamp_column) }}) as _dbt_last_run_at #}
from {{ historical_relation }}
),
new_raw as (
{{ model_sql }}
),
new as (
select *
{# ,'raw' as _dbt_lambda_view_source, #}
{# {{ dbt_utils.current_timestamp() }} as _dbt_last_run_at #}
from new_raw
),
unioned as (
select * from historical
{% if unique_key %}
where {{ unique_key }} not in (
select {{ unique_key }} from new
)
{% endif %}
union
select * from new
)
select * from unioned
{% endmacro %}