Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Add deduplication of source page views #76

Merged
merged 3 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions models/base/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
{% docs segment_web_page_views %}

This is a base model for Segment's web page views table. It does some straightforward renaming and parsing of Segment raw data in this table.
If a page view id has multiple entries in the source table then deduplication is done to keep the row with the earliest `received_at` timestamp.

{% enddocs %}
20 changes: 19 additions & 1 deletion models/base/segment_web_page_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ with source as (

),

row_numbering as (

select
*,
row_number() over (partition by id order by received_at asc) as row_num
from source

),

deduped as (

select
*
from row_numbering
where row_num = 1

),

renamed as (

select
Expand Down Expand Up @@ -50,7 +68,7 @@ renamed as (

{% endif %}

from source
from deduped

),

Expand Down