Fix missing job_changes (position id not unique, no initial job_change
for first position) and fix duplicate workers (department fall-back joining didn't consider duplicate naming of multiple levels)
This commit is contained in:
@@ -17,12 +17,7 @@ latest_departments AS (
|
|||||||
FROM {{ ref('department') }}
|
FROM {{ ref('department') }}
|
||||||
),
|
),
|
||||||
|
|
||||||
positions_deduped AS (
|
-- note: Positions ID is not unique, hence removed the deduplication logic
|
||||||
SELECT DISTINCT ON (position_id) *
|
|
||||||
FROM {{ source('tap_spreadsheets_anywhere', 'positions') }}
|
|
||||||
WHERE _sdc_deleted_at IS NULL
|
|
||||||
ORDER BY position_id, _sdc_received_at DESC
|
|
||||||
),
|
|
||||||
|
|
||||||
transformed_worker AS (
|
transformed_worker AS (
|
||||||
SELECT worker_hris_id, id
|
SELECT worker_hris_id, id
|
||||||
@@ -41,12 +36,12 @@ position_details AS (
|
|||||||
p.assigned_employee_effective_date::DATE AS new_job_effective_date,
|
p.assigned_employee_effective_date::DATE AS new_job_effective_date,
|
||||||
p.fte_utilized_by_employee_in_this_position * 100 AS new_fte_percentage,
|
p.fte_utilized_by_employee_in_this_position * 100 AS new_fte_percentage,
|
||||||
tw.id as worker_id
|
tw.id as worker_id
|
||||||
FROM positions_deduped p
|
FROM transformed_worker tw
|
||||||
LEFT JOIN latest_workers w
|
LEFT JOIN {{ source('tap_spreadsheets_anywhere', 'positions') }} p
|
||||||
ON p.assigned_employee_id = w.user_id
|
ON p.assigned_employee_id = tw.worker_hris_id
|
||||||
LEFT JOIN latest_departments d
|
LEFT JOIN latest_departments d
|
||||||
ON p.assigned_unit_id = d.department_hris_id
|
ON p.assigned_unit_id = d.department_hris_id
|
||||||
LEFT JOIN transformed_worker tw ON tw.worker_hris_id = w.user_id
|
LEFT JOIN latest_workers w ON tw.worker_hris_id = w.user_id
|
||||||
),
|
),
|
||||||
|
|
||||||
job_changes_with_history AS (
|
job_changes_with_history AS (
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ joined_data AS (
|
|||||||
LEFT JOIN {{ ref('department') }} d -- Source = Department from Positions report, only relevant for active workers
|
LEFT JOIN {{ ref('department') }} d -- Source = Department from Positions report, only relevant for active workers
|
||||||
ON p.assigned_unit_id = d.department_hris_id
|
ON p.assigned_unit_id = d.department_hris_id
|
||||||
LEFT JOIN {{ ref('department') }} d2 -- Source = Business Unit from All Users report, only relevant for inactive workers
|
LEFT JOIN {{ ref('department') }} d2 -- Source = Business Unit from All Users report, only relevant for inactive workers
|
||||||
ON w.business_unit = d2.name
|
ON w.business_unit = d2.name AND nlevel(d2.path) = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
|
|||||||
Reference in New Issue
Block a user