I am using the incremental_strategy=‘insert’ in one of my models. My adapter is Snowflake. The first time that I run the model everything works fine. But the second time an error is raised because a temp view that i created the same time is being delete the second time. The problem is that the adapter changes the view to a table and of course it fails.
Error in snowflake is “SQL compilation error: Object found is of type ‘VIEW’, not specified type ‘TABLE’.”
so I am trying to follow the call sequence to the culprit. which is as follows:
{% set tmp_relation_type = dbt_snowflake_get_tmp_relation_type(incremental_strategy, unique_key, 'sql') %}
Then it goes into dbt file dbt/include/global_project/macros/adapters/relation.sql
About the last question, when you use adapter.dispatch you have to look to the string you passed as the first argument. In this case, you have ‘make_temp_relation’.
What adapter.dispatch does is to search for macro named <your_adapter>__make_temp_relation, in your case snowflake__make_temp_relation
If this macro does not exist it searched for default__make_temp_relation, that is defined here
yes, it helped. I end up creating a new macro that dispatch to a Snowflake macro get_drop_view_sql and I replace the call to that macro with the new one.
I will put here the solution if somebody have the same problem. Here is the new macro:
{% macro drop_view_relation_if_exists(relation) %}
{% if relation is not none %}
{{ return(adapter.dispatch(‘get_drop_view_sql’)(relation)) }}
{% endif %}
{% endmacro %}
And this is what I changed in the current code to call the new macro:
From: {% do drop_relation_if_exists(tmp_relation) %}
To: {% do dc.drop_view_relation_if_exists(tmp_relation) %}