Brief
Diagnose an overloaded partition and choose a suitable redistribution without assuming it removes every imbalance.
The trip map fills up. Three workers finish quickly; a fourth still handles D7 passages. Voss wants to delete 'repeated' trips to accelerate the job, which could erase the lead. Mara asks for a diagnosis without touching originals. The meeting presses the characters, but the exercise has no timer.
Your mission
- Calculate total rows and the ratio between maximum and median loads.
- Explain what a shuffle does when grouping by depot.
- Say whether repartitioning by trip_id guarantees that D7 is fixed.
- State the counts that any optimized output must retain.
How to check your work
- 18 trips; ratio 6.
- Shuffle gathers rows sharing a key.
- No: independent per-trip work may balance, then groupBy gathers D7.
- D7=12, D8=D9=D10=2, total 18.
Course example
from collections import Counter
from statistics import median
depot_counts = Counter({"D7": 12, "D8": 2, "D9": 2, "D10": 2})
loads_by_depot = sorted(depot_counts.values())
balanced_row_tasks = [5, 5, 4, 4]
print("rows", sum(loads_by_depot))
print("depot_loads", loads_by_depot)
print("largest_to_median", max(loads_by_depot) / median(loads_by_depot))
print("hypothetical_row_tasks", balanced_row_tasks)
print("same_rows", sum(balanced_row_tasks) == sum(loads_by_depot))