Skip to content

Commit

Permalink
(fixes #1292) Check for relation type in is_incremental()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
drewbanin committed Feb 13, 2019
1 parent b17d706 commit 2c94e9e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
{{ return(False) }}
{% else %}
{% set relation = adapter.get_relation(this.database, this.schema, this.table) %}
{{ return(relation is not none and not flags.FULL_REFRESH) }}
{{ return(relation is not none and relation.type == 'table' and not flags.FULL_REFRESH) }}
{% endif %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@


{{ config(materialized=var('materialized'), sql_where='TRUE') }}
{{ config(materialized=var('materialized')) }}

select '{{ var("materialized") }}' as materialization

{% if var('materialized') == 'incremental' and is_incremental() %}
where 'abc' != (select max(materialization) from {{ this }})
{% endif %}

0 comments on commit 2c94e9e

Please sign in to comment.