Follow one action from the DAG to stages cut at shuffles to one task per partition — and find it in the Spark UI.
Every DataFrame operation is one of two kinds. Transformations — filter, select, withColumn, groupBy().agg(), join — return a new DataFrame and only extend the plan. Actions — count, collect, show, take, write — need an actual result, so they make the driver run the plan.
Until the last line below, Spark has read nothing but file metadata. The write is the action: it becomes a job, the job is cut into stages, and each stage runs as tasks on the executors.
from pyspark.sql import functions as F
orders = spark.read.parquet("s3://lake/orders/")
paid = (orders
.filter(F.col("status") == "paid") # narrow
.select("country", "amount")) # narrow
revenue = (paid.groupBy("country") # wide: shuffle
.agg(F.sum("amount").alias("revenue")))
# the action: only now does Spark run anything
revenue.write.mode("overwrite").parquet("s3://lake/revenue/")Reach the last step for the run summary: the key takeaways from this lesson.