How Spark plans your code Work in progress
This lab is still in development and is not yet complete. Features, lessons and animations may change.
Write code and follow the plan
Build a small program, then watch the driver plan it and executor tasks read their input partitions.
This is an educational simulation. DuckDB verifies the result on eight sessions from the ticketing database. The source preview is teaching data, not the driver’s collected result.
Your small program
Use event_sessions, an optional numeric capacity filter, then select(...) or groupBy("event_id").agg(F.sum("capacity").alias(...)). collect() requests the result. Other Python is not executed. Changing the code starts a fresh walkthrough.
Choose an example, then explain the plan. No simulated job has started.
From PySpark to working partitions
PySpark for this step
Orange marks the instruction related to this animation. One source line may generate multiple physical operators; it is not one line per task.
Scheduling uses free task slots and data locality. Equal totals are not guaranteed. Key hashes choose shuffle partitions, not executors.
Driver
Sends instructions and partition references. Source rows are read by executor tasks.
External dataset · event_sessions
8 source rowsTeaching preview of storage, not rows collected on the driver.
Executor 0
1 core · at most 1 running task
Idle
Executor 1
1 core · at most 1 running task
Idle
Is distribution equal, random, or based on a hash?
Input partitions: scan partitions depend on the data source, files, splits and configuration. This lesson explicitly prepares four partitions of two rows; real partitions need not have the same size.
Tasks → executors: the scheduler considers available resources and preferred data locations. A free executor may process another partition while a different executor is still busy. There is no guarantee of equal totals, and partitions do not permanently belong to executors.
Shuffle by key: a hash can map a grouping key to a target partition. Equal keys must reach the same target partition; equal row counts are not guaranteed. That partition’s task is then scheduled on an executor. Hash partitioning does not select the executor itself.
This animation shows planning and input reads. Processing between task waves is summarized. This view does not animate every transformation or the full shuffle. Completed input previews are history, not a cache. Placements and timings are illustrative, and AQE is off.
Spark Pill 2 · Plans and DAGs · Spark Pill 3 · Shuffle · Spark · Data locality · Spark · Cluster overview
The animation uses the same eight prepared source rows throughout. This static site simulates Spark; DuckDB checks the result and does not supply Spark execution metrics.
Connect the animation to Spark Pills
Pill 2 · Lazy evaluation and DAG Pill 3 · The shuffle Explore the complete seriesModel assumptions and sources
These are simplified Spark 3.5-style batch scenarios with AQE disabled, no pre-existing key partitioning, no cache, no retries and no modeled spills. The planning lab arranges eight source rows into four teaching partitions. The playground assigns source partitions round-robin. Shuffle uses an illustrative hash, not Spark’s hash. Task slots assume one CPU per task. Animation ticks are not timings or performance predictions.
A grouped sum/count uses partial aggregation before exchange and final aggregation after exchange. The narrow select scenario has no exchange. Real physical plans, stage counts, partitioning and task placement depend on configuration, data sources, optimizations and runtime statistics. Loading the DuckDB sample is lab setup; it does not demonstrate a Spark read or measure Spark I/O.
Tasks execute work. Data blocks, rather than tasks, may be stored. Shuffle files, cached partitions and memory spills are distinct; these scenarios model shuffle outputs only.
References: Spark cluster overview, shuffle operations, adaptive query execution.