Skip to content

Commit

Permalink
Simplify base events this run (close #60)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgewoodhead committed Nov 29, 2023
1 parent bcd6e3a commit 3a68e11
Show file tree
Hide file tree
Showing 31 changed files with 608 additions and 1,335 deletions.
11 changes: 10 additions & 1 deletion integration_tests/.scripts/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,20 @@ for db in ${DATABASES[@]}; do
echo "Snowplow media player integration tests (v1 only): Execute models - run 1/6"

eval "dbt run --target $db --full-refresh --vars '{snowplow__allow_refresh: true, snowplow__enable_media_player_v2: false, snowplow__enable_media_session: false, snowplow__enable_media_ad: false, snowplow__enable_media_ad_break: false, snowplow__enable_ad_quartile_event: false, snowplow__enable_mobile_events: false}'" || exit 1;

echo "Snowplow media player integration tests (v1 only): Execute models - run 2/2"

eval "dbt run --target $db --vars '{snowplow__allow_refresh: true, snowplow__enable_media_player_v2: false, snowplow__enable_media_session: false, snowplow__enable_media_ad: false, snowplow__enable_media_ad_break: false, snowplow__enable_ad_quartile_event: false, snowplow__enable_mobile_events: false}'" || exit 1;

# This run and the subsequent incremental ones exist just to make sure that the models work with the older contexts disabled
echo "Snowplow media player integration tests (v2 only): Execute models - run 1/6"

eval "dbt run --target $db --full-refresh --vars '{snowplow__allow_refresh: true, snowplow__backfill_limit_days: 3000, 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 (v2 only): Execute models - run 2/2"

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"
Expand Down
2 changes: 1 addition & 1 deletion macros/identifiers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0


{% macro user_identifiers() %}
{{ return(adapter.dispatch('user_identifiers', 'snowplow_unified')()) }}
{{ return(adapter.dispatch('user_identifiers', 'snowplow_media_player')()) }}
{% endmacro %}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{#
Copyright (c) 2022-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/
#}

{% macro dtype_to_type(dtype) -%}
{{ return(adapter.dispatch('dtype_to_type', 'snowplow_media_player')(dtype)) }}
{%- endmacro %}

{% macro default__dtype_to_type(dtype) -%}

{%- if 'string' in dtype -%}
{{ type_string() }}

{%- elif 'integer' in dtype -%}
{{ type_int() }}

{%- elif 'number' in dtype -%}
{{ type_numeric() }}

{%- elif 'float' in dtype -%}
{{ type_float() }}

{%- elif 'boolean' in dtype -%}
{{ type_boolean() }}

{%- else -%}
{{ exceptions.raise_compiler_error(dtype ~ ' dtype is not supported, please use data type specified in schema') }}

{%- endif -%}

{%- endmacro %}
39 changes: 0 additions & 39 deletions macros/snowplow_media_player_base_events_this_run/field.sql

This file was deleted.

18 changes: 18 additions & 0 deletions macros/snowplow_media_player_base_events_this_run/field_alias.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{#
Copyright (c) 2022-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/
#}

{% macro field_alias(field, prefix=None) -%}
{{ return(adapter.dispatch('field_alias', 'snowplow_media_player')(field, prefix)) }}
{%- endmacro %}

{% macro default__field_alias(field, prefix) -%}

{% set alias = (prefix~'_' if prefix else '')~(snakeify_case(field.get('field'))) -%}

{{ alias }}

{%- endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{#
Copyright (c) 2022-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/
#}

{% macro get_context_fields(fields, enabled, context, prefix=None) %}
{{ return(adapter.dispatch('get_context_fields', 'snowplow_media_player')(fields, enabled, context, prefix)) }}
{% endmacro %}

{% macro default__get_context_fields(fields, enabled, context, prefix) %}

{%- for f in fields %}
{% if '_' in f.get('field') %}
{{ exceptions.raise_compiler_error(f ~ ' field value should be in Camel case and not contain any "_" characters') }}
{% endif %}
{% endfor %}

{%- if enabled -%}
{{ get_enabled_context_fields(fields, context, prefix) }}
{%- else -%}
{% for f in fields %}
, cast(null as {{ dtype_to_type(f.get('dtype')) }}) as {{ field_alias(f, prefix) }}
{%- endfor %}

{%- endif -%}

{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{#
Copyright (c) 2022-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/
#}

{% macro get_enabled_context_fields(fields, col_prefix, field_prefix) -%}
{{ return(adapter.dispatch('get_enabled_context_fields')(fields, col_prefix, field_prefix)) }}
{%- endmacro %}


{% macro postgres__get_enabled_context_fields(fields, col_prefix, field_prefix) -%}
{%- endmacro %}


{% macro bigquery__get_enabled_context_fields(fields, col_prefix, field_prefix) -%}
{% for f in fields %}
, {{ snowplow_utils.get_optional_fields(
enabled=true,
fields=[{'field': snakeify_case(f.get('field')), 'dtype': f.get('dtype') }],
col_prefix=col_prefix,
relation=source('atomic', 'events'),
relation_alias='ev',
include_field_alias=false
) }} as {{ field_alias(f, field_prefix) }}
{%- endfor %}
{%- endmacro %}


{% macro snowflake__get_enabled_context_fields(fields, col_prefix, field_prefix) -%}
{% for f in fields %}
{% set type = dtype_to_type(f.get('dtype')) %}
, {{ snowplow_utils.get_field(
column_name=col_prefix,
field_name=f.get('field'),
table_alias='ev',
type=type,
array_index='0' if 'contexts_' in col_prefix else none
) }} as {{ field_alias(f, field_prefix) }}
{%- endfor %}
{%- endmacro %}


{% macro spark__get_enabled_context_fields(fields, col_prefix, field_prefix) -%}
{% for f in fields %}
{% set type = dtype_to_type(f.get('dtype')) %}
, {{ snowplow_utils.get_field(
column_name=col_prefix,
field_name=snakeify_case(f.get('field')),
table_alias='ev',
type=type,
array_index='0' if 'contexts_' in col_prefix else none
) }} as {{ field_alias(f, field_prefix) }}
{%- endfor %}
{%- endmacro %}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,19 @@ and you may not use this file except in compliance with the Snowplow Personal an
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/
#}

{% macro media_event_type_field(media_player_event_type, event_name) %}
{% macro media_event_type_field() -%}
coalesce(
{% if var("snowplow__enable_media_player_v1") -%}
-- for v1 media schemas, use the type property in media_player_event
{{ field(
media_player_event_type,
col_prefix="unstruct_event_com_snowplowanalytics_snowplow_media_player_event_1",
field='type'
) }}
{%- else -%}
{% if media_player_event_type is string and target.type not in ['postgres', 'redshift'] -%}
{{ media_player_event_type }}
{% elif target.type not in ['postgres', 'redshift'] %}
cast(null as {{ media_player_event_type.get('dtype', 'string') }})
{%- else -%}
null
{% endif %}
{%- endif %},
-- for v1 media schemas, use the type property in media_player_event
media_player_event__type,
-- for v2 media schemas, the type is the event name, remove underscores to match v1 event types
case
when right({{ event_name }}, 6) = '_event'
case
when right(event_name, 6) = '_event'
then replace(
left({{ event_name }}, length({{ event_name }}) - 6),
left(event_name, length(event_name) - 6),
'_',
''
)
else null
end
)
{% endmacro %}
{%- endmacro %}

This file was deleted.

Loading

0 comments on commit 3a68e11

Please sign in to comment.