IntermediateSpark · 14 min · 14 challenges

Catalyst Optimizer: Intermediate

A Netflix engineer's Spark job totals viewing hours per country and title, then keeps only Brazil. Read literally, it shuffles viewing data from every country. In practice only Brazil's data crosses the network, because Spark rewrote the query before any task started. Whether a rewrite like that happens, and where each shuffle lands, is what this lesson teaches you to read from the plan.

Analysis

Daily Life
Interviews

Every DataFrame call you chain, and every SQL string you hand to spark.sql, first becomes a tree of names Spark has not checked. The tree mentions a relation called order_items and a column called quantity, but nothing in it says whether either exists or what type the column holds. Analysis settles those questions. The driver walks the tree and resolves each name against the catalog, the registry of tables, views and functions your session knows about. No executor takes part.

DataFrame calls or SQL
Unresolved plan
catalog lookups
Analyzer
rewrite rules
Optimizer
strategies
Planner
tasks on executors
Physical plan

Each arrow carries the current tree: unresolved into the Analyzer, resolved into the Optimizer, optimized into the Planner. The 3 middle phases run on the driver, and only the physical plan turns into tasks.

What the analyzer fills in

Take a query that totals each order's line items, run against an order_items table whose quantity is an int and whose unit_price is a double. Calling explain(extended=True) prints the tree after every phase, and the first 2 trees show the analyzer's work.

