Skip to content

47. Files VACUUM Can Delete

Difficulty: Medium · Topics: Joins, Aggregations, Dates, Filtering & Selection

The transaction log has version, day ('YYYY-MM-DD'), action ('add' / 'remove') and path. today holds one row with the current day.

VACUUM may delete a file only if it is not in the current table (its latest action is a remove) and that remove happened at least 7 days before today. Return path and removed_on (the day of that latest remove) for every deletable file.

Row order does not matter; column names must match. Your code is graded on 3 test cases, including hidden edge cases.

Sample data

log

versiondayactionpath
02025-03-01addf1
02025-03-01addf2
12025-03-02removef1
12025-03-02addf3
22025-03-10removef2
22025-03-10addf4

today

day
2025-03-12

Expected output

pathremoved_on
f12025-03-02

Hints

Hint 1Per path, find the latest action and its day: max_by works for both, ordered by version.
Hint 2Files whose latest action is an add are live and never deletable, even if they were removed earlier.
Hint 3F.datediff(today_day, removed_on) >= 7; bring the one-row today table in with a cross join.

Learn the concepts

PySpark functions you'll practise

Related problems

Browse

Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings

Difficulty: Easy · Medium · Hard · PySpark interview roadmap · Learn · All problems