Skip to content

IN 1200 - Remove 2019 data cutoff #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hrqb/tasks/sql/employee_appointments.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CHANGELOG
- 2024-05-13 Query created and added
- 2024-06-03 Limit rows to appointments that end on or before 2019-01-01
- 2024-06-05 Do not filter on benefits types
- 2025-02-05 Remove 2019-01-01 date cutoff entirely

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, curious why you included this in the changelog if no changes -- beyond this updated comment -- are present in this script?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it got lost in the diff, but this was removed in this file:

where a.APPT_END_DATE >= TO_DATE('2019-01-01', 'YYYY-MM-DD')

*/

select distinct
Expand Down Expand Up @@ -61,5 +62,4 @@ left join HR_POSITION p on p.HR_POSITION_KEY = a.HR_POSITION_KEY
left join BENEFITS_ELIGIBILITY_CURRENT bec on
bec.MIT_ID = a.MIT_ID
and a.PERSONNEL_KEY = bec.PERSONNEL_KEY
where a.APPT_END_DATE >= TO_DATE('2019-01-01', 'YYYY-MM-DD')
order by a.MIT_ID, a.APPT_BEGIN_DATE, a.APPT_END_DATE
6 changes: 2 additions & 4 deletions hrqb/tasks/sql/employee_leave.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Query for Employee Leaves.
CHANGELOG
- 2024-05-13 Query created and added
- 2024-07-23 Added HR_POSITION.POSITION ID to select
- 2025-02-05 Remove 2019-01-01 date cutoff entirely
*/

select distinct
Expand All @@ -25,8 +26,5 @@ from HR_ABSENCE_DETAIL abse
inner join HR_APPOINTMENT_DETAIL appt on abse.MIT_ID = appt.MIT_ID
inner join HR_ABSENCE_TYPE at on at.HR_ABSENCE_TYPE_KEY = abse.HR_ABSENCE_TYPE_KEY
left join HR_POSITION p on p.HR_POSITION_KEY = appt.HR_POSITION_KEY
where (
appt.APPT_END_DATE >= TO_DATE('2019-01-01', 'YYYY-MM-DD')
and abse.ABSENCE_DATE between appt.APPT_BEGIN_DATE and appt.APPT_END_DATE
)
where abse.ABSENCE_DATE between appt.APPT_BEGIN_DATE and appt.APPT_END_DATE
order by appt.MIT_ID, abse.ABSENCE_DATE
2 changes: 1 addition & 1 deletion hrqb/tasks/sql/employee_leave_balances.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Query for Employee Leave Balances.
CHANGELOG
- 2024-09-26 Query created and added
- 2024-09-26 Filter to employees with appointment end dates >= 2019
- 2025-02-05 Remove 2019-01-01 date cutoff entirely
*/

select
Expand All @@ -24,5 +25,4 @@ and b.MIT_ID in (
select
a.MIT_ID
from HR_APPOINTMENT_DETAIL a
where a.APPT_END_DATE >= TO_DATE('2019-01-01', 'YYYY-MM-DD')
)
4 changes: 2 additions & 2 deletions hrqb/tasks/sql/employee_salary_history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CHANGELOG
- 2024-06-03 Date limit to appointments ending after 2019-01-01
- 2024-07-24 Added appointment begin/end date to help match appointments
- 2024-09-18 Omit any HR_PERSONNEL_ACTION_TYPE rows where type is "Salary Supplement"
- 2025-02-05 Remove 2019-01-01 date cutoff entirely
*/

select distinct
Expand Down Expand Up @@ -45,6 +46,5 @@ inner join HR_APPOINTMENT_DETAIL appt on appt.HR_APPT_KEY = a.HR_APPT_KEY
left join HR_PERSONNEL_ACTION_TYPE at on at.HR_PERSONNEL_ACTION_TYPE_KEY = a.HR_PERSONNEL_ACTION_TYPE_KEY
left join HR_JOB j on j.HR_JOB_KEY = a.HR_JOB_KEY
left join HR_POSITION p on p.HR_POSITION_KEY = a.HR_POSITION_KEY
where a.APPT_END_DATE >= TO_DATE('2019-01-01', 'YYYY-MM-DD')
and at.HR_PERSONNEL_ACTION not in ('Salary Supplement')
where at.HR_PERSONNEL_ACTION not in ('Salary Supplement')
order by a.MIT_ID, a.APPT_TX_BEGIN_DATE, a.APPT_TX_END_DATE
16 changes: 13 additions & 3 deletions hrqb/tasks/sql/employees.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ CHANGELOG
- 2024-10-08
- reworked CTEs to provide details about last library appointment only
- move > 2019 filtering to HR_PERSON_EMPLOYEE in ordered_lib_appt MIT_IDs
- 2025-02-05 Remove 2019-01-01 date cutoff entirely
- 2025-02-05 Add CTE 'last_appt_termination_txn' to ensure only the last termination
reason is included to avoid duplicating employee rows
*/

-- get all library appointments for employee, ordered
Expand All @@ -26,7 +29,6 @@ with ordered_lib_appt as (
order by APPT_BEGIN_DATE desc, APPT_END_DATE desc
) as appt_row_num
from HR_APPOINTMENT_DETAIL
where APPT_END_DATE >= TO_DATE('2019-01-01', 'YYYY-MM-DD')
),
-- select only the last / current appointment for employee
last_lib_appt as (
Expand All @@ -40,19 +42,27 @@ appt_termination_txns as (
ad.MIT_ID,
ad.HR_POSITION_KEY,
at.HR_PERSONNEL_ACTION,
at.HR_ACTION_REASON as TERMINATION_REASON
at.HR_ACTION_REASON as TERMINATION_REASON,
row_number() over (
partition by MIT_ID
order by APPT_BEGIN_DATE desc, APPT_END_DATE desc
) as termination_txn_row_num
from HR_APPT_ACTION_DETAIL ad
left join HR_PERSONNEL_ACTION_TYPE at on at.HR_PERSONNEL_ACTION_TYPE_KEY = ad.HR_PERSONNEL_ACTION_TYPE_KEY
where at.HR_PERSONNEL_ACTION in ('Retirement','Termination')
),
last_appt_termination_txn as (
select * from appt_termination_txns
where termination_txn_row_num = 1
),
Comment on lines +46 to +57
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of the row_number() sorts the termination reasons, and the new last_appt_termination_txn CTE allows for getting only the most recent one, i.e. the "last" termination reason.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I follow! Hmm, is there every a scenario like the following?:

[{
    "APPT_BEGIN_DATE": "2024-01-01", 
    "APPT_END_DATE": "2025-01-01",
    "termination_txn_row_num":  1
   }, 
 {
   "APPT_BEGIN_DATE": "2023-12-31"
   "APPT_END_DATE": "2025-02-01"
   "termination_txn_row_num": 2
 }]

-- combine CTEs above to get last / current appointment end date and termination reason
last_lib_appt_details as (
select
lla.MIT_ID,
lla.APPT_END_DATE as LAST_LIB_APPT_END_DATE,
att.TERMINATION_REASON
from last_lib_appt lla
left join appt_termination_txns att on (
left join last_appt_termination_txn att on (
att.MIT_ID = lla.MIT_ID
and att.HR_POSITION_KEY = lla.HR_POSITION_KEY
)
Expand Down