Skip to content

Commit

Permalink
Use regular dbt 'is_incremental' and 'this', when testing incremental…
Browse files Browse the repository at this point in the history
… models
  • Loading branch information
psousa50 committed Jun 20, 2023
1 parent fe70042 commit 6c55e0b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions integration-tests/models/incremental_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

select c from {{ dbt_unit_testing.ref('model_for_incremental') }}

{% if dbt_unit_testing.is_incremental() %}
where c > (select max(c) from {{ dbt_unit_testing.this() }})
{% if is_incremental() %}
where c > (select max(c) from {{ this }})
{% endif %}
2 changes: 1 addition & 1 deletion integration-tests/tests/unit/incremental_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

UNION ALL

{% call dbt_unit_testing.test('incremental_model', 'incremental test', options={"is_incremental": "True"}) %}
{% call dbt_unit_testing.test('incremental_model', 'incremental test', options={"run_as_incremental": "True"}) %}
{% call dbt_unit_testing.mock_ref ('model_for_incremental') %}
select 10 as c
UNION ALL
Expand Down
9 changes: 9 additions & 0 deletions macros/sql_builders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
{{ return(model_complete_sql) }}
{% endmacro %}

{% macro replace_this_with_model_name(rendered_node) %}
{% set this_name = this | string %}
{% set model_name = dbt_unit_testing.get_test_context('model_name') %}
{% if model_name is defined %}
{{ return (rendered_node.replace(this_name, model_name)) }}
{% endif %}
{{ return (rendered_node) }}
{% endmacro %}

{% macro cte_name(node) %}
{% if node.resource_type in ('source') %}
{{ return (dbt_unit_testing.source_cte_name(node.source_name, node.name)) }}
Expand Down

0 comments on commit 6c55e0b

Please sign in to comment.