Skip to content

Commit

Permalink
Mm 61860 add email to nps feedback (#1670)
Browse files Browse the repository at this point in the history
* MM-61860: Add email to nps feedback

* Add email to final table
  • Loading branch information
ifoukarakis authored Nov 19, 2024
1 parent a76661a commit f61e630
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 49 deletions.
12 changes: 8 additions & 4 deletions transform/snowflake-dbt/models/mattermost/hourly/nps_data.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{{config({
"materialized": 'incremental',
"materialized": "incremental",
"on_schema_change": "append_new_columns",
"schema": "mattermost",
"unique_key":'id',
"tags":["nightly"]
"unique_key": "id",
"tags": ["nightly"]
})
}}

Expand All @@ -17,7 +18,7 @@ daily_nps_scores AS (
WITH daily_nps_scores AS (
{% endif %}

SELECT timestamp::date as date
SELECT timestamp::date as date
, license_id
, server_version
, user_role
Expand Down Expand Up @@ -74,6 +75,7 @@ daily_feedback_scores AS (
timestamp::date as date
, user_actual_id
, feedback
, null as email
, id as feedback_id
FROM (
SELECT ROW_NUMBER() over (PARTITION BY nps.timestamp::DATE, nps.user_actual_id ORDER BY nps.timestamp DESC) AS rownum, nps.*
Expand All @@ -92,6 +94,7 @@ daily_feedback_scores AS (
timestamp::date as date
, COALESCE(useractualid, user_actual_id) as user_actual_id
, feedback
, email
, id as feedback_id
FROM (
SELECT ROW_NUMBER() over (PARTITION BY nps.timestamp::DATE, COALESCE(nps.useractualid, nps.user_actual_id) ORDER BY nps.timestamp DESC) AS rownum, nps.*
Expand All @@ -118,6 +121,7 @@ daily_feedback_scores AS (
daily_nps_scores.user_actual_id AS user_id,
daily_nps_scores.user_id AS server_id,
daily_feedback_scores.feedback,
daily_feedback_scores.email,
daily_nps_scores.timestamp,
daily_nps_scores.nps_id,
daily_feedback_scores.feedback_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{{config({
"materialized": 'incremental',
"unique_key": 'id',
"materialized": "incremental",
"unique_key": "id",
"on_schema_change": "append_new_columns",
"schema": "mattermost",
"tags":["nightly"]
"tags": ["nightly"]
})
}}

Expand Down Expand Up @@ -42,47 +43,6 @@ min_nps AS (
AND d.date <= current_date
GROUP BY 1, 2, 3
),

daily_feedback_scores AS (

SELECT
timestamp::date as date
, timestamp::timestamp AS timestamp
, id
, user_id as server_id
, COALESCE(user_actual_id, null) as user_id
, feedback
FROM (
SELECT ROW_NUMBER() over (PARTITION BY timestamp::DATE, COALESCE(user_actual_id, null) ORDER BY timestamp DESC) AS rownum, *
FROM {{ source('mattermost_nps', 'nps_feedback') }}
WHERE TIMESTAMP::DATE <= CURRENT_DATE
{% if is_incremental() %}
AND TIMESTAMP::date >= (SELECT MAX(date) from {{this}})
{% endif %}
)
where rownum = 1

UNION ALL

SELECT
timestamp::date as date
, timestamp::timestamp as timestamp
, id
, user_id as server_id
, COALESCE(user_actual_id, useractualid) as user_id
, feedback
FROM (
SELECT ROW_NUMBER() over (PARTITION BY timestamp::DATE, COALESCE(user_actual_id, useractualid) ORDER BY timestamp DESC) AS rownum, *
FROM {{ source('mm_plugin_prod', 'nps_nps_feedback') }}
WHERE TIMESTAMP::DATE <= CURRENT_DATE
{% if is_incremental() %}
AND TIMESTAMP::date >= (SELECT MAX(date) from {{this}})
{% endif %}
)
WHERE rownum = 1

),

max_date_by_month AS (
SELECT
d.date
Expand Down Expand Up @@ -131,7 +91,7 @@ min_nps AS (
ELSE 'Promoter' END AS promoter_type
, nps.user_create_at::DATE AS user_created_at
, nps.server_install_date::DATE AS server_install_date
, LISTAGG(DISTINCT nps.feedback, '; ') WITHIN GROUP (ORDER BY nps.feedback) AS feedback
, LISTAGG(DISTINCT nps.feedback, '; ') WITHIN GROUP (ORDER BY nps.feedback) AS feedback
, MAX(nps.timestamp::DATE) AS last_feedback_date
, m.responses
, m.promoter_responses
Expand All @@ -142,6 +102,7 @@ min_nps AS (
, m.feedback_count
, m.feedback_count_alltime
, m.id
, LISTAGG(DISTINCT nps.email, '; ') WITHIN GROUP (ORDER BY nps.email) AS email
FROM max_date_by_month m
JOIN daily_nps_scores nps
ON m.server_id = nps.server_id
Expand Down

0 comments on commit f61e630

Please sign in to comment.