Question about this… My situation is we have 3 sources synced at different times but I’m creating an events table that runs dbt.union_relations
to union all of these related tables. If I know the events that are synced at different times, is it possible to account for this by running something like this?
{{ config(schema='website_events', materialized='incremental', full_refresh=false) }}
with cte as (
{{
dbt_utils.union_relations(
relations=[
ref('table_one'),
ref('table_two'),
ref('table_three')
include=[
'timestamp',
'event',
'anonymous_id'
]
)
}}
)
-- website
select
timestamp,
event,
anonymous_id
from
cte
where
event not in ('event_one', 'event_two')
{% if is_incremental() %}
and timestamp > (
select max(timestamp) from {{ this }}
where event not in ('event_one', 'event_two')
)
{% endif %}
union all
-- server event
select
timestamp,
event,
anonymous_id
from
cte
where
event in ('event_one', 'event_two')
{% if is_incremental() %}
and timestamp > (
select max(timestamp) from {{ this }}
where event in ('event_one', 'event_two')
)
{% endif %}
order by 1