-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dbt): support column lineage for self-referential incremental mo…
…dels (#23024) ## Summary & Motivation When writing an incremental model, you can use `{{ this }}` as a Jinja variable to self-reference the current model when generating the next batch of incremental rows. This made building column lineage fail, as we did not also pass the schema of the current model to the `sqlglot` optimization function. This fixes that. ## How I Tested These Changes pytest -- updated incremental test would fail if current model's schema was not passed into `sqlglot` optimization.
- Loading branch information
1 parent
5e0e3fd
commit c76651b
Showing
3 changed files
with
30 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 17 additions & 4 deletions
21
...er-dbt/dagster_dbt_tests/dbt_projects/test_dagster_metadata/models/incremental_orders.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
{{ | ||
config( | ||
materialized='incremental', | ||
unique_key='order_id', | ||
incremental_strategy='append', | ||
materialized='incremental' | ||
) | ||
}} | ||
|
||
select order_id from {{ ref('orders') }} | ||
with max_order_date as ( | ||
select | ||
max(order_date) as max_order_date | ||
from {{ this }} | ||
) | ||
|
||
select | ||
order_id, | ||
order_date | ||
from {{ ref('orders') }} | ||
|
||
{% if is_incremental() %} | ||
|
||
where order_date >= (select max_order_date from max_order_date) | ||
|
||
{% endif %} |