-
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
Difference between behaviour of already_exists
and get_relation
#1683
Comments
Hey @sumitkumar1209 - I can see in your materialization that you're running a setup step like:
When this happens, dbt does two things:
dbt uses a cache to help reduce the number of In this case, I think your call to drop the In dbt, we account for this by re-caching the new relation after the materialization finishes running. You can see that happen here: https://github.com/fishtown-analytics/dbt/blob/dev/0.14.1/core/dbt/node_runners.py#L351 This happens after the materialization completes, so introspective queries that use the cache in post-hooks will use the cache while it's in an incorrect state. One option here may be to change the calls from For our part, we should probably expose some ability to modify the cache from within a materialization. That might look like a call to {% call statement('main') %}
{% set processed_table_sql -%}
SELECT
*
FROM
{{ tmp_processed_relation }}
{%- endset %}
-- Prepare temp table from scd logic
{{ dbt.create_table_as(False, target_relation, processed_table_sql) }}
{% endcall %}
-- this is the thing we may want to add to dbt
{{ adapter.cache.add(target_relation) }} By doing this, you'll inform dbt's cache that you've created a new relation. Conceivably, we could bake this right into the Thanks for writing this up! it's an interesting issue for sure! Let me know what you think |
Hi @drewbanin, Keeping this code in context https://github.com/fishtown-analytics/dbt/blob/dev/0.14.1/core/dbt/node_runners.py#L351, Is adapter mentioned in the above line same as what we use in macro? In other words can I directly use Your suggestions are awesome. I will prefer the cache to be updated in |
yep, totally agree. Unfortunately, the |
…-to-materializations Expose the cache in dbt's rendering contexts (#1683)
Describe the bug
I am upgrading DBT from 0.12.2 to 0.14
Based on this link,
already_exists
is deprecated and will be removed in favour ofget_relation
.But I am seeing different behaviour of
get_relation
.I am using this macro, and this runs at the start and end of table creation.
After table is created successfully in run and when I am running
get_relation
in a post-hook by above macro, it is giving menone
value.And when I run this in pre-hook, DBT is executing the else part even if the table does not exist and it throws an error relation does not exist in SELECT query.
Steps To Reproduce
Models I am seeing this are custom materialized, which is based on
table
materialization. This problem is not happening intable
materialization.here is the code for the same.
Create a model using the above materialization and run a macro mentioned above in the post as post-hook. If it gives
-1
in audit table or in log that meansget_relation
is not working.Expected behavior
This used to work previously with 0.12.2 giving correct presence of table in database.
get_relation
is expected to behave similar toalready_exists
as it is the replacement.Screenshots and log output
This is my post hook in dbt_project.yml file
You can see in the first line 10 rows were inserted, but in INSERT INTO query where
-1
comes from the macro mentioned above I am getting -1 which means table does not exist.System information
Which database are you using dbt with?
The output of
dbt --version
:The operating system you're using:
macOS Mojave 10.14.5
The output of
python --version
:Python 3.7.0
The text was updated successfully, but these errors were encountered: