Change of transformation order for stg_AGENTS

This commit is contained in:
Anna Saiapina 2024-07-24 08:01:21 +00:00 committed by GCP Dataform
parent be7bc10be4
commit 75298e24d5

View File

@ -9,24 +9,7 @@ config {
description: "All fields that are connected to the AGENT" description: "All fields that are connected to the AGENT"
} }
with last_agent_digital as ( with agent_digital as (
select AGENT_ID,
AGENT_NAME,
AGENT_GROUP,
ROW_NUMBER ()
OVER (partition by AGENT_ID order by timestamp desc) row_n
from ${ref("stg_digital")}
),
last_agent_calls as (
select AGENT_ID,
AGENT_NAME,
AGENT_GROUP,
ROW_NUMBER ()
OVER (partition by AGENT_ID order by timestamp desc) row_n
from ${ref("stg_calls")}
),
agent_digital_dedup as (
select AGENT_ID, select AGENT_ID,
case case
when strpos(AGENT_NAME, '(') > 0 and strpos(AGENT_NAME, ') ') = 0 when strpos(AGENT_NAME, '(') > 0 and strpos(AGENT_NAME, ') ') = 0
@ -48,11 +31,11 @@ agent_digital_dedup as (
when strpos(AGENT_NAME, '-') > 0 when strpos(AGENT_NAME, '-') > 0
then upper(substr(AGENT_NAME, strpos(AGENT_NAME, '-') + 1)) then upper(substr(AGENT_NAME, strpos(AGENT_NAME, '-') + 1))
else null else null
end AS LANGUAGES end AS LANGUAGES,
from last_agent_digital timestamp
where row_n = 1 from ${ref("stg_digital")}
), ),
agent_calls_dedup as ( agent_calls as (
select AGENT_ID, select AGENT_ID,
case case
when strpos(AGENT_NAME, '(') > 0 and strpos(AGENT_NAME, ') ') = 0 when strpos(AGENT_NAME, '(') > 0 and strpos(AGENT_NAME, ') ') = 0
@ -74,25 +57,33 @@ agent_calls_dedup as (
when strpos(AGENT_NAME, '-') > 0 when strpos(AGENT_NAME, '-') > 0
then upper(substr(AGENT_NAME, strpos(AGENT_NAME, '-') + 1)) then upper(substr(AGENT_NAME, strpos(AGENT_NAME, '-') + 1))
else null else null
end AS LANGUAGES end AS LANGUAGES,
from last_agent_calls timestamp
where row_n = 1 from ${ref("stg_calls")}
), ),
all_agents as ( all_agents as (
select * from agent_digital_dedup select * from agent_digital
union distinct union distinct
select * from agent_calls_dedup select * from agent_calls
),
all_agents_dedup as(
select *,
ROW_NUMBER ()
OVER (partition by AGENT_ID order by timestamp desc) row_n
from all_agents
) )
select all_agents.AGENT_ID, select all_agents_dedup.AGENT_ID,
all_agents.AGENT_NAME, all_agents_dedup.AGENT_NAME,
all_agents.LANGUAGES, all_agents_dedup.LANGUAGES,
ml.CODE, ml.CODE,
all_agents.AGENT_GROUP, all_agents_dedup.AGENT_GROUP,
ag.AGENT_GROUP_ID ag.AGENT_GROUP_ID
from all_agents from all_agents_dedup
left join ${ref("stg_MAPPING_AGENT_GROUP")} ag left join ${ref("stg_MAPPING_AGENT_GROUP")} ag
on all_agents.AGENT_GROUP = ag.AGENT_GROUP on all_agents_dedup.AGENT_GROUP = ag.AGENT_GROUP
left join ${ref("stg_MAPPING_LANGUAGES")} ml left join ${ref("stg_MAPPING_LANGUAGES")} ml
on upper(all_agents.LANGUAGES) = upper(ml.LANGUAGE) on upper(all_agents_dedup.LANGUAGES) = upper(ml.LANGUAGE)
order by agent_id where row_n = 1