From da667bce1f249a6b988e2bca6346369ed7834740 Mon Sep 17 00:00:00 2001 From: Ilias Xenogiannis Date: Mon, 10 Jun 2024 19:54:38 +0300 Subject: [PATCH] Change databrick macro to safely access the json elemnts --- .../get_mobile_context_fields.sql | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/macros/field_extractions/get_mobile_context_fields.sql b/macros/field_extractions/get_mobile_context_fields.sql index ea7a575..1282e05 100644 --- a/macros/field_extractions/get_mobile_context_fields.sql +++ b/macros/field_extractions/get_mobile_context_fields.sql @@ -104,35 +104,35 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 , cast(null as {{ dbt.type_string() }}) as mobile__app_set_id , cast(null as {{ dbt.type_string() }}) as mobile__app_set_id_scope {% endif %} -{% endmacro %} +{% endmacro %} {% macro spark__get_mobile_context_fields() %} {% if var('snowplow__enable_mobile_context', false) %} - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0].device_manufacturer::STRING AS mobile__device_manufacturer - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0].device_model::STRING AS mobile__device_model - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0].os_type::STRING AS mobile__os_type - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0].os_version::STRING AS mobile__os_version - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0].android_idfa::STRING AS mobile__android_idfa - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0].apple_idfa::STRING AS mobile__apple_idfa - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0].apple_idfv::STRING AS mobile__apple_idfv - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0].carrier::STRING AS mobile__carrier - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0].open_idfa::STRING AS mobile__open_idfa - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0].network_technology::STRING AS mobile__network_technology - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0].network_type::STRING 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::STRING 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::bigint AS mobile__available_storage - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0].total_storage::bigint 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::STRING 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::STRING AS mobile__language - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0].app_set_id::STRING AS mobile__app_set_id - , contexts_com_snowplowanalytics_snowplow_mobile_context_1[0].app_set_id_scope::STRING AS mobile__app_set_id_scope + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.device_manufacturer')::BOOLEAN AS mobile__device_manufacturer + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.device_model')::BOOLEAN AS mobile__device_model + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.os_type')::BOOLEAN AS mobile__os_type + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.os_version')::BOOLEAN AS mobile__os_version + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.android_idfa')::BOOLEAN AS mobile__android_idfa + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.apple_idfa')::BOOLEAN AS mobile__apple_idfa + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.apple_idfv')::BOOLEAN AS mobile__apple_idfv + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.carrier')::BOOLEAN AS mobile__carrier + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.open_idfa')::BOOLEAN AS mobile__open_idfa + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.network_technology')::BOOLEAN AS mobile__network_technology + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.network_type')::BOOLEAN AS mobile__network_type + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.physical_memory')::BOOLEAN AS mobile__physical_memory + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.system_available_memory')::BOOLEAN AS mobile__system_available_memory + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.app_available_memory')::BOOLEAN AS mobile__app_available_memory + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.battery_level')::BOOLEAN AS mobile__battery_level + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.battery_state')::BOOLEAN AS mobile__battery_state + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.low_power_mode')::BOOLEAN AS mobile__low_power_mode + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.available_storage')::BOOLEAN AS mobile__available_storage + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.total_storage')::BOOLEAN AS mobile__total_storage + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.is_portrait')::BOOLEAN AS mobile__is_portrait + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.resolution')::BOOLEAN AS mobile__resolution + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.scale')::BOOLEAN AS mobile__scale + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.language')::BOOLEAN AS mobile__language + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.app_set_id')::BOOLEAN AS mobile__app_set_id + , get_json_object(contexts_com_snowplowanalytics_snowplow_mobile_context_1[0]::String,'$.app_set_id_scope')::BOOLEAN AS mobile__app_set_id_scope {% else %} , cast(null as {{ dbt.type_string() }}) as mobile__device_manufacturer , cast(null as {{ dbt.type_string() }}) as mobile__device_model