home
diamond Go Premium
Data Engineering Path  ·  PySpark

DataFrame Catalyst Query Plan Tracing

Series Data Engineering & Distributed Systems Series
Estimated Time ~30 Mins Lab
Lab Objective Interpret PySpark DataFrame `.explain(True)` plan outputs — identifying Parsed, Analyzed, Optimized, and Physical plan stages for a grouped aggregation query.

Target Query & Execution Code

df = spark.read.json("products.json")
result_df = df.select("category", "price") \
              .filter("price > 100") \
              .groupBy("category") \
              .count()

result_df.explain(True)

Catalyst Plan Breakdown

1. Parsed Logical Plan (AST Syntax Tree):

== Parsed Logical Plan ==
'Aggregate ['category], ['category, 'count(1) AS 'count]
+- 'Filter ('price > 100)
   +- 'Project ['category, 'price]
      +- 'UnresolvedRelation [products.json]

2. Analyzed Logical Plan (Catalog Types Resolved):

== Analyzed Logical Plan ==
Aggregate [category#1], [category#1, count(1) AS count#2L]
+- Filter (price#2 > 100)
   +- Project [category#1, price#2]
      +- Relation [category#1,price#2] json

3. Optimized Logical Plan (Predicate Pushdown & Projection Pruning):

== Optimized Logical Plan ==
Aggregate [category#1], [category#1, count(1) AS count#2L]
+- Project [category#1]
   +- Filter (price#2 > 100)
      +- Relation [category#1,price#2] json

4. Physical Plan (Whole-Stage Code Gen Execution):

== Physical Plan ==
*(2) HashAggregate(keys=[category#1], functions=[count(1)], output=[category#1, count#2L])
+- Exchange hashpartitioning(category#1, 200), ENSURE_REQUIREMENTS, [id=#10]
   +- *(1) HashAggregate(keys=[category#1], functions=[partial_count(1)], output=[category#1, count#12L])
      +- *(1) Project [category#1]
         +- *(1) Filter (isnotnull(price#2) AND (price#2 > 100))
            +- FileScan json [category#1,price#2] Batched: false, Format: JSON
Find this content helpful? ☕ Buy me a coffee

Entity Details

Create New Item

celebration
Enjoying the free content?

Create a free account to track your progress and save your place.

Create Free Account
help

Submit Technical Query

Have a question or run into an issue? Describe it below, upload an optional screenshot, and our engineering team will answer it!

image Attach image (optional)

Submit Feedback

build Free Developer Utility Free Tool
gavel

Privacy & Legal Disclaimer

1. Client-Side Browser Processing

All utility tools on DeepEngineerHub (including Image to PDF, Text Formatters, JSON Converters, and Encryptors) execute 100% locally within your client browser using WebAssembly and JavaScript. No uploaded images, text, or documents are transmitted, collected, or stored on remote servers.

2. Limitation of Liability ("As-Is" Provision)

Tools and services are provided free of charge for convenience and educational purposes "as-is" without warranties of any kind. DeepEngineerHub shall not be held liable for any data loss, formatting inconsistencies, or indirect damages resulting from tool usage.

3. Open Source & Third-Party Software

Certain utilities utilize open-source client libraries (such as jsPDF, Mermaid.js, Pyodide) licensed under MIT, Apache, or BSD open licenses. All intellectual property remains with their respective copyright holders.