Catalyst Optimizer and Project Tungsten in Spark
knowledge of Spark SQL internals.
Catalyst transforms logical plans with rules, picks physical plans by cost; Tungsten optimizes execution with off-heap memory and codegen.
WHAT THIS TESTS: Whether you understand that Spark SQL does not execute queries literally but compiles them through an optimizer, and whether you can separate plan-level optimization (Catalyst) from execution-level optimization (Tungsten).
A GOOD ANSWER COVERS: Catalyst is Spark SQL's extensible query optimizer. It first parses a query or DataFrame into an unresolved logical plan, resolves column and table references against the catalog to produce an analyzed logical plan, then applies a library of rule-based transformations such as predicate pushdown, projection pruning, constant folding, and Boolean simplification to produce an optimized logical plan. From that it generates one or more physical plans and uses cost-based optimization to choose among them, for example selecting a broadcast hash join over a sort-merge join when one side is small. Project Tungsten then makes the chosen plan run fast at the execution layer. It manages memory off-heap in compact binary format to cut garbage-collection pressure, exploits cache-aware data structures, and uses whole-stage code generation to fuse multiple operators into a single compiled JVM function, avoiding virtual-call overhead.
COMMON WRONG ANSWERS: Saying Catalyst executes the query, or that Tungsten optimizes the logical plan. Tungsten is about CPU and memory efficiency, not plan rewriting.
LIKELY FOLLOW-UPS: What is the difference between rule-based and cost-based optimization? How does whole-stage codegen reduce overhead? When does Adaptive Query Execution re-optimize at runtime?
ONE CONCRETE EXAMPLE: A join filters one table by date. Catalyst pushes the date predicate down so the scan reads fewer rows, prunes unused columns, and picks a broadcast join because the dimension table is tiny. Tungsten then code-generates the filter and join into one tight loop operating on off-heap binary rows, so the query runs far faster than an interpreted plan would.
Read the original → databricks.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.