diff --git a/dbt_project.yml b/dbt_project.yml index 0c9e251..202f40a 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -115,6 +115,7 @@ vars: # Snowflake: snowplow__query_tag: snowplow_dbt + snowplow__snowflake_lakeloader: false # Databricks: # Depending on the use case it should either be the catalog (for Unity Catalog users from databricks connector 1.1.1 onwards) or the same value as your snowplow__atomic_schema (unless changed it should be 'atomic') diff --git a/macros/field_extractions/get_app_error_event_fields.sql b/macros/field_extractions/get_app_error_event_fields.sql index 9d68947..1a4b98e 100644 --- a/macros/field_extractions/get_app_error_event_fields.sql +++ b/macros/field_extractions/get_app_error_event_fields.sql @@ -84,15 +84,28 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% macro snowflake__get_app_error_event_fields() %} {% if var('snowplow__enable_app_errors', false) %} - , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:message::VARCHAR() AS app_error__message - , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:programmingLanguage::VARCHAR() AS app_error__programming_language - , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:className::VARCHAR() AS app_error__class_name - , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:exceptionName::VARCHAR() AS app_error__exception_name - , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:isFatal::BOOLEAN AS app_error__is_fatal - , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:lineNumber::INT AS app_error__line_number - , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:stackTrace::VARCHAR() AS app_error__stack_trace - , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:threadId::INT AS app_error__thread_id - , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:threadName::VARCHAR() AS app_error__thread_name + {% if var('snowplow__snowflake_lakeloader', false) %} + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:message::VARCHAR() AS app_error__message + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:programming_language::VARCHAR() AS app_error__programming_language + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:class_name::VARCHAR() AS app_error__class_name + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:exception_name::VARCHAR() AS app_error__exception_name + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:is_fatal::BOOLEAN AS app_error__is_fatal + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:line_number::INT AS app_error__line_number + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:stack_trace::VARCHAR() AS app_error__stack_trace + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:thread_id::INT AS app_error__thread_id + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:thread_name::VARCHAR() AS app_error__thread_name + {% else %} + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:message::VARCHAR() AS app_error__message + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:programmingLanguage::VARCHAR() AS app_error__programming_language + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:className::VARCHAR() AS app_error__class_name + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:exceptionName::VARCHAR() AS app_error__exception_name + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:isFatal::BOOLEAN AS app_error__is_fatal + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:lineNumber::INT AS app_error__line_number + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:stackTrace::VARCHAR() AS app_error__stack_trace + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:threadId::INT AS app_error__thread_id + , unstruct_event_com_snowplowanalytics_snowplow_application_error_1:threadName::VARCHAR() AS app_error__thread_name + {% endif %} + {% else %} , cast(null as {{ dbt.type_string() }}) as app_error__message , cast(null as {{ dbt.type_string() }}) as app_error__programming_language diff --git a/macros/field_extractions/get_browser_context_fields.sql b/macros/field_extractions/get_browser_context_fields.sql index ba4b4fb..a1b0ffc 100644 --- a/macros/field_extractions/get_browser_context_fields.sql +++ b/macros/field_extractions/get_browser_context_fields.sql @@ -105,19 +105,35 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% macro snowflake__get_browser_context_fields() %} {% if var('snowplow__enable_browser_context', false) %} - , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:viewport::varchar AS browser__viewport - , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:documentSize::varchar AS browser__document_size - , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:resolution::varchar AS browser__resolution - , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:colorDepth::int AS browser__color_depth - , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:devicePixelRatio::float AS browser__device_pixel_ratio - , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:cookiesEnabled::boolean AS browser__cookies_enabled - , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:online::boolean AS browser__online - , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:browserLanguage::varchar AS browser__browser_language - , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:documentLanguage::varchar AS browser__document_language - , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:webdriver::boolean AS browser__webdriver - , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:deviceMemory::int AS browser__device_memory - , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:hardwareConcurrency::int AS browser__hardware_concurrency - , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:tabId::varchar AS browser__tab_id + {% if var('snowplow__snowflake_lakeloader', false) %} + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:viewport::varchar AS browser__viewport + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:document_size::varchar AS browser__document_size + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:resolution::varchar AS browser__resolution + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:color_depth::int AS browser__color_depth + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:device_pixel_ratio::float AS browser__device_pixel_ratio + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:cookies_enabled::boolean AS browser__cookies_enabled + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:online::boolean AS browser__online + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:browser_language::varchar AS browser__browser_language + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:document_language::varchar AS browser__document_language + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:webdriver::boolean AS browser__webdriver + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:device_memory::int AS browser__device_memory + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:hardware_concurrency::int AS browser__hardware_concurrency + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:tab_id::varchar AS browser__tab_id + {% else %} + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:viewport::varchar AS browser__viewport + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:documentSize::varchar AS browser__document_size + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:resolution::varchar AS browser__resolution + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:colorDepth::int AS browser__color_depth + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:devicePixelRatio::float AS browser__device_pixel_ratio + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:cookiesEnabled::boolean AS browser__cookies_enabled + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:online::boolean AS browser__online + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:browserLanguage::varchar AS browser__browser_language + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:documentLanguage::varchar AS browser__document_language + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:webdriver::boolean AS browser__webdriver + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:deviceMemory::int AS browser__device_memory + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:hardwareConcurrency::int AS browser__hardware_concurrency + , contexts_com_snowplowanalytics_snowplow_browser_context_1[0]:tabId::varchar AS browser__tab_id + {% endif %} {% else %} , cast(null as {{ dbt.type_string() }}) as browser__viewport , cast(null as {{ dbt.type_string() }}) as browser__document_size diff --git a/macros/field_extractions/get_cmp_visible_event_fields.sql b/macros/field_extractions/get_cmp_visible_event_fields.sql index f565bd4..740fa1a 100644 --- a/macros/field_extractions/get_cmp_visible_event_fields.sql +++ b/macros/field_extractions/get_cmp_visible_event_fields.sql @@ -46,7 +46,11 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% macro snowflake__get_cmp_visible_event_fields() %} {% if var('snowplow__enable_consent', false) %} - , unstruct_event_com_snowplowanalytics_snowplow_cmp_visible_1:elapsedTime::float as cmp__elapsed_time + {% if var('snowplow__snowflake_lakeloader', false) %} + , unstruct_event_com_snowplowanalytics_snowplow_cmp_visible_1:elapsed_time::float as cmp__elapsed_time + {% else %} + , unstruct_event_com_snowplowanalytics_snowplow_cmp_visible_1:elapsedTime::float as cmp__elapsed_time + {% endif %} {% else %} , cast(null as {{ dbt.type_float() }}) as cmp__elapsed_time {% endif %} diff --git a/macros/field_extractions/get_consent_event_fields.sql b/macros/field_extractions/get_consent_event_fields.sql index d41c7dc..abfa231 100644 --- a/macros/field_extractions/get_consent_event_fields.sql +++ b/macros/field_extractions/get_consent_event_fields.sql @@ -74,23 +74,32 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% endmacro %} {% macro snowflake__get_consent_event_fields() %} - {% if var('snowplow__enable_consent', false) %} - - , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:eventType::varchar as consent__event_type - , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:basisForProcessing::varchar as consent__basis_for_processing - , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:consentUrl::varchar as consent__consent_url - , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:consentVersion::varchar as consent__consent_version - , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:consentScopes::array as consent__consent_scopes - , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:domainsApplied::array as consent__domains_applied - , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:gdprApplies::boolean as consent__gdpr_applies - + {% if var('snowplow__enable_consent', false) %} + {% if var('snowplow__snowflake_lakeloader', false) %} + , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:event_type::varchar as consent__event_type + , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:basis_for_processing::varchar as consent__basis_for_processing + , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:consent_url::varchar as consent__consent_url + , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:consent_version::varchar as consent__consent_version + , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:consent_scopes::array as consent__consent_scopes + , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:domains_applied::array as consent__domains_applied + , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:gdpr_applies::boolean as consent__gdpr_applies {% else %} - , cast(null as {{ dbt.type_string() }}) as consent__event_type - , cast(null as {{ dbt.type_string() }}) as consent__basis_for_processing - , cast(null as {{ dbt.type_string() }}) as consent__consent_url - , cast(null as {{ dbt.type_string() }}) as consent__consent_version - , cast(null as array) as consent__consent_scopes - , cast(null as array) as consent__domains_applied - , cast(null as {{ dbt.type_boolean() }}) as consent__gdpr_applies + , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:eventType::varchar as consent__event_type + , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:basisForProcessing::varchar as consent__basis_for_processing + , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:consentUrl::varchar as consent__consent_url + , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:consentVersion::varchar as consent__consent_version + , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:consentScopes::array as consent__consent_scopes + , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:domainsApplied::array as consent__domains_applied + , unstruct_event_com_snowplowanalytics_snowplow_consent_preferences_1:gdprApplies::boolean as consent__gdpr_applies {% endif %} + + {% else %} + , cast(null as {{ dbt.type_string() }}) as consent__event_type + , cast(null as {{ dbt.type_string() }}) as consent__basis_for_processing + , cast(null as {{ dbt.type_string() }}) as consent__consent_url + , cast(null as {{ dbt.type_string() }}) as consent__consent_version + , cast(null as array) as consent__consent_scopes + , cast(null as array) as consent__domains_applied + , cast(null as {{ dbt.type_boolean() }}) as consent__gdpr_applies + {% endif %} {% endmacro %} diff --git a/macros/field_extractions/get_cwv_fields.sql b/macros/field_extractions/get_cwv_fields.sql index 92a81cf..0238aec 100644 --- a/macros/field_extractions/get_cwv_fields.sql +++ b/macros/field_extractions/get_cwv_fields.sql @@ -74,13 +74,23 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% macro snowflake__get_cwv_fields() %} {% if var('snowplow__enable_cwv', false) %} - , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:lcp::decimal(14,4) as cwv__lcp - , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:fcp::decimal(14,4) as cwv__fcp - , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:fid::decimal(14,4) as cwv__fid - , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:cls::decimal(14,4) as cwv__cls - , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:inp::decimal(14,4) as cwv__inp - , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:ttfb::decimal(14,4) as cwv__ttfb - , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:navigationType::varchar as cwv__navigation_type + {% if var('snowplow__snowflake_lakeloader', false) %} + , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:lcp::decimal(14,4) as cwv__lcp + , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:fcp::decimal(14,4) as cwv__fcp + , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:fid::decimal(14,4) as cwv__fid + , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:cls::decimal(14,4) as cwv__cls + , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:inp::decimal(14,4) as cwv__inp + , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:ttfb::decimal(14,4) as cwv__ttfb + , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:navigation_type::varchar as cwv__navigation_type + {% else %} + , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:lcp::decimal(14,4) as cwv__lcp + , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:fcp::decimal(14,4) as cwv__fcp + , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:fid::decimal(14,4) as cwv__fid + , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:cls::decimal(14,4) as cwv__cls + , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:inp::decimal(14,4) as cwv__inp + , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:ttfb::decimal(14,4) as cwv__ttfb + , unstruct_event_com_snowplowanalytics_snowplow_web_vitals_1:navigationType::varchar as cwv__navigation_type + {% endif %} {% else %} , cast(null as decimal(14,4)) as cwv__lcp, , cast(null as decimal(14,4)) as cwv__fcp, diff --git a/macros/field_extractions/get_geo_context_fields.sql b/macros/field_extractions/get_geo_context_fields.sql index 90903dd..dc64870 100644 --- a/macros/field_extractions/get_geo_context_fields.sql +++ b/macros/field_extractions/get_geo_context_fields.sql @@ -74,13 +74,23 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% macro snowflake__get_geo_context_fields() %} {% if var('snowplow__enable_geolocation_context', false) %} - , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:latitude::float AS geo__latitude - , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:longitude::float AS geo__longitude - , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:latitudeLongitudeAccuracy::float AS geo__latitude_longitude_accuracy - , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:altitude::float AS geo__altitude - , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:altitudeAccuracy::float AS geo__altitude_accuracy - , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:bearing::float AS geo__bearing - , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:speed::float AS geo__speed + {% if var('snowplow__snowflake_lakeloader', false) %} + , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:latitude::float AS geo__latitude + , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:longitude::float AS geo__longitude + , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:latitude_longitude_accuracy::float AS geo__latitude_longitude_accuracy + , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:altitude::float AS geo__altitude + , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:altitude_accuracy::float AS geo__altitude_accuracy + , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:bearing::float AS geo__bearing + , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:speed::float AS geo__speed + {% else %} + , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:latitude::float AS geo__latitude + , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:longitude::float AS geo__longitude + , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:latitudeLongitudeAccuracy::float AS geo__latitude_longitude_accuracy + , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:altitude::float AS geo__altitude + , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:altitudeAccuracy::float AS geo__altitude_accuracy + , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:bearing::float AS geo__bearing + , contexts_com_snowplowanalytics_snowplow_geolocation_context_1[0]:speed::float AS geo__speed + {% endif %} {% else %} , cast(null as {{ dbt.type_float() }}) as geo__latitude , cast(null as {{ dbt.type_float() }}) as geo__longitude diff --git a/macros/field_extractions/get_iab_context_fields.sql b/macros/field_extractions/get_iab_context_fields.sql index 8df97b7..f42976d 100644 --- a/macros/field_extractions/get_iab_context_fields.sql +++ b/macros/field_extractions/get_iab_context_fields.sql @@ -59,10 +59,18 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% macro snowflake__get_iab_context_fields() %} {%- if var('snowplow__enable_iab', false) %} - , contexts_com_iab_snowplow_spiders_and_robots_1[0]:category::VARCHAR as iab__category - , contexts_com_iab_snowplow_spiders_and_robots_1[0]:primaryImpact::VARCHAR as iab__primary_impact - , contexts_com_iab_snowplow_spiders_and_robots_1[0]:reason::VARCHAR as iab__reason - , contexts_com_iab_snowplow_spiders_and_robots_1[0]:spiderOrRobot::BOOLEAN as iab__spider_or_robot + {% if var('snowplow__snowflake_lakeloader', false) %} + , contexts_com_iab_snowplow_spiders_and_robots_1[0]:category::VARCHAR as iab__category + , contexts_com_iab_snowplow_spiders_and_robots_1[0]:primary_impact::VARCHAR as iab__primary_impact + , contexts_com_iab_snowplow_spiders_and_robots_1[0]:reason::VARCHAR as iab__reason + , contexts_com_iab_snowplow_spiders_and_robots_1[0]:spider_or_robot::BOOLEAN as iab__spider_or_robot + {% else %} + , contexts_com_iab_snowplow_spiders_and_robots_1[0]:category::VARCHAR as iab__category + , contexts_com_iab_snowplow_spiders_and_robots_1[0]:primaryImpact::VARCHAR as iab__primary_impact + , contexts_com_iab_snowplow_spiders_and_robots_1[0]:reason::VARCHAR as iab__reason + , contexts_com_iab_snowplow_spiders_and_robots_1[0]:spiderOrRobot::BOOLEAN as iab__spider_or_robot + {% endif %} + {%- else -%} , cast(null as {{ dbt.type_string() }}) as iab__category , cast(null as {{ dbt.type_string() }}) as iab__primary_impact diff --git a/macros/field_extractions/get_mobile_context_fields.sql b/macros/field_extractions/get_mobile_context_fields.sql index 5fd1dff..2465248 100644 --- a/macros/field_extractions/get_mobile_context_fields.sql +++ b/macros/field_extractions/get_mobile_context_fields.sql @@ -164,31 +164,59 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% macro snowflake__get_mobile_context_fields() %} {% if var('snowplow__enable_mobile_context', false) %} - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:deviceManufacturer::varchar AS mobile__device_manufacturer - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:deviceModel::varchar AS mobile__device_model - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:osType::varchar AS mobile__os_type - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:osVersion::varchar AS mobile__os_version - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:androidIdfa::varchar AS mobile__android_idfa - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:appleIdfa::varchar AS mobile__apple_idfa - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:appleIdfv::varchar AS mobile__apple_idfv - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:carrier::varchar AS mobile__carrier - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:openIdfa::varchar AS mobile__open_idfa - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:networkTechnology::varchar AS mobile__network_technology - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:networkType::varchar(255) AS mobile__network_type - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:physicalMemory::int AS mobile__physical_memory - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:systemAvailableMemory::int AS mobile__system_available_memory - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:appAvailableMemory::int AS mobile__app_available_memory - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:batteryLevel::int AS mobile__battery_level - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:batteryState::varchar AS mobile__battery_state - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:lowPowerMode::boolean AS mobile__low_power_mode - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:availableStorage::int AS mobile__available_storage - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:totalStorage::int AS mobile__total_storage - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:isPortrait::boolean AS mobile__is_portrait - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:resolution::varchar AS mobile__resolution - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:scale::float AS mobile__scale - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:language::varchar AS mobile__language - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:appSetId::varchar AS mobile__app_set_id - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:appSetIdScope::varchar AS mobile__app_set_id_scope + {% if var('snowplow__snowflake_lakeloader', false) %} + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:device_manufacturer::varchar AS mobile__device_manufacturer + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:device_model::varchar AS mobile__device_model + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:os_type::varchar AS mobile__os_type + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:os_version::varchar AS mobile__os_version + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:android_idfa::varchar AS mobile__android_idfa + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:apple_idfa::varchar AS mobile__apple_idfa + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:apple_idfv::varchar AS mobile__apple_idfv + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:carrier::varchar AS mobile__carrier + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:open_idfa::varchar AS mobile__open_idfa + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:network_technology::varchar AS mobile__network_technology + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:network_type::varchar(255) AS mobile__network_type + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:physical_memory::int AS mobile__physical_memory + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:system_available_memory::int AS mobile__system_available_memory + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:app_available_memory::int AS mobile__app_available_memory + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:battery_level::int AS mobile__battery_level + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:battery_state::varchar AS mobile__battery_state + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:low_power_mode::boolean AS mobile__low_power_mode + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:available_storage::int AS mobile__available_storage + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:total_storage::int AS mobile__total_storage + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:is_portrait::boolean AS mobile__is_portrait + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:resolution::varchar AS mobile__resolution + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:scale::float AS mobile__scale + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:language::varchar AS mobile__language + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:app_set_id::varchar AS mobile__app_set_id + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:app_set_id_scope::varchar AS mobile__app_set_id_scope + {% else %} + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:deviceManufacturer::varchar AS mobile__device_manufacturer + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:deviceModel::varchar AS mobile__device_model + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:osType::varchar AS mobile__os_type + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:osVersion::varchar AS mobile__os_version + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:androidIdfa::varchar AS mobile__android_idfa + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:appleIdfa::varchar AS mobile__apple_idfa + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:appleIdfv::varchar AS mobile__apple_idfv + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:carrier::varchar AS mobile__carrier + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:openIdfa::varchar AS mobile__open_idfa + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:networkTechnology::varchar AS mobile__network_technology + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:networkType::varchar(255) AS mobile__network_type + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:physicalMemory::int AS mobile__physical_memory + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:systemAvailableMemory::int AS mobile__system_available_memory + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:appAvailableMemory::int AS mobile__app_available_memory + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:batteryLevel::int AS mobile__battery_level + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:batteryState::varchar AS mobile__battery_state + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:lowPowerMode::boolean AS mobile__low_power_mode + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:availableStorage::int AS mobile__available_storage + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:totalStorage::int AS mobile__total_storage + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:isPortrait::boolean AS mobile__is_portrait + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:resolution::varchar AS mobile__resolution + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:scale::float AS mobile__scale + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:language::varchar AS mobile__language + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:appSetId::varchar AS mobile__app_set_id + , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]:appSetIdScope::varchar AS mobile__app_set_id_scope + {% endif %} {% else %} , cast(null as {{ dbt.type_string() }}) as mobile__device_manufacturer , cast(null as {{ dbt.type_string() }}) as mobile__device_model diff --git a/macros/field_extractions/get_screen_context_fields.sql b/macros/field_extractions/get_screen_context_fields.sql index df3f099..9f4c29d 100644 --- a/macros/field_extractions/get_screen_context_fields.sql +++ b/macros/field_extractions/get_screen_context_fields.sql @@ -74,13 +74,23 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% macro snowflake__get_screen_context_fields() %} {% if var('snowplow__enable_screen_context', false) %} - , contexts_com_snowplowanalytics_mobile_screen_1[0]:id::varchar(36) AS screen__id - , contexts_com_snowplowanalytics_mobile_screen_1[0]:name::varchar AS screen__name - , contexts_com_snowplowanalytics_mobile_screen_1[0]:activity::varchar AS screen__activity - , contexts_com_snowplowanalytics_mobile_screen_1[0]:fragment::varchar AS screen__fragment - , contexts_com_snowplowanalytics_mobile_screen_1[0]:topViewController::varchar AS screen__top_view_controller - , contexts_com_snowplowanalytics_mobile_screen_1[0]:type::varchar AS screen__type - , contexts_com_snowplowanalytics_mobile_screen_1[0]:viewController::varchar AS screen__view_controller + {% if var('snowplow__snowflake_lakeloader', false) %} + , contexts_com_snowplowanalytics_mobile_screen_1[0]:id::varchar(36) AS screen__id + , contexts_com_snowplowanalytics_mobile_screen_1[0]:name::varchar AS screen__name + , contexts_com_snowplowanalytics_mobile_screen_1[0]:activity::varchar AS screen__activity + , contexts_com_snowplowanalytics_mobile_screen_1[0]:fragment::varchar AS screen__fragment + , contexts_com_snowplowanalytics_mobile_screen_1[0]:top_view_controller::varchar AS screen__top_view_controller + , contexts_com_snowplowanalytics_mobile_screen_1[0]:type::varchar AS screen__type + , contexts_com_snowplowanalytics_mobile_screen_1[0]:view_controller::varchar AS screen__view_controller + {% else %} + , contexts_com_snowplowanalytics_mobile_screen_1[0]:id::varchar(36) AS screen__id + , contexts_com_snowplowanalytics_mobile_screen_1[0]:name::varchar AS screen__name + , contexts_com_snowplowanalytics_mobile_screen_1[0]:activity::varchar AS screen__activity + , contexts_com_snowplowanalytics_mobile_screen_1[0]:fragment::varchar AS screen__fragment + , contexts_com_snowplowanalytics_mobile_screen_1[0]:topViewController::varchar AS screen__top_view_controller + , contexts_com_snowplowanalytics_mobile_screen_1[0]:type::varchar AS screen__type + , contexts_com_snowplowanalytics_mobile_screen_1[0]:viewController::varchar AS screen__view_controller + {% endif %} {% else %} , cast(null as {{ dbt.type_string() }}) as screen__id , cast(null as {{ dbt.type_string() }}) as screen__name diff --git a/macros/field_extractions/get_screen_view_event_fields.sql b/macros/field_extractions/get_screen_view_event_fields.sql index 153c2be..64cfec0 100644 --- a/macros/field_extractions/get_screen_view_event_fields.sql +++ b/macros/field_extractions/get_screen_view_event_fields.sql @@ -74,13 +74,23 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% macro snowflake__get_screen_view_event_fields() %} {% if var('snowplow__enable_mobile', false) %} - , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:id::varchar(36) AS screen_view__id - , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:name::varchar AS screen_view__name - , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:previousId::varchar(36) AS screen_view__previous_id - , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:previousName::varchar AS screen_view__previous_name - , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:previousType::varchar AS screen_view__previous_type - , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:transitionType::varchar AS screen_view__transition_type - , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:type::varchar AS screen_view__type + {% if var('snowplow__snowflake_lakeloader', false) %} + , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:id::varchar(36) AS screen_view__id + , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:name::varchar AS screen_view__name + , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:previous_id::varchar(36) AS screen_view__previous_id + , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:previous_name::varchar AS screen_view__previous_name + , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:previous_type::varchar AS screen_view__previous_type + , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:transition_type::varchar AS screen_view__transition_type + , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:type::varchar AS screen_view__type + {% else %} + , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:id::varchar(36) AS screen_view__id + , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:name::varchar AS screen_view__name + , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:previousId::varchar(36) AS screen_view__previous_id + , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:previousName::varchar AS screen_view__previous_name + , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:previousType::varchar AS screen_view__previous_type + , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:transitionType::varchar AS screen_view__transition_type + , unstruct_event_com_snowplowanalytics_mobile_screen_view_1:type::varchar AS screen_view__type + {% endif %} {% else %} , cast(null as {{ dbt.type_string() }}) as screen_view__id , cast(null as {{ dbt.type_string() }}) as screen_view__name diff --git a/macros/field_extractions/get_session_context_fields.sql b/macros/field_extractions/get_session_context_fields.sql index 56e57fb..34d61eb 100644 --- a/macros/field_extractions/get_session_context_fields.sql +++ b/macros/field_extractions/get_session_context_fields.sql @@ -76,6 +76,16 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% macro snowflake__get_session_context_fields() %} {% if var('snowplow__enable_mobile', false) %} + {% if var('snowplow__snowflake_lakeloader', false) %} + , contexts_com_snowplowanalytics_snowplow_client_session_1[0]:session_id::varchar(36) AS session__session_id + , contexts_com_snowplowanalytics_snowplow_client_session_1[0]:session_index::int AS session__session_index + , contexts_com_snowplowanalytics_snowplow_client_session_1[0]:previous_session_id::varchar(36) AS session__previous_session_id + , contexts_com_snowplowanalytics_snowplow_client_session_1[0]:user_id::varchar(36) AS session__user_id + , contexts_com_snowplowanalytics_snowplow_client_session_1[0]:first_event_id::varchar(36) AS session__first_event_id + , contexts_com_snowplowanalytics_snowplow_client_session_1[0]:event_index::int AS session__event_index + , contexts_com_snowplowanalytics_snowplow_client_session_1[0]:storage_mechanism::varchar(36) AS session__storage_mechanism + , contexts_com_snowplowanalytics_snowplow_client_session_1[0]:first_event_timestamp::varchar(36) AS session__first_event_timestamp + {% else %} , contexts_com_snowplowanalytics_snowplow_client_session_1[0]:sessionId::varchar(36) AS session__session_id , contexts_com_snowplowanalytics_snowplow_client_session_1[0]:sessionIndex::int AS session__session_index , contexts_com_snowplowanalytics_snowplow_client_session_1[0]:previousSessionId::varchar(36) AS session__previous_session_id @@ -84,14 +94,15 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 , contexts_com_snowplowanalytics_snowplow_client_session_1[0]:eventIndex::int AS session__event_index , contexts_com_snowplowanalytics_snowplow_client_session_1[0]:storageMechanism::varchar(36) AS session__storage_mechanism , contexts_com_snowplowanalytics_snowplow_client_session_1[0]:firstEventTimestamp::varchar(36) AS session__first_event_timestamp - {% else %} - , cast(null as {{ dbt.type_string() }}) as session__session_id - , cast(null as {{ dbt.type_numeric() }}) as session__session_index - , cast(null as {{ dbt.type_string() }}) as session__previous_session_id - , cast(null as {{ dbt.type_string() }}) as session__user_id - , cast(null as {{ dbt.type_string() }}) as session__first_event_id - , cast(null as {{ dbt.type_numeric() }}) as session__event_index - , cast(null as {{ dbt.type_string() }}) as session__storage_mechanism - , cast(null as {{ dbt.type_string() }}) as session__first_event_timestamp + {% endif %} + {% else %} + , cast(null as {{ dbt.type_string() }}) as session__session_id + , cast(null as {{ dbt.type_numeric() }}) as session__session_index + , cast(null as {{ dbt.type_string() }}) as session__previous_session_id + , cast(null as {{ dbt.type_string() }}) as session__user_id + , cast(null as {{ dbt.type_string() }}) as session__first_event_id + , cast(null as {{ dbt.type_numeric() }}) as session__event_index + , cast(null as {{ dbt.type_string() }}) as session__storage_mechanism + , cast(null as {{ dbt.type_string() }}) as session__first_event_timestamp {% endif %} {% endmacro %} diff --git a/macros/field_extractions/get_ua_context_fields.sql b/macros/field_extractions/get_ua_context_fields.sql index 53f5414..321df9c 100644 --- a/macros/field_extractions/get_ua_context_fields.sql +++ b/macros/field_extractions/get_ua_context_fields.sql @@ -100,18 +100,33 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% macro snowflake__get_ua_context_fields() %} {%- if var('snowplow__enable_ua', false) -%} - , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragentFamily::VARCHAR as ua__useragent_family - , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragentMajor::VARCHAR as ua__useragent_major - , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragentMinor::VARCHAR as ua__useragent_minor - , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragentPatch::VARCHAR as ua__useragent_patch - , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragentVersion::VARCHAR as ua__useragent_version - , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:osFamily::VARCHAR as ua__os_family - , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:osMajor::VARCHAR as ua__os_major - , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:osMinor::VARCHAR as ua__os_minor - , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:osPatch::VARCHAR as ua__os_patch - , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:osPatchMinor::VARCHAR as ua__os_patch_minor - , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:osVersion::VARCHAR as ua__os_version - , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:deviceFamily::VARCHAR as ua__device_family + {% if var('snowplow__snowflake_lakeloader', false) %} + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragent_family::VARCHAR as ua__useragent_family + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragent_major::VARCHAR as ua__useragent_major + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragent_minor::VARCHAR as ua__useragent_minor + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragent_patch::VARCHAR as ua__useragent_patch + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragent_version::VARCHAR as ua__useragent_version + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:os_family::VARCHAR as ua__os_family + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:os_major::VARCHAR as ua__os_major + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:os_minor::VARCHAR as ua__os_minor + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:os_patch::VARCHAR as ua__os_patch + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:os_patch_minor::VARCHAR as ua__os_patch_minor + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:os_version::VARCHAR as ua__os_version + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:device_family::VARCHAR as ua__device_family + {% else %} + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragentFamily::VARCHAR as ua__useragent_family + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragentMajor::VARCHAR as ua__useragent_major + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragentMinor::VARCHAR as ua__useragent_minor + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragentPatch::VARCHAR as ua__useragent_patch + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:useragentVersion::VARCHAR as ua__useragent_version + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:osFamily::VARCHAR as ua__os_family + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:osMajor::VARCHAR as ua__os_major + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:osMinor::VARCHAR as ua__os_minor + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:osPatch::VARCHAR as ua__os_patch + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:osPatchMinor::VARCHAR as ua__os_patch_minor + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:osVersion::VARCHAR as ua__os_version + , contexts_com_snowplowanalytics_snowplow_ua_parser_context_1[0]:deviceFamily::VARCHAR as ua__device_family + {% endif %} {%- else -%} , cast(null as {{ dbt.type_string() }}) as ua__useragent_family , cast(null as {{ dbt.type_string() }}) as ua__useragent_major diff --git a/macros/field_extractions/get_yauaa_context_fields.sql b/macros/field_extractions/get_yauaa_context_fields.sql index 6137a07..5ef0940 100644 --- a/macros/field_extractions/get_yauaa_context_fields.sql +++ b/macros/field_extractions/get_yauaa_context_fields.sql @@ -139,6 +139,28 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% macro snowflake__get_yauaa_context_fields() %} {%- if var('snowplow__enable_yauaa', false) -%} + {% if var('snowplow__snowflake_lakeloader', false) %} + , contexts_nl_basjes_yauaa_context_1[0]:device_class::VARCHAR as yauaa__device_class + , contexts_nl_basjes_yauaa_context_1[0]:agent_class::VARCHAR as yauaa__agent_class + , contexts_nl_basjes_yauaa_context_1[0]:agent_name::VARCHAR as yauaa__agent_name + , contexts_nl_basjes_yauaa_context_1[0]:agent_name_version::VARCHAR as yauaa__agent_name_version + , contexts_nl_basjes_yauaa_context_1[0]:agent_name_version_major::VARCHAR as yauaa__agent_name_version_major + , contexts_nl_basjes_yauaa_context_1[0]:agent_version::VARCHAR as yauaa__agent_version + , contexts_nl_basjes_yauaa_context_1[0]:agent_version_major::VARCHAR as yauaa__agent_version_major + , contexts_nl_basjes_yauaa_context_1[0]:device_brand::VARCHAR as yauaa__device_brand + , contexts_nl_basjes_yauaa_context_1[0]:device_name::VARCHAR as yauaa__device_name + , contexts_nl_basjes_yauaa_context_1[0]:device_version::VARCHAR as yauaa__device_version + , contexts_nl_basjes_yauaa_context_1[0]:layout_engine_class::VARCHAR as yauaa__layout_engine_class + , contexts_nl_basjes_yauaa_context_1[0]:layout_engine_name::VARCHAR as yauaa__layout_engine_name + , contexts_nl_basjes_yauaa_context_1[0]:layout_engine_name_version::VARCHAR as yauaa__layout_engine_name_version + , contexts_nl_basjes_yauaa_context_1[0]:layout_engine_name_version_major::VARCHAR as yauaa__layout_engine_name_version_major + , contexts_nl_basjes_yauaa_context_1[0]:layout_engine_version::VARCHAR as yauaa__layout_engine_version + , contexts_nl_basjes_yauaa_context_1[0]:layout_engine_version_major::VARCHAR as yauaa__layout_engine_version_major + , contexts_nl_basjes_yauaa_context_1[0]:operating_system_class::VARCHAR as yauaa__operating_system_class + , contexts_nl_basjes_yauaa_context_1[0]:operating_system_name::VARCHAR as yauaa__operating_system_name + , contexts_nl_basjes_yauaa_context_1[0]:operating_system_name_version::VARCHAR as yauaa__operating_system_name_version + , contexts_nl_basjes_yauaa_context_1[0]:operating_system_version::VARCHAR as yauaa__operating_system_version + {% else %} , contexts_nl_basjes_yauaa_context_1[0]:deviceClass::VARCHAR as yauaa__device_class , contexts_nl_basjes_yauaa_context_1[0]:agentClass::VARCHAR as yauaa__agent_class , contexts_nl_basjes_yauaa_context_1[0]:agentName::VARCHAR as yauaa__agent_name @@ -159,6 +181,7 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 , contexts_nl_basjes_yauaa_context_1[0]:operatingSystemName::VARCHAR as yauaa__operating_system_name , contexts_nl_basjes_yauaa_context_1[0]:operatingSystemNameVersion::VARCHAR as yauaa__operating_system_name_version , contexts_nl_basjes_yauaa_context_1[0]:operatingSystemVersion::VARCHAR as yauaa__operating_system_version + {% endif %} {%- else -%} , cast(null as {{ dbt.type_string() }}) as yauaa__device_class , cast(null as {{ dbt.type_string() }}) as yauaa__agent_class diff --git a/macros/identifiers.sql b/macros/identifiers.sql index 036cd0e..6ddc987 100644 --- a/macros/identifiers.sql +++ b/macros/identifiers.sql @@ -39,11 +39,17 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% else %} + {% if var('snowplow__snowflake_lakeloader', false) %} + {% set mobile_id_field = 'session_id' %} + {% else %} + {% set mobile_id_field = 'sessionId' %} + {% endif %} + {% if var('snowplow__enable_web') and var('snowplow__enable_mobile') %} - {{ return([{'schema': 'contexts_com_snowplowanalytics_snowplow_client_session_1', 'field': 'sessionId'}, {'schema': 'atomic', 'field': 'domain_sessionid'}] )}} + {{ return([{'schema': 'contexts_com_snowplowanalytics_snowplow_client_session_1', 'field': mobile_id_field}, {'schema': 'atomic', 'field': 'domain_sessionid'}] )}} {% elif var('snowplow__enable_mobile') %} - {{ return([{'schema': 'contexts_com_snowplowanalytics_snowplow_client_session_1', 'field': 'sessionId'}] )}} + {{ return([{'schema': 'contexts_com_snowplowanalytics_snowplow_client_session_1', 'field': mobile_id_field}] )}} {% else %} {{ return([{'schema': 'atomic', 'field': 'domain_sessionid'}] )}} @@ -188,10 +194,3 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 {% endif %} {% endmacro %} - - - - - - - diff --git a/models/base/scratch/snowplow_unified_base_events_this_run.sql b/models/base/scratch/snowplow_unified_base_events_this_run.sql index 8d2b7e1..86ac2ee 100644 --- a/models/base/scratch/snowplow_unified_base_events_this_run.sql +++ b/models/base/scratch/snowplow_unified_base_events_this_run.sql @@ -102,9 +102,29 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 with base_query as ( {{ base_events_query }} ) --- depends_on: {{ ref('snowplow_unified_base_sessions_this_run') }} + +{# NOTE: This lakeloader workaround should be removed when Snowflake support structured types in regular tables https://docs.snowflake.com/en/sql-reference/data-types-structured #} + +{% if var('snowplow__snowflake_lakeloader', false) -%} + {% set base_query_cols = get_column_schema_from_query( 'select * from (' + base_events_query +') a') %} +{%- endif -%} + select + {% if var('snowplow__snowflake_lakeloader', false) and target.type == 'snowflake' -%} + {% for col in base_query_cols | map(attribute='name') | list -%} + {% if col.startswith('CONTEXTS_')%} + cast({{col}} as array) as {{col}} + {% elif col.startswith('UNSTRUCT_')%} + cast({{col}} as object) as {{col}} + {%- else -%} + {{col}} + {%- endif -%} + {%- if not loop.last -%},{%- endif %} + {% endfor %} + {% else %} * + {%- endif -%} + -- extract commonly used contexts / sdes (prefixed) {{ snowplow_unified.get_web_page_context_fields() }} {{ snowplow_unified.get_iab_context_fields() }}