Apache Spark Big Data (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
How does the Catalyst Optimizer optimize Spark SQL queries?
senior LevelSystem DesignDatabases & SQL
In Simple Words: Catalyst is Spark's rule-based and cost-based query optimization engine. It operates in 4 phases:
- Analysis: Resolves table and column names against the Catalog to produce an Analyzed Logical Plan.
- Logical Optimization: Applies rule-based optimizations: Predicate Pushdown (filters pushed to storage source) and Column Pruning (reading only queried columns).
- Physical Planning: Generates multiple physical execution strategies and picks the cheapest one using a Cost-Based Optimizer (CBO).
- Code Generation (CodeGen): Generates optimized Java bytecode on-the-fly for whole-stage execution.