-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BigQuery support to snowplow_incremental (Close #7)
- Loading branch information
1 parent
5c3574c
commit 5d9941b
Showing
14 changed files
with
442 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
# Expected input: | ||
# -d (database) target database for dbt | ||
# -s (seed) boolean of whether to seed test data. Default true. | ||
|
||
SEED_DATA=true | ||
|
||
while getopts 'd:s:' opt | ||
do | ||
case $opt in | ||
d) DATABASE=$OPTARG ;; | ||
s) SEED_DATA=$OPTARG ;; | ||
esac | ||
done | ||
|
||
|
||
if [ "$SEED_DATA" = true ]; then | ||
|
||
echo "Snowplow-utils integration tests: Seeding data" | ||
|
||
eval "dbt seed --target $DATABASE --full-refresh" || exit 1; | ||
|
||
fi | ||
|
||
echo "Test materializations: Refresh models" | ||
|
||
eval "dbt run --models materializations --target $DATABASE --full-refresh " || exit 1; | ||
|
||
echo "Test materializations: Execute models" | ||
|
||
eval "dbt run --models materializations --target $DATABASE" || exit 1; | ||
|
||
echo "Test materializations: Test models" | ||
|
||
eval "dbt test --models materializations --target $DATABASE" || exit 1; | ||
|
||
echo "Test materializations: All tests passed" |
8 changes: 8 additions & 0 deletions
8
integration_tests/data/materializations/bigquery/data_snowplow_incremental_expected.csv
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,8 @@ | ||
id,start_tstamp | ||
1,2021-01-01 00:00:00 | ||
1,2021-03-05 00:00:00 | ||
2,2021-03-02 00:00:00 | ||
2,2021-03-02 00:00:00 | ||
3,2021-03-07 00:00:00 | ||
4,2021-03-04 00:00:00 | ||
5,2021-03-08 00:00:00 |
9 changes: 9 additions & 0 deletions
9
...data/materializations/bigquery/data_snowplow_incremental_w_lookback_disabled_expected.csv
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,9 @@ | ||
id,start_tstamp | ||
1,2021-01-01 00:00:00 | ||
1,2021-03-05 00:00:00 | ||
2,2021-03-01 00:00:00 | ||
2,2021-03-02 00:00:00 | ||
3,2021-03-07 00:00:00 | ||
3,2021-03-07 00:00:00 | ||
4,2021-03-04 00:00:00 | ||
5,2021-03-08 00:00:00 |
10 changes: 10 additions & 0 deletions
10
integration_tests/data/materializations/data_snowplow_incremental.csv
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,10 @@ | ||
run,id,start_tstamp | ||
1,1,2021-01-01 00:00:00 | ||
1,2,2021-03-01 00:00:00 | ||
1,2,2021-03-03 00:00:00 | ||
1,3,2021-03-03 00:00:00 | ||
1,4,2021-03-04 00:00:00 | ||
2,1,2021-03-05 00:00:00 | ||
2,2,2021-03-02 00:00:00 | ||
2,3,2021-03-07 00:00:00 | ||
2,5,2021-03-08 00:00:00 |
7 changes: 7 additions & 0 deletions
7
integration_tests/data/materializations/redshift/data_snowplow_incremental_expected.csv
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,7 @@ | ||
id,start_tstamp | ||
1,2021-01-01 00:00:00 | ||
4,2021-03-04 00:00:00 | ||
5,2021-03-08 00:00:00 | ||
1,2021-03-05 00:00:00 | ||
2,2021-03-02 00:00:00 | ||
3,2021-03-07 00:00:00 |
8 changes: 8 additions & 0 deletions
8
...data/materializations/redshift/data_snowplow_incremental_w_lookback_disabled_expected.csv
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,8 @@ | ||
id,start_tstamp | ||
2,2021-03-01 00:00:00 | ||
3,2021-03-07 00:00:00 | ||
2,2021-03-02 00:00:00 | ||
1,2021-01-01 00:00:00 | ||
4,2021-03-04 00:00:00 | ||
1,2021-03-05 00:00:00 | ||
5,2021-03-08 00:00:00 |
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
12 changes: 12 additions & 0 deletions
12
integration_tests/models/materializations/materializations.yml
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,12 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: test_snowplow_incremental | ||
tests: | ||
- dbt_utils.equality: | ||
compare_model: ref('data_snowplow_incremental_expected') | ||
- name: test_snowplow_incremental_w_lookback_disabled | ||
tests: | ||
- dbt_utils.equality: | ||
compare_model: ref('data_snowplow_incremental_w_lookback_disabled_expected') | ||
|
43 changes: 43 additions & 0 deletions
43
integration_tests/models/materializations/test_snowplow_incremental.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,43 @@ | ||
{# Tests both RS (delete/insert) and BQ (merge) snowplow_incremental materialization | ||
upsert_date_key: RS only. Key used to limit the table scan | ||
partition_by: BQ only. Key used to limit table scan | ||
TODO: Add tests that change the granularity of the partition #} | ||
|
||
{{ | ||
config( | ||
materialized='snowplow_incremental', | ||
unique_key='id', | ||
upsert_date_key='start_tstamp', | ||
partition_by = { | ||
"field": "start_tstamp", | ||
"data_type": "timestamp", | ||
"granularity": "day" | ||
}, | ||
) | ||
}} | ||
|
||
with data as ( | ||
select * from {{ ref('data_snowplow_incremental') }} | ||
) | ||
|
||
{% if snowplow_utils.snowplow_is_incremental() %} | ||
|
||
select | ||
id, | ||
start_tstamp | ||
|
||
from data | ||
where run = 2 | ||
|
||
{% else %} | ||
|
||
select | ||
id, | ||
start_tstamp | ||
|
||
from data | ||
where run = 1 | ||
|
||
{% endif %} | ||
|
||
|
43 changes: 43 additions & 0 deletions
43
integration_tests/models/materializations/test_snowplow_incremental_w_lookback_disabled.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,43 @@ | ||
{# Tests both RS (delete/insert) and BQ (merge) snowplow_incremental materialization with lookback disabled. | ||
upsert_date_key: RS only. Key used to limit the table scan | ||
partition_by: BQ only. Key used to limit table scan #} | ||
|
||
{{ | ||
config( | ||
materialized='snowplow_incremental', | ||
unique_key='id', | ||
upsert_date_key='start_tstamp', | ||
disable_upsert_lookback=true, | ||
partition_by = { | ||
"field": "start_tstamp", | ||
"data_type": "timestamp", | ||
"granularity": "day" | ||
}, | ||
) | ||
}} | ||
|
||
with data as ( | ||
select * from {{ ref('data_snowplow_incremental') }} | ||
) | ||
|
||
{% if snowplow_utils.snowplow_is_incremental() %} | ||
|
||
select | ||
id, | ||
start_tstamp | ||
|
||
from data | ||
where run = 2 | ||
|
||
{% else %} | ||
|
||
select | ||
id, | ||
start_tstamp | ||
|
||
from data | ||
where run = 1 | ||
|
||
{% endif %} | ||
|
||
|
Oops, something went wrong.