A DataFrame recomputed three times, a slow Python UDF and one giant executor per node: three fixes for one job.
A feature job builds one expensive DataFrame (a join, a Python UDF and a window) and writes three outputs from it. It takes 72 minutes; the Jobs tab shows three jobs that each re-read 800 GB and redo the join, and the Executors tab shows GC eating 28% of task time.
DataFrames are recipes, not results: every action replays the whole lineage from the source. This lesson fixes the recomputation, the UDF and the executor shape, and covers when the usual cures (cache, collect, bigger executors) make things worse.
from pyspark.sql import Window, functions as F
w = Window.partitionBy("user_id").orderBy(F.desc("ts"))
feat = (events.join(users, "user_id")
.withColumn("score", score_udf("amount", "clicks")) # Python UDF
.withColumn("rank", F.row_number().over(w)))
feat.groupBy("country").count().write.parquet("s3://out/daily/")
feat.filter("rank <= 10").write.parquet("s3://out/top10/")
feat.write.parquet("s3://out/features/")Reach the last step for the run summary: the key takeaways from this lesson.