-
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
using {{ ref('anything') }}
in a set_sql_header
call resolves to the current model and not 'anything'
#2793
Comments
@yuzeh This is a weird one, all right. I've confirmed that this behavior occurs on other databases (Postgres) and regardless of whether you use I think what's going on here is that, in its first parse through the project, dbt captures all I admit it feels quite strange to see two different values interpolated for
I'd welcome a community contribution for this one, though I need to get to the bottom of what's going on here, and it's likely too tricky to be a good first issue. I don't think we'll prioritize an immediate fix here because the intended purpose of In the meantime, I think the near-term fix is to document that Jinja + macros (including |
The same issue appears also with other config parameters: I built a custom materialization and wanted to pass ref to another model as a parameter, but I ended with the same issue highlighted here. |
Also seeing this issue when when passing When logging what the macro is generating, I see two values:
But for some reason, the executed SQL does not use the correct reference, but instead the current node reference "dummy" value. |
I am seeing this issue when I am trying to create a temporary table using set_sql_header with a source.
|
Ran into this too, my use case is the same as @gmailMichaelSha's - creating a temp table. In my case to split a large complex query in two to avoid BigQuery's |
Any updates here? This has been broken for a long time, and remains undocumented. |
Another use case: setting a variable with the a value to use in incremental builds for BQ, as BQ doesn't prune partitions if you use a subquery to find this (there are other ways around this though, e.g. using |
Another use case: setting a variable to the result of part of a query, so that it can be referenced in multiple places. BigQuery reevaluates CTEs if they're queried more than once (I assume there's some rational behaviour for this, I guess due to parallelisation?) and so the recommended approach is to set a variable to the result and reference it instead. |
I think I've come across another bug related to this too: I'm trying to create my own custom version of _dbt_max_partitions that only looks at the last 3 months of data instead of scanning the column for all time: (all time is ~ 10gb of data), when doing:
this doesn't work because I'm using a custom I've raised this as a seperate issue with a bit more explanation: #7151 |
Another use case is setting the config value from a ref: Inside a model: -- my_model.sql
{{
config(
meta = {
'ref': ref('some_other_model').identifier
},
)
}} After compiling, the value of |
Ran into this today, except that I'm using
This renders the DECLARE statement with the incorrect schema and table name. |
I ran into the same issue and I could solved it declaring the referenced table name before the set_sql_reader: {% set target_relation = api.Relation.create(database=database, schema=schema, identifier='table_referenced') -%}
{% call set_sql_header(config) %}
select * from {{ target_relation }}
{%- endcall %}
{{ config(materialized = 'incremental') }}
select * from source('sources', 'table')
where date = latest_date |
The ability to create temporary tables during incremental executions is a really important capability that I am missing in the current behavior of set_sql_header() to be honest. I am using postgres and the difference in terms of performance with or without this capability is huge. Is there any solution to the fact that is_incremental() always returns false during the first parsing step? Thank you in advance! |
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. |
Keep alive please, worth resolving. |
Describe the bug
Here's a minimal reproducible example (running on BigQuery).
When I
dbt run
this project, I get an error whentest_tmp_2
is run saying something along the lines of "test_tmp_2 does not exist".The output SQL for
test_tmp_2
after adbt run
shows:Expected behavior
The
ref('test_tmp_1')
call in thecall set_sql_header(config)
block should resolve totest_tmp_1
.Instead it resolves to
test_tmp_2
.System information
Which database are you using dbt with?
The output of
dbt --version
:The operating system you're using:
macOS 10.15.6
The output of
python --version
:Python 3.8.1
Additional context
N/A
The text was updated successfully, but these errors were encountered: