Skip to content

Commit

Permalink
Duplicate media ad views passthroughs (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilias1111 committed Dec 10, 2024
1 parent 7801e68 commit 900c09b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
19 changes: 16 additions & 3 deletions integration_tests/.scripts/integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -69,6 +67,21 @@ 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 --select +snowplow_media_player_media_ad_views_this_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\"},
{\"sql\": \"v_tracker || app_id\", \"alias\": \"tracker_app_id_1\", \"agg\": \"min\"},
{\"sql\": \"v_collector\", \"alias\": \"tracker_app_id_2\", \"agg\": \"min\"}
]
}'" || exit 1;

eval "dbt test --target $db --select snowplow_media_player_media_ad_views_this_run" || exit 1;

echo "Snowplow media player integration tests: All tests passed"

done
done
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,39 @@ events_this_run as (
,ev.media_ad_break__break_id as ad_break_id
,ev.media_ad__ad_id as ad_id


{%- set non_agg_identifiers = [] -%}
{%- for identifier in var('snowplow__ad_views_passthroughs', []) -%}
{%- if identifier is not mapping or 'agg' not in identifier -%}
{%- do non_agg_identifiers.append(identifier) -%}
{%- endif -%}
{%- endfor -%}


{%- if var('snowplow__ad_views_passthroughs', []) -%}
{%- set passthrough_names = [] -%}
{%- set agg_identifiers = [] -%}

{%- for identifier in var('snowplow__ad_views_passthroughs', []) %}
{# Check if it is a simple column or a sql+alias #}
{%- if identifier is mapping -%}
,{{identifier['sql']}} as {{identifier['alias']}}
{%- do passthrough_names.append(identifier['alias']) -%}
{%- else -%}
,ev.{{identifier}}
{%- do passthrough_names.append(identifier) -%}
{%- endif -%}
{# Check if it is a mapping with no agg attribute #}
{%- if identifier is mapping and 'agg' not in identifier -%}
,{{identifier['sql']}} as {{identifier['alias']}}
{%- do passthrough_names.append(identifier['alias']) -%}

{# Check if it is a mapping with agg attribute #}
{%- elif identifier is mapping and 'agg' in identifier -%}
{%- do agg_identifiers.append(identifier) -%}

{# Handle simple column names #}
{%- else -%}
,ev.{{identifier}}
{%- do passthrough_names.append(identifier) -%}
{%- endif -%}
{% endfor -%}

{# Add aggregated columns after the main selection #}
{%- for agg_col in agg_identifiers %}
,{{agg_col['agg']}}({{agg_col['sql']}}) as {{agg_col['alias']}}
{% endfor -%}
{%- endif %}

Expand All @@ -81,7 +103,7 @@ events_this_run as (
,{{ snowplow_utils.get_string_agg('original_session_identifier', 'ev', is_distinct=True) }} as domain_sessionid_array

from events_this_run as ev
{{ dbt_utils.group_by(n=9+(var('snowplow__ad_views_passthroughs', [])|length)) }}
{{ dbt_utils.group_by(n=9+non_agg_identifiers|length) }}


)
Expand Down Expand Up @@ -123,6 +145,10 @@ select
{%- for col in passthrough_names %}
, p.{{col}}
{%- endfor -%}
{%- for agg_col in agg_identifiers %}
, p.{{agg_col['alias']}}
{%- endfor -%}

{%- endif %}

from prep as p

0 comments on commit 900c09b

Please sign in to comment.