Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate media ad views passthroughs #84

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_columns = [] -%}
{%- for identifier in var('snowplow__ad_views_passthroughs', []) -%}
{%- if identifier is not mapping or 'agg' not in identifier -%}
{%- do non_agg_columns.append(identifier) -%}
{%- endif -%}
{%- endfor -%}


{%- if var('snowplow__ad_views_passthroughs', []) -%}
{%- set passthrough_names = [] -%}
{%- set agg_columns = [] -%}
ilias1111 marked this conversation as resolved.
Show resolved Hide resolved

{%- 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_columns.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_columns %}
,{{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_columns|length) }}


)
Expand Down Expand Up @@ -123,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
Loading