Skip to content

Commit

Permalink
Refactor: optional contexts (#89)
Browse files Browse the repository at this point in the history
* Fix dbt_project.yml

* Cross-compat filter in web timing
  • Loading branch information
jtcohen6 authored Jun 12, 2020
1 parent d21547e commit ec0e95c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
7 changes: 1 addition & 6 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,4 @@ vars:
models:
snowplow:
base:
materialized: ephemeral
optional:
enabled: false
page_views:
optional:
enabled: false
+materialized: ephemeral
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
{{ config(
enabled=(var('snowplow:context:performance_timing') and is_adapter('default'))
) }}

select * from {{ var('snowplow:context:performance_timing') }}
3 changes: 3 additions & 0 deletions models/base/optional/snowplow_base_useragent_context.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
{{ config(
enabled=(var('snowplow:context:useragent') and is_adapter('default'))
) }}

select * from {{ var('snowplow:context:useragent') }}
13 changes: 9 additions & 4 deletions models/page_views/optional/snowplow_web_timing_context.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
config(
materialized='table',
sort='page_view_id',
dist='page_view_id'
dist='page_view_id',
enabled=(var('snowplow:context:performance_timing') and is_adapter('default'))
)
}}

Expand Down Expand Up @@ -74,9 +75,13 @@ prep as (
and pt.load_event_end is not null -- zero is acceptable

-- remove rare outliers (Unix timestamp is more than twice what it should be)
and datediff(d, pt.root_tstamp, (timestamp 'epoch' + pt.response_end/1000 * interval '1 second ')) < 365
and datediff(d, pt.root_tstamp, (timestamp 'epoch' + pt.unload_event_start/1000 * interval '1 second ')) < 365
and datediff(d, pt.root_tstamp, (timestamp 'epoch' + pt.unload_event_end/1000 * interval '1 second ')) < 365

{% set ts_columns = ['pt.response_end', 'pt.unload_event_start', 'pt.unload_event_end'] %}
{% for ts_column in ts_columns %}

and {{ dbt_utils.datediff(dbt_utils.dateadd('millisecond', ts_column, "'1970-01-01'"), 'pt.root_tstamp', 'day') }} < 365

{% endfor %}

),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
config(
materialized='table',
sort='page_view_id',
dist='page_view_id'
dist='page_view_id',
enabled=(var('snowplow:context:useragent') and is_adapter('default'))
)
}}

Expand Down

0 comments on commit ec0e95c

Please sign in to comment.