-
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.
(#1884) Fix for non-atomic snapshot staging tables
- Loading branch information
Showing
6 changed files
with
149 additions
and
55 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
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
44 changes: 44 additions & 0 deletions
44
test/integration/004_simple_snapshot_test/models-slow/gen.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,44 @@ | ||
|
||
{{ config(materialized='ephemeral') }} | ||
|
||
|
||
/* | ||
Generates 50 rows that "appear" to update every | ||
second to a query-er. | ||
1 2020-04-21 20:44:00-04 0 | ||
2 2020-04-21 20:43:59-04 59 | ||
3 2020-04-21 20:43:58-04 58 | ||
4 2020-04-21 20:43:57-04 57 | ||
.... 1 second later .... | ||
1 2020-04-21 20:44:01-04 1 | ||
2 2020-04-21 20:44:00-04 0 | ||
3 2020-04-21 20:43:59-04 59 | ||
4 2020-04-21 20:43:58-04 58 | ||
This view uses pg_sleep(2) to make queries against | ||
the view take a non-trivial amount of time | ||
Use statement_timestamp() as it changes during a transactions. | ||
If we used now() or current_time or similar, then the timestamp | ||
of the start of the transaction would be returned instead. | ||
*/ | ||
|
||
with gen as ( | ||
|
||
select | ||
id, | ||
date_trunc('second', statement_timestamp()) - (interval '1 second' * id) as updated_at | ||
|
||
from generate_series(1, 10) id | ||
|
||
) | ||
|
||
select | ||
id, | ||
updated_at, | ||
extract(seconds from updated_at)::int as seconds | ||
|
||
from gen, pg_sleep(2) |
23 changes: 23 additions & 0 deletions
23
test/integration/004_simple_snapshot_test/test-snapshots-slow-tests/test_timestamps.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,23 @@ | ||
|
||
/* | ||
Assert that the dbt_valid_from of the latest record | ||
is equal to the dbt_valid_to of the previous record | ||
*/ | ||
|
||
with snapshot as ( | ||
|
||
select * from {{ ref('my_slow_snapshot') }} | ||
|
||
) | ||
|
||
select | ||
snap1.id, | ||
snap1.dbt_valid_from as new_valid_from, | ||
snap2.dbt_valid_from as old_valid_from, | ||
snap2.dbt_valid_to as old_valid_to | ||
|
||
from snapshot as snap1 | ||
join snapshot as snap2 on snap1.id = snap2.id | ||
where snap1.dbt_valid_to is null | ||
and snap2.dbt_valid_to is not null | ||
and snap1.dbt_valid_from != snap2.dbt_valid_to |
21 changes: 21 additions & 0 deletions
21
test/integration/004_simple_snapshot_test/test-snapshots-slow/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,21 @@ | ||
|
||
{% snapshot my_slow_snapshot %} | ||
|
||
{{ | ||
config( | ||
target_database=var('target_database', database), | ||
target_schema=schema, | ||
unique_key='id', | ||
strategy='timestamp', | ||
updated_at='updated_at' | ||
) | ||
}} | ||
|
||
select | ||
id, | ||
updated_at, | ||
seconds | ||
|
||
from {{ ref('gen') }} | ||
|
||
{% 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