-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
set_sql_header
and is_incremental
#3264
Comments
Thanks for opening this issue @yuzeh! I believe this is the same underlying issue as the one you found previously (#2793). I've got a firmer grasp on what's going on, and so I come with a few potential ideas. None is simple, but I do believe we should do something. Basically: Because This is also the same reason why the SQL header is not included in the node's It's clear that users want to leverage SQL headers for a mission beyond its original vocation. We initially envisioned With that in mind, here are the options as I see them:
The first hook is fully rendered at parse time, so it has the parse-time values for each. The second hook contains nested curlies, and because hooks are special, at execution time they are re-rendered—i.e., that nested Jinja is rendered for the first time. The results:
The claim here would be, SQL headers should be able to do the same nested-Jinja thing, giving the user the (confusing yet useful) ability to save some rendering for later.
What do you think? Which of the capabilities above would you find most compelling? |
Hey @jtcohen6 thank you for the very detailed response! As for how to proceed; I'm not entirely sure as I don't quite have a good sense of the other dbt features (for example, I make no use of hooks in my project). A couple of thoughts from an end-user's perspective:
All that said, (2) seems the most straightforward solution to my current issue. If you could -- what's the fastest way to work around my existing issue? I've been racking my head on this for a couple of hours at this point, and I see two solutions currently:
|
This is helpful to know @yuzeh! I'd say that For the a way to hack around this limitation in the meantime: Mike Ascah in dbt Slack came up with a not-pretty (but honestly pretty reasonable) answer that approximates the functionality in (1). In your model SQL, add an easily identifiable delimiter (such as {{ my_split_sql[0] }};
create table ... as (
{{ my_split_sql[1] }}
); That would involve a simple reimplementation or adaptation of the BQ incremental materialization, or the macros it calls (such as |
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 remove the stale label or comment on the issue, or it will be closed in 7 days. |
Describe the bug
set_sql_header
doesn't play nicely with theis_incremental
macro. In particular,is_incremental
seems to always evaluate to false duringdbt run
.Steps To Reproduce
Minimal reproducible dbt model:
Expected behavior
dbt run
the first time or with--full-refresh
... ✔️dbt run
subsequent times (because of the non-SQL code)... ❌System information
Which database are you using dbt with?
The output of
dbt --version
:The operating system you're using: Ubuntu (on WSL2)
The output of
python --version
:Python 3.8.5
Additional context
This is somewhat related to #2793. I had some reasonable workarounds for the other issues I ran into while putting arbitrary BigQuery SQL into
set_sql_header
(e.g. hardcoding table names rather than usingref
), but I'm not sure how to work aroundis_incremental
not working the way I expect.Additionally, the output of the compile step (e.g.
target/compiled/project/models/test__is_incremental__inside__set_sql_header.sql
) does not include the contents ofset_sql_header
... is this expected?The text was updated successfully, but these errors were encountered: