Skip to content

Commit 112010d

Browse files
authored
Update rentsense_former_tenants_to_refined.py
Adding a bit to only get the payment ref that has ended most recently.
1 parent 5aa3277 commit 112010d

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

scripts/jobs/rentsense_former_tenants_to_refined.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
datediff,
2424
when,
2525
)
26+
from pyspark.sql.window import Window
2627
from scripts.helpers.helpers import (
2728
PARTITION_KEYS,
2829
add_import_time_columns,
@@ -980,23 +981,21 @@ def export_dynamic_frame_as_xml_gzip(
980981
case_priorities, accounts4.tenancy_ref == case_priorities.tenancy_ref2, "left"
981982
)
982983

983-
accounts6 = accounts5.selectExpr(
984-
"AccountReference as AccountReference",
985-
# "TenureType",
986-
# "TenureTypeCode",
987-
# "max_date as TenancyStartDate",
984+
w = Window.partitionBy("AccountReference").orderBy(F.col("TenancyEndDate").desc())
985+
986+
accounts6 = (
987+
accounts5
988+
.withColumn("rn", F.row_number().over(w))
989+
.filter(F.col("rn") == 1)
990+
.selectExpr(
991+
"AccountReference",
988992
"TenancyEndDate",
989993
"LocalAuthority",
990-
# "HousingOfficerName",
991994
"Patch",
992995
"'Hackney' as Region",
993-
# "import_date as import_date",
994-
# "tenancy_ref as TenReference",
995-
# "is_paused_until as BreathingSpaceEndDate",
996-
"Case when Deceased=1 then 'Y' else 'N' end as Deceased"
997-
# "previousweekbalance"
996+
"case when Deceased=1 then 'Y' else 'N' end as Deceased"
998997
)
999-
998+
)
1000999
accounts7 = accounts6.filter("AccountReference is not null")
10011000

10021001
accounts8 = accounts7.distinct()

0 commit comments

Comments
 (0)