How do you diagnose and resolve data skew in a Spark cluster when processing multi-terabyte datasets?
Implement plan_skew_mitigation(partition_loads, target_ratio) to model this decision algorithmically. Given an array of nonnegative partition loads and an integer target ratio, use the lower median load as the baseline and return an array of split factors. Each factor must be the minimum number of tasks needed to keep that partition at or below target_ratio * median, with a minimum threshold of 1 when the median is zero.
def plan_skew_mitigation(partition_loads, target_ratio):