-
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
[Bug] Inconsistent behaviour of 'defer' with the 'dbt compile' command #9991
Comments
Thanks for reaching out @siljamardla -- indeed state selection can be tricky to think about! I don't think this is a bug. Let me explain why. Project setupSuppose you have the following simple models in your dbt project and you start with a set of production artifacts: Project files
-- model_a: {{ this }}
select 1 as id
-- model_b: {{ this }}
select 2 as id
-- model_c: {{ this }}
-- depends on:
-- model_a: {{ ref("model_a") }}
-- model_b: {{ ref("model_b") }}
select 1 as id Production artifacts`profiles.yml duckdb:
target: dev
outputs:
prod:
type: duckdb
path: 'db.db'
schema: prod
dev:
type: duckdb
path: 'db.db'
schema: feature_456 Build production and examine the database table names: dbt build --target prod
dbt --quiet ls --output json --output-keys database schema alias --target prod | jq . Save the production state: rm -rf prod-run-artifacts
mv target prod-run-artifacts 💡 Insight 1When you do a
👉 Not specifying 💡 Insight 2When you add
👉 Example 1These are all equivalent:
And they all compile to this result ( -- model_c: "db"."feature_456"."model_c"
-- depends on:
-- model_a: "db"."feature_456"."model_a"
-- model_b: "db"."feature_456"."model_b"
select 1 as id Examples 2 and 3Either of the examples below will compile with different output than above since some nodes are not selected. Example 1dbt compile --target dev --defer --favor-state --state prod-run-artifacts --select model_c model_b is the same as: dbt compile --target dev --defer --favor-state --state prod-run-artifacts --select model_c model_b model_a --exclude model_a is the same as: dbt compile --target dev --defer --favor-state --state prod-run-artifacts --exclude model_a Compiled output: -- model_c: "db"."feature_456"."model_c"
-- depends on:
-- model_a: "db"."prod"."model_a"
-- model_b: "db"."feature_456"."model_b"
select 1 as id Example 2dbt compile --target dev --defer --favor-state --state prod-run-artifacts --select model_c Compiled output: -- model_c: "db"."feature_456"."model_c"
-- depends on:
-- model_a: "db"."prod"."model_a"
-- model_b: "db"."prod"."model_b"
select 1 as id Notes
SummaryI'm going to close this a not a bug, but please let me know I've missed something important and we can re-consider. 🙏 |
@dbeatty10 I've actually come back to this issue because I was trying to use defer for testing. I guess I'm hitting the same concept here. I tried something like select order_key
from dev_schema.my_model
where order_key is null Is there a way to compile the test to run on live? If not, should I create a feature request? What could be a good way to achieve this functionality? Edit: tests:
- dbt_expectations.expect_table_aggregation_to_equal_other_table:
expression: count(*)
compare_model: source("source_name","source_table_for_my_model")
compare_expression: count(*)
group_by: [created_date]
compare_group_by: [created_date]
row_condition:
created_date = (SELECT max(created_date) from {{ref('my_other_model')}})
compare_row_condition: >
created_date = (SELECT max(created_date) from {{ref('my_other_model')}}) I was thinking that maybe this reference to another table will compile for the live schema because it's not included in the |
Is this a new bug in dbt-core?
Current Behavior
Defer does not work with simple compile. This will compile to SQL that uses the dev schema tables:
However, if you need to compile production SQL for a specific table, this will work:
Expected Behavior
Any dbt command executed with
--defer
should have the same behaviour of combining live data with data that exist in the dev environment.Steps To Reproduce
dbt compile --defer --state target/live
(this is where I store the latest live manifest)dbt compile --defer --state target/live
againdbt compile --defer --state target/live --select my_model_name > target/tmp_my_model_name.sql
Relevant log output
No response
Environment
Which database adapter are you using with dbt?
spark
Additional Context
dbt-labs/docs.getdbt.com#5162
The text was updated successfully, but these errors were encountered: