-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support merge_update_columns logic for unit_tests #10115
Comments
@rburke45 Thanks for opening the issue (and for trying out dbt unit testing)! In my opinion, this is a fair and reasonable limitation to unit tests and the I believe that an important principle of dbt is the separation of "transformation logic" and "materialization logic." As a general rule, dbt models should apply all transformation logic within their While that makes it more ergonomic to apply this trickier logic, it also makes it more difficult to preview or test the exact returned dataset before it's applied. Effectively, you can test this already in dbt, with a mocked (seed) input, a full model build, and an Here's another way of accomplishing the same result — "on incremental runs, update {{
config(
materialized='incremental',
unique_key='col1',
)
}}
select
{{ 'old.col1' if is_incremental() else 'new.col1' }},
new.col2,
{{ 'old.col3' if is_incremental() else 'new.col3' }},
from
{{ref('table')}} as new
-- this filter will only be applied on an incremental run
{% if is_incremental() %}
left join {{ this }} as old
on new.col1 = old.col1
where new.col2 > (select max(col2) from {{ this }})
{% endif %} This SQL is trickier to read, but I do believe it's simpler to test, and more explicit as to what's happening: on incremental runs, |
@MichelleArk has alerted me to the fact that this issue is quite similar to another one we'd opened: This is blocked on introducing a different strategy for unit tests, where all input fixtures + expected + actual are materialized in the data warehouse: |
This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days. |
Is this a new bug in dbt-core?
Current Behavior
When a model with set
merge_update_columns
is unit tested all fields are updated, not just those listed inmerge_update_columns
.Expected Behavior
When a model with set
merge_update_columns
is unit tested only the fields listed inmerge_update_columns
should be updated.Steps To Reproduce
Minimal example:
table.sql
update.sql
unit_test.yml
Running this unit test gives the log output below. Calling
dbt run
to replicate the same data produces the expected behavior.Relevant log output
Environment
Which database adapter are you using with dbt?
No response
Additional Context
I'm still relatively new to DBT, so please let me know if there's additional information I can provide.
The text was updated successfully, but these errors were encountered: