Below is my data flow in DBT
publisher_DB_view ->(incremental pull)-> Raw_tbl ->(appends)-> stg_tbl
The requirement is that Raw table should pull only the records incrementally from publisher_DB_view where publisher_DB_view .date_id > stg_tbl.date_id. To resolve this i am refering to stg_tbl.date_id inside where clause of raw_tbl.date_id like below .
raw_tbl.sql
{{config(materialized='table')}}
select *
from {{ref('external_db_view')}}
where date_id > ( select max(date_id) from {{ref('stg_tbl)}})
--------------------------------------------------------------
stg_tbl.sql
{{config(materialized='incremental',unique_key='date_id')}}
select *
from {{ref('raw_tbl')}}
My model fails with uncaught exception while parsing. I assume this is because of DAG nature so a child model can not be referenced back in parent model . I tried implementing this by creating a macro / pre_hook to get max(date_id) from stg_tbl and then use in raw_tbl however it also fails with same parsing error . i checked by referring to another model (independent) and then model succeeds)
Is this a real limitation in DBT and if so , is there any work around to get this done ? Thanks in advance for answering !
If
Raw_tblis not needed, thenstg_tblcan be changed to look like dbt's documentation suggestion: