Skip to content

Commit

Permalink
Temp diff check
Browse files Browse the repository at this point in the history
  • Loading branch information
agnessnowplow committed Oct 28, 2024
1 parent a32dd99 commit 0e45735
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 36 deletions.
41 changes: 5 additions & 36 deletions integration_tests/.scripts/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,14 @@ for db in ${DATABASES[@]}; do

echo "Snowplow unified integration tests: Seeding data"
eval "dbt seed --full-refresh --target $db" || exit 1;

echo "Snowplow unified integration tests: Try run without data"
eval "dbt run --full-refresh --vars '{snowplow__allow_refresh: true, snowplow__backfill_limit_days: 1, snowplow__enable_cwv: false, snowplow__start_date: 2010-01-01}' --target $db" || exit 1;

echo "Snowplow unified integration tests: Try run without data for browser_context_2 only enabled"
eval "dbt run --full-refresh --vars '{snowplow__allow_refresh: true, snowplow__enable_browser_context: false, snowplow__enable_browser_context_2:true, snowplow__backfill_limit_days: 1, snowplow__enable_cwv: false, snowplow__start_date: 2010-01-01}' --target $db" || exit 1;

echo "Snowplow unified integration tests: Try run without data for browser_context_2 and browser_context enabled"
eval "dbt run --full-refresh --vars '{snowplow__allow_refresh: true, snowplow__enable_browser_context:true, snowplow__enable_browser_context_2:true, snowplow__backfill_limit_days: 1, snowplow__enable_cwv: false, snowplow__start_date: 2010-01-01}' --target $db" || exit 1;

echo "Snowplow unified integration tests: Conversions"
eval "dbt run --full-refresh --select +snowplow_unified_conversions snowplow_unified_integration_tests.source --vars '{snowplow__allow_refresh: true, snowplow__backfill_limit_days: 220, snowplow__enable_cwv: false, snowplow__enable_conversions: true}' --target $db" || exit 1;

echo "Snowplow unified integration tests: App errors module"
eval "dbt run --full-refresh --select +snowplow_unified_app_errors snowplow_unified_integration_tests.source --vars '{snowplow__allow_refresh: true, snowplow__backfill_limit_days: 220, snowplow__enable_cwv: false, snowplow__enable_app_errors: true}' --target $db" || exit 1;

echo "Snowplow unified integration tests: Late enabled contexts"
eval "dbt run --full-refresh --select +test_late_enabled_contexts snowplow_unified_integration_tests.source --vars '{snowplow__allow_refresh: true, snowplow__backfill_limit_days: 220, snowplow__enable_cwv: false, snowplow__enable_mobile_context: false, snowplow__enable_geolocation_context: false, snowplow__enable_application_context: false, snowplow__enable_screen_context: false, snowplow__enable_app_errors: false, snowplow__enable_deep_link_context: false, snowplow__enable_cwv: false, snowplow__enable_iab: false, snowplow__enable_ua: false, snowplow__enable_browser_context: false, snowplow__enable_browser_context_2: false, snowplow__enable_consent: false}' --target $db" || exit 1;

eval "dbt run --select +test_late_enabled_contexts run --vars '{snowplow__allow_refresh: true, snowplow__backfill_limit_days: 250, snowplow__enable_cwv: false}' --target $db"
echo "Snowplow unified integration tests: Late enabled contexts test passed"

echo "Snowplow unified integration tests: Execute models (all contexts except for cwv) - run 1/4"
eval "dbt run --full-refresh --vars '{snowplow__allow_refresh: true, snowplow__backfill_limit_days: 243, snowplow__enable_cwv: false}' --target $db" || exit 1;

for i in {2..4}
do
echo "Snowplow unified integration tests: Execute models (all contexts except for cwv) - run $i/4"
eval "dbt run --vars '{snowplow__enable_cwv: false}' --target $db" || exit 1;
done

echo "Snowplow unified integration tests: Test models"

eval "dbt test --exclude snowplow_unified_web_vital_measurements snowplow_unified_web_vital_measurements_actual snowplow_unified_web_vital_events_this_run snowplow_unified_views_mobile_screen_engagement_actual test_name:not_null --store-failures --target $db" || exit 1;

echo "Snowplow unified integration tests: All non-CWV tests passed"

echo "Snowplow unified integration tests - Core Web Vitals: Execute models"
eval "dbt run --select +snowplow_unified_web_vital_measurements_actual snowplow_unified_web_vital_measurements_expected_stg source --full-refresh --vars '{snowplow__allow_refresh: true, snowplow__start_date: '2023-03-01', snowplow__backfill_limit_days: 50, snowplow__cwv_days_to_measure: 999, snowplow__enable_mobile: false, snowplow__enable_mobile_context: false, snowplow__enable_geolocation_context: false, snowplow__enable_application_context: false, snowplow__enable_screen_context: false, snowplow__enable_app_errors: false, snowplow__enable_deep_link_context: false, snowplow__enable_ua: false, snowplow__enable_browser_context: false, snowplow__enable_browser_context_2: false, snowplow__enable_consent: false}' --target $db" || exit 1;