query = """
SELECT
order_id,
SUM(quantity * unit_price) AS order_total
FROM order_items
GROUP BY order_id
"""
totals = spark.sql(query)
totals.explain(extended=True)
Parsed plan showsAnalyzed plan showsWhat the analyzer did
'UnresolvedRelation [order_items]Relation spark_catalog.default.order_items[...] parquetFound the table in the catalog and attached its columns and files
'quantityquantity#5Matched the name to a column of that table and gave it an ID
'SUM(...)sum(...)Found the function and resolved the type of its argument
('quantity * 'unit_price)(cast(quantity#5 as double) * unit_price#6)Cast the int side to double so both operands share a type
no schema lineorder_id: int, order_total: doubleWorked out the type of every output column

Watch for 2 marks. A leading apostrophe, as in 'quantity, means unresolved: a name with no column behind it yet. A # number, as in quantity#5, is an expression ID. Your session will print different numbers. What holds everywhere is that 2 columns printing the same name with different IDs are different columns, and every later phase tracks a column by its ID.

The cast in the fourth row is type coercion. Multiplication needs both operands to share a type, so the analyzer widens the int side to double. That cast exists in the analyzed plan and nowhere in your code, which makes the analyzed plan the first place to look when a comparison or a calculation behaves differently from what you wrote.

Analysis errors arrive before the action

The laziness lessons showed failures that wait for an action: the plan builds and the error appears once tasks run. Analysis keeps a different schedule. A DataFrame is analyzed when it is created, so a misspelled column raises an AnalysisException on the line that names it, before any job exists. When an error fires tells you which kind of mistake you are looking at.

✓Raised as the line runs
  • A column name the input does not have
  • A table or view missing from the catalog
  • A function name Spark does not recognize
  • In SQL, a selected column that is neither grouped nor aggregated
✗Raised at the action
  • A file deleted between planning and reading
  • A value that breaks a cast with spark.sql.ansi.enabled on
  • An executor running out of memory
  • A corrupt file in the input path

On a Spark Connect session the client sends the plan to the server without analyzing it, so the same misspelling raises at the first action or the first call that needs the schema.

Multiple Choice

Which call raises an exception, and at what moment?

from pyspark.sql import functions as F
orders = spark.table("orders")
completed = orders.filter(F.col("status") == "Completed")
totals = completed.groupBy("regoin").agg(F.sum("profit"))
rows = totals.collect()

Run the cell as written: it reads order_items, multiplies quantity by unit_price, and prints the first 5 rows. Then rename unit_price in the select to unit_prise and run again. The error arrives before show is reached, and it lists the columns it could have meant.

from pyspark.sql import functions as F

items = spark.table("order_items")
priced = items.select(
    "order_id",
    "quantity",
    "unit_price",
    (F.col("quantity") * F.col("unit_price")).alias("line_total"),
)
priced.filter(F.col("quantity") > 0).show(5)

Logical Optimization

Daily Life
Interviews

With every name resolved, the optimizer rewrites the tree into one that returns the same rows for less work. It works through rules. Each rule looks for a pattern, such as a Filter above an Aggregate, and swaps in an equivalent shape. Rules are grouped into batches, and most batches repeat until a full pass changes nothing or they reach spark.sql.optimizer.maxIterations, 100 by default. No rule reads data: the same tree gets the same rewrite whether the table holds 10 rows or 10 billion.

Rules you will meet in most plans

RuleBeforeAfterWhat it saves
PushDownPredicatesA Filter above a Project or AggregateThe Filter moved beneath itRows dropped before later steps touch them
ColumnPruningEvery column of the table carried upwardOnly the columns the query usesBytes carried through every step and shuffle
ConstantFoldingprofit > 10 * 100profit > 1000.0Arithmetic done once on the driver, not per row
CombineFilters2 filter calls in a row1 Filter joined by AND1 operator
CollapseProject3 chained withColumn calls1 Project2 operators
InferFiltersFromConstraintsstatus = 'Completed'isnotnull(status) AND status = 'Completed'An explicit null test later steps can rely on

A filter that moves below the groupBy

This program groups first and filters second, the order you might write it after deciding late that only the West matters.
from pyspark.sql import functions as F
orders = spark.table("orders")
by_region = orders.groupBy("region").agg(F.sum("profit").alias("total_profit"))
west = by_region.filter(F.col("region") == "West")
west.explain(extended=True)
Analyzed logical plan
Plan line
Filter (region#2 = West)
+- Aggregate [region#2], [region#2, sum(profit#3) AS total_profit#9]
+- SubqueryAlias spark_catalog.default.orders
+- Relation spark_catalog.default.orders[order_id#0,status#1,region#2,profit#3] parquet
Optimized logical plan
Plan line
Aggregate [region#2], [region#2, sum(profit#3) AS total_profit#9]
+- Project [region#2, profit#3]
+- Filter (isnotnull(region#2) AND (region#2 = West))
+- Relation spark_catalog.default.orders[order_id#0,status#1,region#2,profit#3] parquet

The optimizer fired 4 rules. EliminateSubqueryAliases removed the SubqueryAlias line, which only recorded the name the table was read under. PushDownPredicates moved the filter beneath the Aggregate, which is legal because the test reads only region, the grouping key: every row that lands in the West group started as a West row, so dropping the rest first cannot change West's total. InferFiltersFromConstraints added isnotnull(region#2). ColumnPruning inserted a Project so order_id and status stop travelling upward. The saving shows up at the shuffle the groupBy needs, which now receives West rows only.

The run below plays that program on 12 orders spread over 3 regions, ending in collect(). Watch each map task drop its East and North rows before computing a partial sum, so the shuffle carries only West sums.

from pyspark.sql import functions as F
by_region = orders.groupBy("region").agg(F.sum("profit").alias("total_profit"))
west = by_region.filter(F.col("region") == "West")
west.collect()
orders12 rows
order_id
status
region
profit
1
Completed
West
120
2
Completed
East
80
3
Returned
North
-20
4
Completed
West
200
5
Pending
East
45
6
Completed
North
60
7
Completed
West
90
8
Returned
West
-15
9
Completed
East
150
10
Pending
North
30
11
Completed
West
75
12
Completed
East
110
Preparing the animation

When a filter has to stay

A filter can move to a lower point only if every row there carries what the test reads. Below an Aggregate, a row has its grouping keys but no totals yet.

✓Moves lower in the plan
  • region == 'West' after groupBy('region'): it reads a grouping key only
  • margin > 5 after withColumn('margin', profit * 0.1): rewritten as profit * 0.1 > 5
  • The status test in status == 'Completed' AND total_profit > 0 after groupBy('status')
✗Stays where you wrote it
  • total_profit > 500 after the agg: the total exists only once the group is complete
  • status == 'Completed' OR total_profit > 0: an OR has no half that is safe to move alone
  • Any filter on a DataFrame rebuilt from an RDD: Catalyst cannot see into the RDD code
Multiple Choice

Which filter on summary does the optimizer move below the Aggregate?

from pyspark.sql import functions as F
summary = orders.groupBy("status", "region").agg(
F.sum("profit").alias("total"),
F.count("*").alias("n"),
)
TIP
Filters on grouping keys can go wherever they read best, since Catalyst moves them for you. Filters on aggregated values belong after the agg, and no rewrite, yours or Spark's, can run them sooner.

The cell groups the practice orders by status and keeps the Completed group. Run it, then move the filter above the groupBy and run again. The row that comes back is identical, and that equality is the whole licence the optimizer needs to make the move on its own.

from pyspark.sql import functions as F

orders = spark.table("orders")
by_status = orders.groupBy("status").agg(F.sum("profit").alias("total_profit"))
by_status.filter(F.col("status") == "Completed").show()

Physical Planning

Daily Life
Interviews

The optimized logical plan still says nothing about partitions, tasks or shuffles. The planner supplies those. It runs a list of strategies, each able to turn certain logical operators into physical ones, and produces a tree that can run as tasks. A logical Aggregate becomes 2 HashAggregate operators: a partial one that sums inside each task, then a final one that merges those sums per key. That pair is the combine-before-shuffle pattern you already know, chosen here by the planner.

Logical operatorPhysical operatorWhat changes
RelationFileScanReads the pruned columns, 1 task per input partition
FilterFilterThe same test, run inside each task
AggregatePartial HashAggregate, then final HashAggregateSums per task, then sums per key
Sort from orderBySort with global set to trueRows ordered across every partition
Sort from sortWithinPartitionsSort with global set to falseRows ordered inside each partition only
Repartition on a columnExchange hashpartitioningThe shuffle you asked for, on your key

Where the Exchanges come from

The logical plan never contained a shuffle. Exchange, the physical operator that performs one, is added after the strategies run, by a rule named EnsureRequirements. Each physical operator declares the partitioning it needs from its child and the partitioning it outputs. A final HashAggregate on region needs every row of a region inside 1 partition, while a FileScan outputs partitions that know nothing about region. Wherever a need meets an output that fails it, EnsureRequirements inserts an Exchange, and wherever an operator needs sorted input it lacks, a Sort.

OperatorNeeds from its childInserted when the need is unmet
Final HashAggregate on regionEvery row of a region in 1 partitionExchange hashpartitioning(region, 200)
Global Sort on total DESCPartitions holding consecutive ranges of totalExchange rangepartitioning(total DESC, 200)
Sort from sortWithinPartitionsNothing across partitionsNo Exchange
Filter or ProjectNothingNo Exchange

The 200 is spark.sql.shuffle.partitions, the default number of shuffle partitions, and the run below uses 3 so every task fits on screen. Before you play it, predict the Exchanges: the final aggregate needs each region clustered, and the global sort needs ranges of totals. The range shuffle also needs boundaries, so Spark samples the totals in a short job of its own, which your action triggers before the job that returns your rows.

from pyspark.sql import functions as F
totals = orders.groupBy("region").agg(F.sum("profit").alias("total"))
ranked = totals.orderBy(F.desc("total"))
ranked.collect()
orders12 rows
order_id
status
region
profit
1
Completed
West
120
2
Completed
East
80
3
Returned
North
-20
4
Completed
West
200
5
Pending
East
45
6
Completed
North
60
7
Completed
West
90
8
Returned
West
-15
9
Completed
East
150
10
Pending
North
30
11
Completed
West
75
12
Completed
East
110
Preparing the animation

When a requirement is already met

EnsureRequirements adds an Exchange only where the child's partitioning fails the need. After repartition(8, "region"), the rows of each region already sit in 1 partition, so a following groupBy("region") adds no shuffle. The test is looser than it first looks. Hashing on region also satisfies groupBy("region", "status"), because rows that share both values share region. The reverse fails: hashing on both columns scatters a single region across many partitions.

Child partitioned byThen groupBy onNew Exchange?
hash(region)regionNo
hash(region)region, statusNo: equal pairs already share a region
hash(region, status)regionYes: a region spans many partitions
A file scanregionYes: input partitions ignore region
TIP
A repartition("region") placed right before groupBy("region") slows the job. Its Exchange ships every raw row, while the groupBy's own Exchange would have shipped 1 partial sum per region per task. Repartition first only when several wide steps share that key and can reuse the 1 shuffle.

The planner's interface can return several candidate physical plans, but Spark takes the first. Choices between operators are made by checks inside each strategy, many of them comparing size estimates, the subject of the next section.

Multiple Choice

How many Exchange operators does the physical plan for this program contain?

by_status = orders.repartition(6, "status")
counts = by_status.groupBy("status", "region").count()
ranked = counts.orderBy("count")
rows = ranked.collect()

Cost-Based Optimization

Daily Life
Interviews

The logical rules fire on the shape of the tree alone. Other choices need sizes: how many rows survive a filter, how many groups an aggregate yields, which of 2 inputs is the small one. For those, Catalyst attaches a Statistics estimate to every logical operator. Cost-based optimization covers how the estimates are computed and what is decided from them. With spark.sql.cbo.enabled at its default of false, Spark estimates byte sizes only.

Where the numbers come from

StatisticWhere Spark gets itThere without ANALYZE?
Size in bytes of a file tableTotal size of its filesYes
Row countANALYZE TABLE ... COMPUTE STATISTICSNo
Distinct count, null count, average and max lengthANALYZE TABLE ... COMPUTE STATISTICS FOR COLUMNSNo
Min and maxThe column command, for numeric, date and timestamp columnsNo
HistogramThe column command with spark.sql.statistics.histogram.enabled on, same typesNo
from pyspark.sql import functions as F
spark.sql("ANALYZE TABLE orders COMPUTE STATISTICS FOR COLUMNS status, profit")
spark.conf.set("spark.sql.cbo.enabled", "true")
completed = spark.table("orders").filter(F.col("status") == "Completed")
completed.explain(mode="cost")

explain(mode="cost") prints the optimized logical plan with a Statistics(sizeInBytes=..., rowCount=...) entry on every line: the numbers the planner acts on.

Estimates with and without column statistics

Without column statistics, Spark propagates bytes alone, and its assumption for a filter is that every row survives: the filtered table is estimated at the full table's size. A Project scales the bytes by how much narrower its rows are, and an aggregate with no grouping keys is estimated at 1 row. With CBO on and column statistics present, Spark estimates what fraction a filter keeps. An equality test on a string keeps the row count divided by the distinct count. A range test on a number assumes values spread evenly between min and max, and tests joined by AND multiply their fractions.

Take an orders table of 40,000,000 rows in 1.6 GB of files, where status has 4 distinct values and profit runs from -50 to 950. In the real data, 28,000,000 orders are completed.

Plan stepBytes onlyCBO with column statsReal rows
Relation orders1.6 GB40,000,000 rows40,000,000
Filter status = 'Completed'1.6 GB10,000,000 rows28,000,000
Filter profit > 1001.6 GB34,000,000 rows31,000,000
Both filters, joined by AND1.6 GB8,500,000 rows24,000,000
2.8x
undercount for status = 'Completed'
18M
Completed rows the estimate misses

The status estimate misses because strings get no histogram, so Spark gives each of the 4 values an equal share while most real orders complete. The AND row misses for a second reason: Spark multiplies the fractions as if the 2 tests were unrelated, when completed orders are the ones that carry profit. Neither error is visible until a decision built on the estimate goes wrong.

Multiple Choice

CBO is on and orders was analyzed for columns this morning, with no rows added since. It holds 10,000,000 rows, and status has 5 distinct values and no nulls. What row count does Spark estimate for orders.filter(F.col("status") == "Cancelled")?

Statistics that go stale

Statistics are a snapshot saved in the catalog when ANALYZE runs. When Spark itself writes to the table, it discards the snapshot, or recomputes the size alone if spark.sql.statistics.size.autoUpdate.enabled is on. Files added by another process leave the old snapshot in place, and the planner trusts it: a table analyzed at 40,000,000 rows that has since tripled still plans as 40,000,000.

✓Do
  • Re-run ANALYZE after loads that change a table's size or the spread of its values
  • Collect column stats on the columns your filters and grouping keys use
  • Read explain(mode="cost") when a plan choice surprises you
✗Don't
  • Switch on spark.sql.cbo.enabled for unanalyzed tables and expect a change
  • Trust a distinct-count estimate on a column where 1 value dominates
  • Let other processes add files to a table whose stats the planner still reads
TIP
These estimates change plans mostly where the planner compares a size to a threshold to pick an operator, and the costliest such pick is how 2 tables get joined, which the joins lessons build on.

The cell measures the practice orders the way column statistics would. Divide total_rows by distinct_statuses to get the estimate for status = 'Completed', then set it beside completed_rows, the real count. The gap is the error any plan built on that estimate would carry.

from pyspark.sql import functions as F

orders = spark.table("orders")
orders.agg(
    F.countDistinct("status").alias("distinct_statuses"),
    F.count("*").alias("total_rows"),
    F.sum(F.when(F.col("status") == "Completed", 1).otherwise(0)).alias("completed_rows"),
).show()

Reading a Physical Plan

Daily Life
Interviews

explain() with no arguments prints the physical plan alone: the tree the executors will run. Read it from the bottom. The most indented line is where data enters, and each line above consumes the output of the line beneath it. A +- marks a child, and when an operator has 2 children, as a union does, the first hangs from :-.

from pyspark.sql import functions as F
txns = spark.table("transactions")
top_products = (
txns.filter(F.col("quantity") > 0)
.groupBy("product_id")
.agg(F.sum("total_amount").alias("revenue"))
.orderBy(F.desc("revenue"))
)
top_products.explain()
On a recent Spark version it prints the tree below, shown with its lines numbered in reading order.
ReadLine as printedWhat it tells you
topAdaptiveSparkPlan isFinalPlan=falseA wrapper for re-planning during the run, covered later; read the tree under it
7+- Sort [revenue#30 DESC NULLS LAST], true, 0Sorts within each range; true marks a global sort
6+- Exchange rangepartitioning(revenue#30 DESC NULLS LAST, 200), ENSURE_REQUIREMENTS, [plan_id=61]Range shuffle for orderBy, a stage boundary
5+- HashAggregate(keys=[product_id#22], functions=[sum(total_amount#24)])Final revenue per product
4+- Exchange hashpartitioning(product_id#22, 200), ENSURE_REQUIREMENTS, [plan_id=58]Hash shuffle the final aggregate needs, a stage boundary
3+- HashAggregate(keys=[product_id#22], functions=[partial_sum(total_amount#24)])Partial revenue per product inside each task
2+- Filter (isnotnull(quantity#23) AND (quantity#23 > 0))Your filter plus the inferred null test
1+- FileScan parquet [product_id#22,quantity#23,total_amount#24]Reads 3 columns; the full line goes on to list files and filters

Make 3 checks in every reading. Count the Exchange lines: 2 here, so the main work runs as 3 stages. The range boundaries add a short sampling job of their own, which reads the final aggregate's output once it is ready and finishes before the range shuffle writes. Read the tag after each Exchange: ENSURE_REQUIREMENTS means the planner inserted it to meet an operator's need, while REPARTITION_BY_COL (you passed only columns) or REPARTITION_BY_NUM (you passed a count) means a repartition in your code put it there. Then look below the first Exchange: the filter and the partial sum both run before any byte crosses the network, the cheapest place in the job for work to happen.

Multiple Choice

Which call sorts by_product by total_amount and leaves the repartition's Exchange as the only one in the plan?

by_product = spark.table("transactions").repartition("product_id")

You will also meet plans whose operators carry a *(1) or *(2) prefix, such as the plan of a finished query. The number groups operators Spark compiles into 1 function, a topic for a later lesson, and it never marks a shuffle.

Stage 0
Shuffle 1
Stage 1
Shuffle 2
Stage 2
Result
3 columns read
FileScan transactions
runs inside each task
Filter quantity > 0
sum per task
Partial HashAggregate
product_id
Hash Exchange
PARTITIONS200
sum per product
Final HashAggregate
revenue DESC
Range Exchange
PARTITIONS200
sort each range
Global Sort
collects rows in range order
Driver

The printed plan redrawn as stages, as it runs when the query ends in collect(). At each Exchange a stage's tasks write shuffle files and the next stage's tasks read them, so 2 Exchanges give 3 stages. Everything left of the first Exchange shrinks the bytes that cross it.

Multiple Choice

A query you wrote with no repartition call prints a plan with 2 Exchange lines, both tagged ENSURE_REQUIREMENTS: a hashpartitioning lower down and a rangepartitioning above it. What does that plan tell you?

From the plan to the Spark UI

The plan predicts the stages, and the Spark UI confirms them. In the Stages tab, each stage boundary should match an Exchange you counted. The tab also lists stages beyond those 3: the sampling job's, and some marked skipped because the run is split across several jobs, so match each stage to the shuffle it writes or reads. In the SQL tab, named SQL / DataFrame on recent versions, the same operator tree is drawn after the run with measured numbers on each box: output rows on the Filter, records and bytes written on each Exchange, rows out of each HashAggregate. When the query is slow, those numbers answer what the plan raised: did the filter cut as much as expected, did the partial aggregate shrink the rows before the shuffle, and how large was each shuffle.

A plan-reading checklist
  • ▸Count the Exchange lines; for a plan with 1 input, the main work runs in 1 more stage than that
  • ▸For each Exchange, note its key, its partition count and whether its tag names you or the planner
  • ▸Find each filter you wrote and confirm it sits below every shuffle it is allowed to pass
  • ▸Look for a partial HashAggregate beneath each hash Exchange that feeds an aggregate
  • ▸Check the scan's column list against the columns the query uses
Multiple Choice

This program draws on every phase of the lesson. Which description of its physical plan is right?

from pyspark.sql import functions as F
events = spark.table("user_events")
per_country = (
events.repartition("country")
.groupBy("country", "event_type")
.agg(F.count("*").alias("n"))
.filter(F.col("country") == "US")
)
per_country.explain()
❯❯❯PUTTING IT ALL TOGETHER

> At Netflix, a nightly Spark job totals viewing hours per country and title, keeps Brazil, and ranks the titles by hours for a regional dashboard.

Analysis resolves country, title and hours against the catalog and types the sum of the int hours column as bigint before any task runs, so a renamed column fails the job on the line that names it.
The Brazil filter tests a grouping key, so the optimizer pushes it under the aggregate and only Brazil's rows reach the shuffle.
The planner splits the aggregate into partial and final HashAggregates, inserts a hash Exchange on country and title, then a range Exchange for the ranking.
If the viewing table's statistics were collected before a large backfill, every estimate built on them is wrong, so the pipeline re-runs ANALYZE after each load.
The plan shows 2 Exchanges tagged ENSURE_REQUIREMENTS and 3 stages, and the SQL tab confirms how many rows the Brazil filter kept.
KEY TAKEAWAYS
Analysis resolves every name against the catalog on the driver, so a DataFrame with a bad column fails on the line that builds it.
The analyzed plan shows what Spark decided for you: an expression ID on every column and the casts that type coercion inserted.
Optimizer rules rewrite the tree without reading data, and a filter moves below a groupBy only when it tests grouping keys alone.
Shuffles enter at physical planning, where EnsureRequirements inserts an Exchange wherever a child's partitioning fails its parent's need.
Hash partitioning on a subset of the grouping keys already satisfies the groupBy, so no new Exchange appears.
Size estimates come from file sizes, and from ANALYZE when CBO is on; string equality uses 1 over the distinct count, and a stale snapshot misleads the planner.
Read a physical plan from the bottom, count Exchanges to get stages, read each tag to see who added the shuffle, and confirm the cheap work sits below the first one.

Trace one query through analysis, rewrites, physical planning and costing, then read the plan Spark runs.

Category
Spark
Difficulty
intermediate
Duration
14 minutes
Challenges
14 hands-on challenges

Topics covered: Analysis, Logical Optimization, Physical Planning, Cost-Based Optimization, Reading a Physical Plan

Lesson Sections

  1. Analysis

    What the analyzer fills in Analysis errors arrive before the action On a Spark Connect session the client sends the plan to the server without analyzing it, so the same misspelling raises at the first action or the first call that needs the schema.

  2. Logical Optimization (concepts: Catalyst Optimizer)

    Rules you will meet in most plans A filter that moves below the groupBy This program groups first and filters second, the order you might write it after deciding late that only the West matters. When a filter has to stay

  3. Physical Planning (concepts: Catalyst Optimizer)

    Where the Exchanges come from When a requirement is already met The planner's interface can return several candidate physical plans, but Spark takes the first. Choices between operators are made by checks inside each strategy, many of them comparing size estimates, the subject of the next section.

  4. Cost-Based Optimization (concepts: Catalyst Optimizer)

    Where the numbers come from Estimates with and without column statistics Statistics that go stale

  5. Reading a Physical Plan (concepts: Spark UI Diagnosis)

    On a recent Spark version it prints the tree below, shown with its lines numbered in reading order. You will also meet plans whose operators carry a *(1) or *(2) prefix, such as the plan of a finished query. The number groups operators Spark compiles into 1 function, a topic for a later lesson, and it never marks a shuffle. From the plan to the Spark UI