diff --git a/models/intermediate/hubspot/int_hubspot__deal.sql b/models/intermediate/hubspot/int_hubspot__deal.sql index c89c797..a6db0c7 100644 --- a/models/intermediate/hubspot/int_hubspot__deal.sql +++ b/models/intermediate/hubspot/int_hubspot__deal.sql @@ -1,7 +1,11 @@ {% set id_deal_pipelines_excluded = "('15380854')" %} +{% set generic_account_manager_names = "('Host Services')" %} with stg_hubspot__deals as (select * from {{ ref("stg_hubspot__deals") }}), + stg_seed__hubspot_account_owner as ( + select * from {{ ref("stg_seed__hubspot_account_owner") }} + ), stg_hubspot__deal_pipeline_stages as ( select * from {{ ref("stg_hubspot__deal_pipeline_stages") }} ), @@ -16,6 +20,15 @@ select d.live_date_utc, d.cancellation_date_utc, d.account_manager, + case + when d.onboarding_owner is not null + then onboarding_owner + when + d.onboarding_owner is null + and d.account_manager in {{ generic_account_manager_names }} + then hao.hubspot_account_owner + else null + end as onboarding_owner, dp.deal_pipeline_name as deal_pipeline, dps.stage_name as deal_hubspot_stage, d.cancellation_category, @@ -27,6 +40,7 @@ select d.dashboard_type, d.pricing_structure, d.partnership_services, + d.expressed_service_interest, d.created_at_utc, d.created_date_utc, d.updated_at_utc, @@ -34,5 +48,8 @@ select from stg_hubspot__deals d left join stg_hubspot__deal_pipeline_stages dps on d.id_deal_stage = dps.id_stage left join stg_hubspot__deal_pipelines dp on dps.id_deal_pipeline = dp.id_deal_pipeline +left join + stg_seed__hubspot_account_owner hao + on d.id_hubspot_account_owner = hao.id_hubspot_account_owner -- Exclude Guardhog pipelines where dps.id_deal_pipeline not in {{ id_deal_pipelines_excluded }} diff --git a/models/intermediate/hubspot/schema.yml b/models/intermediate/hubspot/schema.yml index ea598f2..95a9939 100644 --- a/models/intermediate/hubspot/schema.yml +++ b/models/intermediate/hubspot/schema.yml @@ -47,6 +47,12 @@ models: The name of the account manager that is currently taking care of this deal. + - name: onboarding_owner + data_type: text + description: | + The name of the person who is or has been in charge of onboarding this + deal. + - name: deal_pipeline data_type: text description: | @@ -111,6 +117,18 @@ models: for complete accuracy. It can be null. + - name: expressed_service_interest + data_type: text + description: | + The services that captured the interest of the potential client + during onboarding calls, for New Dash. + This field has been processed by applying a standardized separation + "|" and an upper case. Be aware that this is not how data is + presented in HubSpot. + Not to be confused with the actual services that host has applied. + For the later, check backend data. + It can be null. + - name: created_at_utc data_type: timestamp with time zone description: Timestamp of when the record was created in Hubspot diff --git a/models/staging/hubspot/schema.yml b/models/staging/hubspot/schema.yml index 7113122..a7aa896 100644 --- a/models/staging/hubspot/schema.yml +++ b/models/staging/hubspot/schema.yml @@ -399,7 +399,7 @@ models: description: | The pricing structure that the customer has. It can be null. - - name: partnership_services_raw + - name: raw_partnership_services data_type: text description: | The partnership type, i.e., the services that the client has @@ -424,6 +424,29 @@ models: for complete accuracy. It can be null. + - name: raw_expressed_service_interest + data_type: text + description: | + The services that captured the interest of the potential client + during onboarding calls, for New Dash. + This exactly matches the input as is from HubSpot, in the sense + that no processing has been applied. + Not to be confused with the actual services that host has applied. + For the later, check backend data. + It can be null. + + - name: expressed_service_interest + data_type: text + description: | + The services that captured the interest of the potential client + during onboarding calls, for New Dash. + This field has been processed by applying a standardized separation + "|" and an upper case. Be aware that this is not how data is + presented in HubSpot. + Not to be confused with the actual services that host has applied. + For the later, check backend data. + It can be null. + - name: created_at_utc data_type: timestamp with time zone description: "" diff --git a/models/staging/hubspot/stg_hubspot__deals.sql b/models/staging/hubspot/stg_hubspot__deals.sql index fbbee1d..0f80737 100644 --- a/models/staging/hubspot/stg_hubspot__deals.sql +++ b/models/staging/hubspot/stg_hubspot__deals.sql @@ -100,6 +100,27 @@ with 'g' ) ) as partnership_services, + {{ adapter.quote("properties") }} + ->> 'services' as raw_expressed_service_interest, + -- Services (that are of interest in onboarding/sales time) are stored as + -- a string with multiple values separated by ; and these can contain + -- leading or trailing spaces. + -- In the following field we apply a standardization to the + -- values by replacing the separators with | and converting the values + -- to uppercase. The regex applied is: + -- \s* → Matches any leading or trailing spaces. + -- [;] → Matches ; as separator. + -- \s* → Again, ensures spaces around the separator are also replaced. + -- 'g' → Applies the replacement globally (to all occurrences in the + -- string). + upper( + regexp_replace( + {{ adapter.quote("properties") }} ->> 'services', + '\s*[;]\s*', + '|', + 'g' + ) + ) as expressed_service_interest, {{ adapter.quote("properties") }} as properties, {{ adapter.quote("createdAt") }} as created_at_utc, cast({{ adapter.quote("createdAt") }} as date) as created_date_utc, diff --git a/seeds/schema.yml b/seeds/schema.yml index 6fb1b66..a793db6 100644 --- a/seeds/schema.yml +++ b/seeds/schema.yml @@ -387,3 +387,30 @@ seeds: achieve by the end of the financial year. data_tests: - not_null + + - name: stg_seed__hubspot_account_owner + description: | + A seed that converts the id_hubspot_account_owner to the + person's name for Hubspot onboarding purposes. + To be revisited; ideally this is a standalone Hubspot + property. + config: + column_types: + id_hubspot_account_owner: varchar + + columns: + - name: id_hubspot_account_owner + data_type: character varying + description: | + ID of the hubspot account owner. + data_tests: + - not_null + - unique + + - name: hubspot_account_owner + data_type: character varying + description: | + Name of the hubspot account owner. + data_tests: + - not_null + - unique diff --git a/seeds/stg_seed__hubspot_account_owner.csv b/seeds/stg_seed__hubspot_account_owner.csv new file mode 100644 index 0000000..c91043f --- /dev/null +++ b/seeds/stg_seed__hubspot_account_owner.csv @@ -0,0 +1,7 @@ +id_hubspot_account_owner,hubspot_account_owner +"1732260638",Agustina Gil +"679781281",Cali Bowen +"203088812",Chloe Fraser +"1837277529",Danielle Miller +"76054743",María belén Florio +"76054690",Paola Zapata \ No newline at end of file