Skip to content

Commit f3e117f

Browse files
Bug/duplicate user role histories (#208)
* bug/duplicate-user-role-histories * bug/duplicate-user-role-histories * add dedupe * pre-release * udpate version * changelog * Generate dbt docs via GitHub Actions --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 2b9703c commit f3e117f

File tree

6 files changed

+30
-15
lines changed

6 files changed

+30
-15
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# dbt_zendesk v1.0.1
2+
This is the general release of v0.25.1-a1. [PR #208](https://github.com/fivetran/dbt_zendesk/pull/208) includes the following updates:
3+
4+
## Bug Fixes
5+
- Fixed uniqueness issue in `int_zendesk__user_role_history` by removing duplicate and erroneous logs with identical timestamps.
6+
17
# dbt_zendesk v1.0.0
28

39
[PR #211](https://github.com/fivetran/dbt_zendesk/pull/211) includes the following updates:
@@ -18,6 +24,12 @@
1824
- Removed all `dbt_utils.unique_combination_of_columns` tests.
1925
- Moved `loaded_at_field: _fivetran_synced` under the `config:` block in `src_zendesk.yml`.
2026

27+
# dbt_zendesk v0.25.1-a1
28+
[PR #208](https://github.com/fivetran/dbt_zendesk/pull/208) includes the following updates:
29+
30+
## Bug Fixes
31+
- Fixed uniqueness issue in `int_zendesk__user_role_history` by removing duplicate and erroneous logs with identical timestamps.
32+
2133
# dbt_zendesk v0.25.0
2234

2335
## Schema/Data Changes

dbt_project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'zendesk'
2-
version: '1.0.0'
2+
version: '1.0.1'
33

44
config-version: 2
55
require-dbt-version: [">=1.3.0", "<2.0.0"]

docs/catalog.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/manifest.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

integration_tests/dbt_project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
config-version: 2
22

33
name: 'zendesk_integration_tests'
4-
version: '1.0.0'
4+
version: '1.0.1'
55

66
profile: 'integration_tests'
77

models/intermediate/int_zendesk__user_role_history.sql

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ with audit_logs as (
44
select
55
source_relation,
66
source_id as user_id,
7-
source_label as user_name,
87
created_at,
98
lower(change_description) as change_description
109
from {{ ref('stg_zendesk__audit_log') }}
@@ -21,9 +20,7 @@ with audit_logs as (
2120
select
2221
source_relation,
2322
user_id,
24-
user_name,
2523
created_at,
26-
change_description,
2724
-- extract and split change description for the support role
2825
trim({{ dbt.split_part(zendesk.extract_support_role_changes('change_description'), "' to '", 1) }}) as from_role,
2926
trim({{ dbt.split_part(zendesk.extract_support_role_changes('change_description'), "' to '", 2) }}) as to_role,
@@ -32,30 +29,38 @@ with audit_logs as (
3229
min(created_at) over (partition by source_relation, user_id) as min_created_at_per_user
3330
from audit_logs
3431

32+
), split_to_from_deduped as (
33+
select
34+
source_relation,
35+
user_id,
36+
created_at,
37+
from_role,
38+
to_role,
39+
min_created_at_per_user
40+
from split_to_from
41+
where from_role != to_role
42+
{{ dbt_utils.group_by(6) }}
43+
3544
-- Isolates the first "from" role as the base
3645
), first_roles as (
3746
select
3847
source_relation,
3948
user_id,
40-
user_name,
41-
change_description,
4249
cast(null as {{ dbt.type_timestamp() }}) as valid_starting_at, --fill in with created_at of user later
4350
created_at as valid_ending_at, -- this it the created_at of the audit log entry
4451
from_role as role
45-
from split_to_from
52+
from split_to_from_deduped
4653
where created_at = min_created_at_per_user
4754

4855
-- Captures all subsequent "to" roles
4956
), role_changes as (
5057
select
5158
source_relation,
5259
user_id,
53-
user_name,
54-
change_description,
5560
created_at as valid_starting_at,
5661
lead(created_at) over (partition by source_relation, user_id order by created_at asc) as valid_ending_at,
5762
to_role as role
58-
from split_to_from
63+
from split_to_from_deduped
5964

6065
), unioned as (
6166
select *
@@ -74,7 +79,6 @@ with audit_logs as (
7479
lower(coalesce(unioned.role, users.role)) as role,
7580
coalesce(unioned.valid_starting_at, users.created_at, cast('1970-01-01' as {{ dbt.type_timestamp() }})) as valid_starting_at,
7681
coalesce(unioned.valid_ending_at, {{ dbt.current_timestamp() }}) as valid_ending_at,
77-
unioned.change_description,
7882
-- include these in case they're needed for the internal_user_criteria
7983
users.external_id,
8084
users.email,
@@ -101,7 +105,6 @@ with audit_logs as (
101105
role,
102106
valid_starting_at,
103107
valid_ending_at,
104-
change_description,
105108

106109
{% if var('internal_user_criteria', false) -%} -- apply the filter to historical roles if provided
107110
role in ('admin', 'agent') or {{ var('internal_user_criteria', false) }} as is_internal_role

0 commit comments

Comments
 (0)