From ec0e95c1ef756f9904ef6e019bcbed403eb7c33c Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Fri, 12 Jun 2020 16:06:30 -0400 Subject: [PATCH] Refactor: optional contexts (#89) * Fix dbt_project.yml * Cross-compat filter in web timing --- dbt_project.yml | 7 +------ .../snowplow_base_performance_timing_context.sql | 3 +++ .../optional/snowplow_base_useragent_context.sql | 3 +++ .../optional/snowplow_web_timing_context.sql | 13 +++++++++---- .../optional/snowplow_web_ua_parser_context.sql | 3 ++- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/dbt_project.yml b/dbt_project.yml index e2fe2b6..a47493c 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -28,9 +28,4 @@ vars: models: snowplow: base: - materialized: ephemeral - optional: - enabled: false - page_views: - optional: - enabled: false + +materialized: ephemeral diff --git a/models/base/optional/snowplow_base_performance_timing_context.sql b/models/base/optional/snowplow_base_performance_timing_context.sql index 3a88bec..8c47ece 100644 --- a/models/base/optional/snowplow_base_performance_timing_context.sql +++ b/models/base/optional/snowplow_base_performance_timing_context.sql @@ -1,2 +1,5 @@ +{{ config( + enabled=(var('snowplow:context:performance_timing') and is_adapter('default')) +) }} select * from {{ var('snowplow:context:performance_timing') }} diff --git a/models/base/optional/snowplow_base_useragent_context.sql b/models/base/optional/snowplow_base_useragent_context.sql index 6a17e56..bf2a998 100644 --- a/models/base/optional/snowplow_base_useragent_context.sql +++ b/models/base/optional/snowplow_base_useragent_context.sql @@ -1,2 +1,5 @@ +{{ config( + enabled=(var('snowplow:context:useragent') and is_adapter('default')) +) }} select * from {{ var('snowplow:context:useragent') }} diff --git a/models/page_views/optional/snowplow_web_timing_context.sql b/models/page_views/optional/snowplow_web_timing_context.sql index d3e35be..4573f1f 100644 --- a/models/page_views/optional/snowplow_web_timing_context.sql +++ b/models/page_views/optional/snowplow_web_timing_context.sql @@ -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')) ) }} @@ -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 %} ), diff --git a/models/page_views/optional/snowplow_web_ua_parser_context.sql b/models/page_views/optional/snowplow_web_ua_parser_context.sql index 23352b5..93bdc32 100644 --- a/models/page_views/optional/snowplow_web_ua_parser_context.sql +++ b/models/page_views/optional/snowplow_web_ua_parser_context.sql @@ -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')) ) }}