Skip to content

Commit

Permalink
Restructure user sessions this run
Browse files Browse the repository at this point in the history
  • Loading branch information
agnessnowplow committed Jun 24, 2024
1 parent 6a8f179 commit 27b2f04
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions models/users/scratch/snowplow_unified_users_sessions_this_run.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,15 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0
)
}}

with prep as (
select
a.*,
case when platform = 'web' then true else false end on_web_base,
case when platform <> 'web' then true else false end on_mobile_base,
min(a.start_tstamp) over(partition by a.user_identifier) as user_start_tstamp,
max(a.end_tstamp) over(partition by a.user_identifier) as user_end_tstamp

from {{ var('snowplow__sessions_table') }} a
where exists (select 1 from {{ ref('snowplow_unified_base_sessions_this_run') }} b where a.user_identifier = b.user_identifier)
select
a.*,
case when platform = 'web' then true else false end on_web_base,
case when platform <> 'web' then true else false end on_mobile_base,
min(a.start_tstamp) over(partition by a.user_identifier) as user_start_tstamp,
max(a.end_tstamp) over(partition by a.user_identifier) as user_end_tstamp,
cast(max(cast(case when platform = 'web' then true else false end as {{ dbt.type_int() }})) over(partition by user_identifier) as {{ dbt.type_boolean() }}) as on_web,
cast(max(cast(case when platform <> 'web' then true else false end as {{ dbt.type_int() }})) over(partition by user_identifier) as {{ dbt.type_boolean() }}) as on_mobile

)

select *,
cast(max(cast(on_web_base as {{ dbt.type_int() }})) over(partition by user_identifier) as {{ dbt.type_boolean() }}) as on_web,
cast(max(cast(on_mobile_base as {{ dbt.type_int() }})) over(partition by user_identifier) as {{ dbt.type_boolean() }}) as on_mobile

from prep
from {{ var('snowplow__sessions_table') }} a
where exists (select 1 from {{ ref('snowplow_unified_base_sessions_this_run') }} b where a.user_identifier = b.user_identifier)

0 comments on commit 27b2f04

Please sign in to comment.