From b2989b1e6a1fccabefc15367f8dd25b8e12c48f7 Mon Sep 17 00:00:00 2001 From: Ilias Xenogiannis Date: Thu, 28 Nov 2024 18:12:21 +0200 Subject: [PATCH] Test and fix --- .../.scripts/integration_tests.sh | 17 +++++-- .../assert_media_ad_views_passthrough.sql | 45 +++++++++++++++++++ integration_tests/tests/schema.yml | 20 +++++++++ ...w_media_player_media_ad_views_this_run.sql | 4 ++ 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 integration_tests/tests/assert_media_ad_views_passthrough.sql create mode 100644 integration_tests/tests/schema.yml diff --git a/integration_tests/.scripts/integration_tests.sh b/integration_tests/.scripts/integration_tests.sh index 1add026..eea8ab0 100755 --- a/integration_tests/.scripts/integration_tests.sh +++ b/integration_tests/.scripts/integration_tests.sh @@ -45,8 +45,6 @@ for db in ${DATABASES[@]}; do eval "dbt run --target $db --vars '{snowplow__enable_youtube: false, snowplow__enable_whatwg_media: false, snowplow__enable_whatwg_video: false, snowplow__enable_media_player_v1: false}'" || exit 1; - - echo "Snowplow media player integration tests: Execute models - run 1/6" eval "dbt run --target $db --full-refresh --vars '{snowplow__allow_refresh: true}'" || exit 1; @@ -69,6 +67,19 @@ for db in ${DATABASES[@]}; do eval "dbt test --target $db" || exit 1; + echo "Snowplow media player integration tests: Testing ad views passthrough - mixed configuration" + eval "dbt run --target $db --full-refresh --vars '{ + snowplow__allow_refresh: true, + snowplow__enable_media_ad: true, + snowplow__backfill_limit_days: 999, + snowplow__ad_views_passthroughs: [ + \"v_collector\", + {\"sql\": \"v_tracker || app_id\", \"alias\": \"tracker_app_id\", \"agg\": \"max\"} + ] + }'" || exit 1; + + eval "dbt test --target $db --select test_type:singular tag:ad_views_passthrough" || exit 1; + echo "Snowplow media player integration tests: All tests passed" -done +done \ No newline at end of file diff --git a/integration_tests/tests/assert_media_ad_views_passthrough.sql b/integration_tests/tests/assert_media_ad_views_passthrough.sql new file mode 100644 index 0000000..9618551 --- /dev/null +++ b/integration_tests/tests/assert_media_ad_views_passthrough.sql @@ -0,0 +1,45 @@ +-- tests/assert_media_ad_views_passthrough.sql +with base_data as ( + select * from {{ ref('snowplow_media_player_base_events_this_run') }} + where media_ad__ad_id is not null + and media_identifier is not null +), + +expected as ( + select + {{ dbt_utils.generate_surrogate_key(['platform', 'media_identifier', 'media_ad__ad_id']) }} as media_ad_id, + -- simple passthrough + v_collector, + -- max aggregation + max(v_tracker || app_id) as tracker_app_id + from base_data + group by 1, 2 +), + +actual as ( + select + media_ad_id, + v_collector, + tracker_app_id + from {{ ref('snowplow_media_player_media_ad_views_this_run') }} +), + +comparison as ( + select + coalesce(e.media_ad_id, a.media_ad_id) as media_ad_id, + case + when e.v_collector != a.v_collector then 1 + when e.tracker_app_id != a.tracker_app_id then 1 + when e.media_ad_id is null then 1 + when a.media_ad_id is null then 1 + else 0 + end as has_mismatch + from expected e + full outer join actual a using (media_ad_id) +) + +select + 'Data mismatch found' as test_name, + sum(has_mismatch) as failures +from comparison +having sum(has_mismatch) > 0 \ No newline at end of file diff --git a/integration_tests/tests/schema.yml b/integration_tests/tests/schema.yml new file mode 100644 index 0000000..9f9b996 --- /dev/null +++ b/integration_tests/tests/schema.yml @@ -0,0 +1,20 @@ +version: 2 + +models: + - name: snowplow_media_player_media_ad_views_this_run + tests: + - assert_media_ad_views_passthrough + columns: + - name: media_ad_id + tests: + - not_null + - unique + - name: v_collector + tests: + - not_null + - name: tracker_app_id + tests: + - not_null + + config: + tags: ['this_run'] \ No newline at end of file diff --git a/models/media_ad_views/scratch/snowplow_media_player_media_ad_views_this_run.sql b/models/media_ad_views/scratch/snowplow_media_player_media_ad_views_this_run.sql index 0a12632..ae4b8ca 100644 --- a/models/media_ad_views/scratch/snowplow_media_player_media_ad_views_this_run.sql +++ b/models/media_ad_views/scratch/snowplow_media_player_media_ad_views_this_run.sql @@ -145,6 +145,10 @@ select {%- for col in passthrough_names %} , p.{{col}} {%- endfor -%} + {%- for agg_col in agg_columns %} + , p.{{agg_col['alias']}} + {%- endfor -%} + {%- endif %} from prep as p