diff --git a/definitions/staging/stg_AGENT.sqlx b/definitions/staging/stg_AGENT.sqlx index c7fec84..666bedb 100644 --- a/definitions/staging/stg_AGENT.sqlx +++ b/definitions/staging/stg_AGENT.sqlx @@ -9,6 +9,11 @@ config { description: "All fields that are connected to the AGENT" } +/* +Originally AGENT_NAME field contains both name and languages of the agent. +They can be divined by different variations of signs. Next 2 subqueries extract AGENT_NAME and LANGUAGES +into 2 different fields for calls and digital data. +*/ with agent_digital as ( select AGENT_ID, case @@ -61,12 +66,13 @@ agent_calls as ( timestamp from ${ref("stg_calls")} ), +-- Union of the agents for digital and calls all_agents as ( select * from agent_digital union distinct select * from agent_calls ), - +-- Deduplication by AGENT_ID and Timestamp. It is necessary because agent characteristics can change over time all_agents_dedup as( select *, ROW_NUMBER () @@ -74,7 +80,7 @@ all_agents_dedup as( from all_agents ) - +-- Add of the codes and ids with mapings select all_agents_dedup.AGENT_ID, all_agents_dedup.AGENT_NAME, all_agents_dedup.LANGUAGES, diff --git a/definitions/staging/stg_calls.sqlx b/definitions/staging/stg_calls.sqlx index 9c8e0ae..be6f73d 100644 --- a/definitions/staging/stg_calls.sqlx +++ b/definitions/staging/stg_calls.sqlx @@ -9,7 +9,8 @@ config { dependencies: ["calls_data_freshness"], description: "All history data for calls" } - + +--Filter out abandoned calls and numerates by key for deduplication with calls_deduplicated as ( select *, ROW_NUMBER() @@ -17,7 +18,7 @@ select *, row_number from ${ref("pphe_five9_raw","calls_*")} where ABANDONED is not null -${ when(incremental(), `and _TABLE_SUFFIX = FORMAT_DATE('%Y%m%d',current_date("Europe/Amsterdam"))`) }) +${ when(incremental(), `and _TABLE_SUFFIX = FORMAT_DATE('%Y%m%d',current_date("Europe/Amsterdam"))`) }) --last date table is taken select DAY_OF_WEEK, CALL_ID, CAMPAIGN, @@ -26,6 +27,7 @@ select DAY_OF_WEEK, AGENT_NAME, ANI, CALL_TIME, + --time data is loaded in seconds. Extra columns for times in formt hh:mm:ss are added regexp_replace( cast(time(timestamp_seconds(cast(CALL_TIME as int))) as string), r'^\d\d', diff --git a/definitions/staging/stg_calls_history_report.sqlx b/definitions/staging/stg_calls_history_report.sqlx index 5210a0d..0fc58ce 100644 --- a/definitions/staging/stg_calls_history_report.sqlx +++ b/definitions/staging/stg_calls_history_report.sqlx @@ -12,6 +12,7 @@ config { description: "Main calls data for history report" } +--Extraction and transformation of fields that are used in Board load further. Contains all history data select sc.SESSION_ID, sc.DNIS, sc.TIMESTAMP, @@ -25,7 +26,7 @@ select sc.SESSION_ID, case when sc.ROUTING_HOTEL_NAME is null then '_' - else ifnull(p.BOARD_PROPERTY_GROUP, 'ADD') + else ifnull(p.BOARD_PROPERTY_GROUP, 'ADD') --for check of the missed properties end BOARD_PROPERTY_GROUP, sc.AGENT_ID, sc.AGENT_NAME, diff --git a/definitions/staging/stg_calls_report.sqlx b/definitions/staging/stg_calls_report.sqlx index edd93b7..7edb2b9 100644 --- a/definitions/staging/stg_calls_report.sqlx +++ b/definitions/staging/stg_calls_report.sqlx @@ -15,6 +15,7 @@ config { description: "Main calls data for report" } +--Extraction and transformation of fields that are used in Board load further. Contains last 7 days select sc.SESSION_ID, sc.DNIS, sc.TIMESTAMP, @@ -28,7 +29,7 @@ select sc.SESSION_ID, case when sc.ROUTING_HOTEL_NAME is null then '_' - else ifnull(p.BOARD_PROPERTY_GROUP, 'ADD') + else ifnull(p.BOARD_PROPERTY_GROUP, 'ADD') --for check of the missed properties end BOARD_PROPERTY_GROUP, sc.AGENT_ID, sc.AGENT_NAME, diff --git a/definitions/staging/stg_digital.sqlx b/definitions/staging/stg_digital.sqlx index 55cbf7c..0b9a320 100644 --- a/definitions/staging/stg_digital.sqlx +++ b/definitions/staging/stg_digital.sqlx @@ -10,16 +10,18 @@ config { description: "All history data for digital" } +--Numerates by key for deduplication with digital_deduplicated as ( select *, ROW_NUMBER() OVER (PARTITION BY SESSION_GUID) row_number from ${ref("pphe_five9_raw","digital_*")} -${ when(incremental(), `where _TABLE_SUFFIX = FORMAT_DATE('%Y%m%d',current_date("Europe/Amsterdam"))`) }) +${ when(incremental(), `where _TABLE_SUFFIX = FORMAT_DATE('%Y%m%d',current_date("Europe/Amsterdam"))`) }) --last date table is taken select AGENT_NAME, COALESCE(DISPOSITION, '[Not Defined]') AS DISPOSITION, RESPONSE_TIME, + --time data is loaded in seconds. Extra columns for times in formt hh:mm:ss are added regexp_replace( cast(time(timestamp_seconds(cast(RESPONSE_TIME as int))) as string), r'^\d\d', diff --git a/definitions/staging/stg_digital_history_report.sqlx b/definitions/staging/stg_digital_history_report.sqlx index 477794f..485a306 100644 --- a/definitions/staging/stg_digital_history_report.sqlx +++ b/definitions/staging/stg_digital_history_report.sqlx @@ -11,7 +11,7 @@ config { description: "Main digital history data for report" } - +--Extraction and transformation of fields that are used in Board load further. Contains all history data select d.SESSION_GUID, d.TIMESTAMP, date(d.TIMESTAMP) DATE, diff --git a/definitions/staging/stg_digital_report.sqlx b/definitions/staging/stg_digital_report.sqlx index 0f17213..c5bdae4 100644 --- a/definitions/staging/stg_digital_report.sqlx +++ b/definitions/staging/stg_digital_report.sqlx @@ -11,6 +11,7 @@ config { description: "Main digital data for report" } +--Extraction and transformation of fields that are used in Board load further. Contains last 7 days select d.SESSION_GUID, d.TIMESTAMP, date(d.TIMESTAMP) DATE,