Skip to content

Commit

Permalink
Add missing primary key to media_ad_views
Browse files Browse the repository at this point in the history
  • Loading branch information
georgewoodhead committed Nov 13, 2023
1 parent e706777 commit a25ebd6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
snowplow-media-player 0.7.0 (2023-xx-xx)
---------------------------------------
## Summary
This release adds a more robust unique media identifier. This fixes an issue where duplicate `media_id` values could occur in the media stats table as a result of incorrect tracking implementation (e.g. sharing the same media label across different media types).
This release adds a more robust unique media identifier. This fixes an issue where duplicate `media_id` values could occur in the media stats table as a result of incorrect tracking implementation (e.g. sharing the same media label across different media types). This release also fixes the incremental materialization of the media_ad_views table by adding a unique primary key.

## Features
Add unique media identifier (close #59)
## Fixes
- Add unique media identifier (close #59)
- Add missing primary key to media_ad_views

## Under the hood

Expand Down
7 changes: 7 additions & 0 deletions models/media_ad_views/media_ad_views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ models:
+tags: "snowplow_media_player_incremental"
description: '{{ doc("table_base") }}'
columns:
- name: media_ad_view_id
description: The primary key of this table
tags:
- primary-key
tests:
- unique
- not_null
- name: media_ad_id
description: '{{ doc("col_media_ad_id") }}'
tests:
Expand Down
7 changes: 7 additions & 0 deletions models/media_ad_views/scratch/base_scratch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ models:
- name: snowplow_media_player_media_ad_views_this_run
description: '{{ doc("table_media_ad_views_this_run") }}'
columns:
- name: media_ad_view_id
description: The primary key of this table
tags:
- primary-key
tests:
- unique
- not_null
- name: media_ad_id
description: '{{ doc("col_media_ad_id") }}'
tests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ events_this_run as (

)

select *
{% if target.type in ['databricks', 'spark'] -%}
, date(prep.viewed_at) as viewed_at_date
{%- endif %}
from prep
select
{{ dbt_utils.generate_surrogate_key(['p.play_id', 'p.ad_break_id', 'p.media_ad_id']) }} as media_ad_view_id
, p.*
{% if target.type in ['databricks', 'spark'] -%}
, date(p.viewed_at) as viewed_at_date
{%- endif %}

from prep as p
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0
{{
config(
materialized= "incremental",
unique_key= 'media_ad_view_id',
upsert_date_key='last_event',
sort = 'last_event',
dist = 'media_ad_id',
Expand Down

0 comments on commit a25ebd6

Please sign in to comment.