Skip to content

Commit

Permalink
fix: create contato_dados from a join of the arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
d116626 committed Oct 16, 2024
1 parent a905702 commit 798947e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,28 +272,42 @@ with
order by merge_order asc, rank asc
),

contato_telefone_dados as (
select
t.cpf,
array_agg(
struct(
t.valor_original,
t.ddd,
t.valor,
t.valor_tipo,
lower(t.sistema) as sistema,
t.rank
)
) as telefone,
from telefone_dedup t
group by t.cpf
),

contato_email_dados as (
select
e.cpf,
array_agg(
struct(lower(e.valor) as valor, lower(e.sistema) as sistema, e.rank)
) as email
from email_dedup e
group by e.cpf
),

contato_dados as (
select
a.cpf as cpf,
a.cpf,
struct(
array_agg(
struct(
t.valor_original,
t.ddd,
t.valor,
t.valor_tipo,
lower(t.sistema) as sistema,
t.rank
)
) as telefone,
array_agg(
struct(lower(e.valor) as valor, lower(e.sistema) as sistema, e.rank)
) as email
contato_telefone_dados.telefone, contato_email_dados.email
) as contato
from all_cpfs a
left join telefone_dedup t on a.cpf = t.cpf
left join email_dedup e on a.cpf = e.cpf
group by a.cpf
inner join contato_email_dados using (cpf)
inner join contato_telefone_dados using (cpf)
),

-- ENDEREÇO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,28 +398,42 @@ with
order by merge_order asc, rank asc
),

contato_telefone_dados as (
select
t.cpf,
array_agg(
struct(
t.valor_original,
t.ddd,
t.valor,
t.valor_tipo,
lower(t.sistema) as sistema,
t.rank
)
) as telefone,
from telefone_dedup t
group by t.cpf
),

contato_email_dados as (
select
e.cpf,
array_agg(
struct(lower(e.valor) as valor, lower(e.sistema) as sistema, e.rank)
) as email
from email_dedup e
group by e.cpf
),

contato_dados as (
select
a.cpf as cpf,
a.cpf,
struct(
array_agg(
struct(
t.valor_original,
t.ddd,
t.valor,
t.valor_tipo,
lower(t.sistema) as sistema,
t.rank
)
) as telefone,
array_agg(
struct(lower(e.valor) as valor, lower(e.sistema) as sistema, e.rank)
) as email
contato_telefone_dados.telefone, contato_email_dados.email
) as contato
from all_cpfs a
left join telefone_dedup t on a.cpf = t.cpf
left join email_dedup e on a.cpf = e.cpf
group by a.cpf
inner join contato_email_dados using (cpf)
inner join contato_telefone_dados using (cpf)
),

-- ENDEREÇO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,28 +247,42 @@ with
order by merge_order asc, rank asc
),

contato_telefone_dados as (
select
t.cpf,
array_agg(
struct(
t.valor_original,
t.ddd,
t.valor,
t.valor_tipo,
lower(t.sistema) as sistema,
t.rank
)
) as telefone,
from telefone_dedup t
group by t.cpf
),

contato_email_dados as (
select
e.cpf,
array_agg(
struct(lower(e.valor) as valor, lower(e.sistema) as sistema, e.rank)
) as email
from email_dedup e
group by e.cpf
),

contato_dados as (
select
a.cpf as cpf,
a.cpf,
struct(
array_agg(
struct(
t.valor_original,
t.ddd,
t.valor,
t.valor_tipo,
lower(t.sistema) as sistema,
t.rank
)
) as telefone,
array_agg(
struct(lower(e.valor) as valor, lower(e.sistema) as sistema, e.rank)
) as email
contato_telefone_dados.telefone, contato_email_dados.email
) as contato
from all_cpfs a
left join telefone_dedup t on a.cpf = t.cpf
left join email_dedup e on a.cpf = e.cpf
group by a.cpf
inner join contato_email_dados using (cpf)
inner join contato_telefone_dados using (cpf)
),

-- ENDEREÇO
Expand Down

0 comments on commit 798947e

Please sign in to comment.