Changed the logic for the model
This commit is contained in:
parent
84f2156c99
commit
35e7144efd
3 changed files with 43 additions and 20 deletions
|
|
@ -1,20 +0,0 @@
|
||||||
with
|
|
||||||
int_xero__contacts as (select * from {{ ref("int_xero__contacts") }}),
|
|
||||||
int_core__unified_user as (select * from {{ ref("int_core__unified_user") }}),
|
|
||||||
int_hubspot__deal as (select * from {{ ref("int_hubspot__deal") }})
|
|
||||||
|
|
||||||
select 'core' as source, id_deal, company_name as deal_name
|
|
||||||
from int_core__unified_user
|
|
||||||
where id_deal is not null
|
|
||||||
|
|
||||||
union all
|
|
||||||
|
|
||||||
select 'hubspot' as source, id_deal, deal_name
|
|
||||||
from int_hubspot__deal
|
|
||||||
where id_deal is not null
|
|
||||||
|
|
||||||
union all
|
|
||||||
|
|
||||||
select 'xero' as source, id_deal, contact_name as deal_name
|
|
||||||
from int_xero__contacts
|
|
||||||
where id_deal is not null
|
|
||||||
42
models/intermediate/cross/int_deals_consolidation.sql
Normal file
42
models/intermediate/cross/int_deals_consolidation.sql
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
with
|
||||||
|
int_xero__contacts as (select * from {{ ref("int_xero__contacts") }}),
|
||||||
|
int_core__unified_user as (select * from {{ ref("int_core__unified_user") }}),
|
||||||
|
int_hubspot__deal as (select * from {{ ref("int_hubspot__deal") }}),
|
||||||
|
ranked_core_deals as (
|
||||||
|
select
|
||||||
|
id_deal,
|
||||||
|
company_name as core_company_name,
|
||||||
|
row_number() over (partition by id_deal order by company_name) as row_num
|
||||||
|
from intermediate.int_core__unified_user
|
||||||
|
where id_deal is not null
|
||||||
|
),
|
||||||
|
deals_core as (
|
||||||
|
select id_deal, core_company_name from ranked_core_deals where row_num = 1
|
||||||
|
),
|
||||||
|
ranked_hubspot_deals as (
|
||||||
|
select
|
||||||
|
id_deal,
|
||||||
|
deal_name as hubspot_deal_name,
|
||||||
|
row_number() over (partition by id_deal order by deal_name) as row_num
|
||||||
|
from intermediate.int_hubspot__deal
|
||||||
|
where id_deal is not null
|
||||||
|
),
|
||||||
|
deals_hubspot as (
|
||||||
|
select id_deal, hubspot_deal_name from ranked_hubspot_deals where row_num = 1
|
||||||
|
),
|
||||||
|
ranked_xero_deals as (
|
||||||
|
select
|
||||||
|
id_deal,
|
||||||
|
contact_name as xero_contact_name,
|
||||||
|
row_number() over (partition by id_deal order by contact_name) as row_num
|
||||||
|
from intermediate.int_xero__contacts
|
||||||
|
where id_deal is not null
|
||||||
|
),
|
||||||
|
deals_xero as (
|
||||||
|
select id_deal, xero_contact_name from ranked_xero_deals where row_num = 1
|
||||||
|
)
|
||||||
|
|
||||||
|
select *
|
||||||
|
from deals_core
|
||||||
|
full outer join deals_hubspot using (id_deal)
|
||||||
|
full outer join deals_xero using (id_deal)
|
||||||
|
|
@ -1463,6 +1463,7 @@ models:
|
||||||
description: |
|
description: |
|
||||||
Main name for this ID deal.
|
Main name for this ID deal.
|
||||||
tests:
|
tests:
|
||||||
|
- unique
|
||||||
- not_null
|
- not_null
|
||||||
|
|
||||||
- name: main_billing_country_iso_3_per_deal
|
- name: main_billing_country_iso_3_per_deal
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue