dbt-labs / dbt-core

dbt enables data analysts and engineers to transform their data using the same practices that software engineers use to build applications.
https://getdbt.com
Apache License 2.0
9.62k stars 1.59k forks source link

[CT-3129] Ability to test the incremental behavior of models after merge/insert/append/etc has occurred #8664

Open gshank opened 12 months ago

gshank commented 12 months ago

Description

Ability to test the incremental behavior of models using an incremental strategy that requires partitioning (insert_overwrite or delete+insert). See #8422.

Screenshot 2024-02-15 at 3 15 47 PM

If I have an incremental model that uses a strategy that uses "partitioning":

{{
  config(
    materialized='incremental',
    unique_key='date_day',
    incremental_strategy='insert_overwrite',
    ...
  )
}}

select
    date_trunc('day', event_at) as date_day,
    count(distinct user_id) as daily_active_users

from {{ ref('events') }} 

{% if is_incremental() %}

  -- this filter will only be applied on an incremental run
  -- (uses >= to include records arriving later on the same day as the last run of this model)
  where date_day >= (select max(date_day) from {{ this }})

{% endif %}

group by 1

I should be able to add a unit test to this model and have it work as expected.


unit_tests:
  - name: my_favorite_unit_test
    model: my_incremental_model
    given:
      - input: ref('events')
        format: csv
        fixture: my_events_input_fixture
      - input: this
        format: csv
        fixture: my_incremental_model_this_fixture
    expect:
      format: csv
      fixture: my_incremental_model_output_fixture
    overrides: 
      macros:
        is_incremental: true 

Acceptance Criteria

Unit testing of incremental models with insert_overwrite or delete+insert strategy.

Impact to Other Teams

None

Will backports be required?

No

Context

ChenyuLInx commented 4 months ago

blocked on #8499

paulbakkerbloom commented 2 weeks ago

Hi @graciegoheen @gshank. I see this issue is blocked. Was wondering if there's any development going on to make this happen and if so, if you have any (super broad) timelines? Or has this been deprioritised for the moment? Thanks in advance!

rangelrey commented 1 week ago

I believe this feature is a must for proper testing. Bringing analytics much closer to Soft. Engineering. I woud like to ask if this will come soon. Thanks for the effort!