echo "Debugging help:"

eval "dbt run-operation log_equality_error --args '{"table_to_check": "web_vital_measurements"}' --target $db" || exit 1;

eval "dbt test --select snowplow_unified_web_vital_measurements_actual --store-failures --target $db" || exit 1;

echo "Snowplow unified integration tests: Execute web (all web contexts except for cwv)"
Expand Down
87 changes: 87 additions & 0 deletions integration_tests/macros/log_equality_error.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{#
Copyright (c) 2021-present Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Snowplow Personal and Academic License Version 1.0,
and you may not use this file except in compliance with the Snowplow Personal and Academic License Version 1.0.
You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 at https://docs.snowplow.io/personal-and-academic-license-1.0/
#}

/* example how to use it:
echo "Debugging help:"
eval "dbt run-operation log_equality_error --args '{"table_to_check": "web_vital_measurements"}' --target $db" || exit 1;
*/

{% macro log_equality_error(table_to_check) %}

{% if target.type == "redshift" %}
{% set diff_query %}

{% if table_to_check == "web_vital_measurements" %}

with a as (
select * from {{ ref('snowplow_unified_web_vital_measurements_actual') }}
),

b as (
select * from {{ ref('snowplow_unified_web_vital_measurements_expected_stg') }}
),

a_minus_b as (

select "compound_key", "measurement_type", "page_url", "device_class", "geo_country", "country", "time_period", "view_count", round(cast("lcp_75p" as numeric(28,6)),3) as "lcp_75p", round(cast("fid_75p" as numeric(28,6)),3) as "fid_75p", round(cast("cls_75p" as numeric(28,6)),3) as "cls_75p", round(cast("ttfb_75p" as numeric(28,6)),3) as "ttfb_75p", round(cast("inp_75p" as numeric(28,6)),3) as "inp_75p", "lcp_result", "fid_result", "cls_result", "ttfb_result", "inp_result", "passed" from a
except
select "compound_key", "measurement_type", "page_url", "device_class", "geo_country", "country", "time_period", "view_count", round(cast("lcp_75p" as numeric(28,6)),3) as "lcp_75p", round(cast("fid_75p" as numeric(28,6)),3) as "fid_75p", round(cast("cls_75p" as numeric(28,6)),3) as "cls_75p", round(cast("ttfb_75p" as numeric(28,6)),3) as "ttfb_75p", round(cast("inp_75p" as numeric(28,6)),3) as "inp_75p", "lcp_result", "fid_result", "cls_result", "ttfb_result", "inp_result", "passed" from b

),

b_minus_a as (

select "compound_key", "measurement_type", "page_url", "device_class", "geo_country", "country", "time_period", "view_count", round(cast("lcp_75p" as numeric(28,6)),3) as "lcp_75p", round(cast("fid_75p" as numeric(28,6)),3) as "fid_75p", round(cast("cls_75p" as numeric(28,6)),3) as "cls_75p", round(cast("ttfb_75p" as numeric(28,6)),3) as "ttfb_75p", round(cast("inp_75p" as numeric(28,6)),3) as "inp_75p", "lcp_result", "fid_result", "cls_result", "ttfb_result", "inp_result", "passed" from b
except
select "compound_key", "measurement_type", "page_url", "device_class", "geo_country", "country", "time_period", "view_count", round(cast("lcp_75p" as numeric(28,6)),3) as "lcp_75p", round(cast("fid_75p" as numeric(28,6)),3) as "fid_75p", round(cast("cls_75p" as numeric(28,6)),3) as "cls_75p", round(cast("ttfb_75p" as numeric(28,6)),3) as "ttfb_75p", round(cast("inp_75p" as numeric(28,6)),3) as "inp_75p", "lcp_result", "fid_result", "cls_result", "ttfb_result", "inp_result", "passed" from a

),

unioned as (

select 'a_minus_b' as which_diff, a_minus_b.* from a_minus_b
union all
select 'b_minus_a' as which_diff, b_minus_a.* from b_minus_a

)

select * from unioned

{% else %}

{{ exceptions.raise_compiler_error("Not a valid table to check.") }}

{% endif %}

{% endset %}

{% set result = run_query(diff_query) %}


{% if execute %}
{% for row in result %}
{% set row_dict = dict(zip(row.keys(), row.values())) %}
{% for key, value in row_dict.items() %}
{% do log(key ~ ': ' ~ value, info=True) %}
{% endfor %}
{% do log('---', info=True) %}
{% endfor %}

{% endif %}

{% endif %}

{% endmacro %}







0 comments on commit 0e45735

Please sign in to comment.