The full answer
Catalyst is Spark SQL's query optimizer. Every DataFrame operation and SQL query becomes a tree of operators that Catalyst analyses, rewrites with optimisation rules and turns into a physical plan, choosing join strategies and pushing work down to the data source. Because of it, the same query is fast whether written in SQL or the DataFrame API, in Python or Scala.
The four phases
- Analysis: the unresolved logical plan (column and table names as written) is resolved against the catalog: names checked, types assigned, functions found. Errors like an unknown column are raised here.
- Logical optimisation: rule-based rewrites of the logical plan, such as:
- predicate pushdown: filters moved as close to the source as possible;
- column pruning: only needed columns kept;
- constant folding:
1 + 2computed once; - simplifying expressions and removing redundant operations;
- combining consecutive filters and projections;
- rewriting some subqueries as joins.
- Physical planning: one or more physical plans are generated and one is chosen, using statistics for cost-based decisions such as broadcast hash join versus sort-merge join, and join order when the cost-based optimizer is enabled.
- Code generation: whole-stage code generation (Tungsten) compiles chains of operators into Java bytecode working on compact binary rows, avoiding per-row function calls.
Runtime re-optimisation Adaptive query execution extends Catalyst at runtime: after each shuffle stage it re-plans with actual sizes, coalescing small partitions, switching to broadcast joins and splitting skewed partitions. Dynamic partition pruning and runtime Bloom filters also use values only known while the query runs.
Seeing it work
df = (spark.read.parquet("/data/orders")
.filter("country = 'DE'")
.select("order_id", "amount"))
df.explain(mode="extended") # parsed, analysed, optimised and physical plans
The optimised plan shows the filter pushed into the Parquet scan (PushedFilters) and only two columns read.
What it means for your code
- Write clear, declarative code; Catalyst handles ordering of filters and projections.
- Python UDFs are opaque: Catalyst can't push filters through them or optimise inside them, and data must move to Python. Prefer built-in functions.
- RDD operations bypass Catalyst entirely.
- Keep table statistics current (
ANALYZE TABLE) so cost-based choices are good. - Catalyst is extensible: platforms and libraries add their own rules, such as Delta Lake's.
Last updated 16 October 2026
Sources