You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks @clrcrl - can you DM me the logs? I can check it out
clrcrl
changed the title
is_incremental() evaluates to True when switching from a view to a tableis_incremental() evaluates to True when switching from a view to an incremental model
Feb 13, 2019
Ok - this is just happening because is_incremental() checks that the relation exists, but does not confirm that the type of the relation is a table.
dbt is smart enough to avoid inserting into the view (it drops the view first), but then is_incremental() does indeed evaluate to true and the incremental filter gets included in the model sql. The problem is that is_incremental() is evaluated before dbt gets to the materialization, so is_incremental() returns true in response to the existing view, which is then dropped immediately in the materialization.
The fix here is probably to make is_incremental() check that the target relation is of type table. That might look like:
{% macro is_incremental() %}
{#-- do not run introspective queries in parsing #}
{% if not execute %}
{{ return(False) }}
{% else %}
{% set relation = adapter.get_relation(this.database, this.schema, this.table) %}
{{ return(relation is not none and relation.type == 'table' and not flags.FULL_REFRESH) }}
{% endif %}
{% endmacro %}
If the target relation is a non-table (probably a view) then dbt
should return False from the is_incremental() macro. The
materialization will drop this relation before running the model
code as a `create table as` statement, so the incremental filter
would likely be invalid.
Steps to reproduce
models/my_model.sql
(this SQL is on Redshift):dbt run
:dbt run
to get this:dbt run
again... and it works...:I have the logs for this as well (I can't attach text files here, and I'm not keen to paste 680 lines of output in this issue).
System info
The text was updated successfully, but these errors were encountered: