-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#2350) Fix for changing snapshot strategy types
- Loading branch information
Showing
4 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...gration/004_simple_snapshot_test/test-snapshots-changing-strategy-tests/test_snapshot.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
{# /* | ||
Given the repro case for the snapshot build, we'd | ||
expect to see both records have color='pink' | ||
in their most recent rows. | ||
*/ #} | ||
with expected as ( | ||
select 1 as id, 'pink' as color union all | ||
select 2 as id, 'pink' as color | ||
), | ||
actual as ( | ||
select id, color | ||
from {{ ref('my_snapshot') }} | ||
where color = 'pink' | ||
and dbt_valid_to is null | ||
) | ||
select * from expected | ||
except | ||
select * from actual | ||
union all | ||
select * from actual | ||
except | ||
select * from expected |
55 changes: 55 additions & 0 deletions
55
test/integration/004_simple_snapshot_test/test-snapshots-changing-strategy/snapshot.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
{# | ||
REPRO: | ||
1. Run with check strategy | ||
2. Add a new ts column and run with check strategy | ||
3. Run with timestamp strategy on new ts column | ||
|
||
Expect: new entry is added for changed rows in (3) | ||
#} | ||
|
||
|
||
{% snapshot my_snapshot %} | ||
|
||
{#--------------- Configuration ------------ #} | ||
|
||
{{ config( | ||
target_schema=schema, | ||
unique_key='id' | ||
) }} | ||
|
||
{% if var('strategy') == 'timestamp' %} | ||
{{ config(strategy='timestamp', updated_at='updated_at') }} | ||
{% else %} | ||
{{ config(strategy='check', check_cols=['color']) }} | ||
{% endif %} | ||
|
||
{#--------------- Test setup ------------ #} | ||
|
||
{% if var('step') == 1 %} | ||
|
||
select 1 as id, 'blue' as color | ||
union all | ||
select 2 as id, 'red' as color | ||
|
||
{% elif var('step') == 2 %} | ||
|
||
-- change id=1 color from blue to green | ||
-- id=2 is unchanged when using the check strategy | ||
select 1 as id, 'green' as color, '2020-01-01'::date as updated_at | ||
union all | ||
select 2 as id, 'red' as color, '2020-01-01'::date as updated_at | ||
|
||
{% elif var('step') == 3 %} | ||
|
||
-- bump timestamp for both records. Expect that after this runs | ||
-- using the timestamp strategy, both ids should have the color | ||
-- 'pink' in the database. This should be in the future b/c we're | ||
-- going to compare to the check timestamp, which will be _now_ | ||
select 1 as id, 'pink' as color, (now() + interval '1 day')::date as updated_at | ||
union all | ||
select 2 as id, 'pink' as color, (now() + interval '1 day')::date as updated_at | ||
|
||
{% endif %} | ||
|
||
{% endsnapshot %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters