Skip to main content

A tool to visualize Apache Spark execution plans.

Project description

Spark Plan Viz

A lightweight, interactive tool to visualize and analyze PySpark execution plans using D3.js. It helps developers and data engineers debug complex queries when the textual result of df.explain() is not enough.

Documentation | PyPI | Optimization Reference

Features

  • Interactive Visualization: Zoom, pan, and click nodes to explore execution details
  • 14-Rule Optimization Engine: Detects cross joins, missing broadcasts, full table scans, Python UDFs, and more
  • Performance Insights: Instantly identify shuffles, broadcast joins, and pushed filters
  • Jupyter Integration: Renders directly inside notebooks without external files
  • Standalone HTML: Export visualizations to share with your team
  • AQE Support: Full support for Adaptive Query Execution details

Installation

uv add spark-plan-viz

Or with pip:

pip install spark-plan-viz

Quick Start

Visualize

from spark_plan_viz import visualize_plan

# Renders inline in Jupyter
visualize_plan(df, notebook=True)

# Or export to HTML file
visualize_plan(df, notebook=False, output_file="my_plan.html")

Analyze

from spark_plan_viz import analyze_plan

suggestions = analyze_plan(df)
for s in suggestions:
    print(f"[{s.severity.value}] {s.title}: {s.message}")

Example

from pyspark.sql import SparkSession
from pyspark.sql.functions import broadcast
from spark_plan_viz import visualize_plan

spark = SparkSession.builder.appName("Example").getOrCreate()

orders = spark.createDataFrame([
    (1, "Alice", 100),
    (2, "Bob", 200),
], ["id", "customer", "amount"])

customers = spark.createDataFrame([
    ("Alice", "NY"),
    ("Bob", "CA"),
], ["name", "state"])

result = orders.filter(orders.amount > 50) \
    .join(broadcast(customers), orders.customer == customers.name) \
    .groupBy("state") \
    .agg({"amount": "sum"})

visualize_plan(result, notebook=True)

example visualization

What the Optimizer Detects

The built-in analyzer checks for 14 common performance issues:

Severity Rule What it catches
ERROR Cross Join df.crossJoin(other) — Cartesian product
ERROR Nested Loop Join Non-equality join condition → O(n*m)
WARNING Full Table Scan Scan with no pushed filters
WARNING Expensive Collect collect_list / collect_set in aggregates
WARNING Window Without PARTITION BY Global window → single partition
WARNING Python UDF Row-level JVM↔Python serialization
WARNING Redundant Shuffle Back-to-back repartition() calls
WARNING Partition Count < 2 or > 10 000 partitions
WARNING Sort Before Shuffle Sort immediately destroyed by shuffle
INFO Missing Broadcast Hint Shuffle join where broadcast may help
INFO Non-Columnar Format CSV/JSON scan instead of Parquet/ORC
INFO Coalesce via Round-Robin repartition(n) when coalesce(n) suffices
INFO Skew Hint SortMergeJoin without skew optimization
INFO Unnecessary Sort Sort not consumed by ordering-dependent op
# Quick example: detect a cross join
result = employees.crossJoin(departments)
suggestions = analyze_plan(result)
# → [ERROR] Cross Join Detected: Cross joins produce the Cartesian product ...

# Fix it:
result = employees.join(departments, employees.department == departments.dept_name)
suggestions = analyze_plan(result)
# → no cross_join finding

See the Gallery for runnable examples of every rule with bad patterns and fixes.

Requirements

  • Python 3.11+
  • PySpark 3.x+
  • For notebook mode: IPython/Jupyter

Limitations

spark_plan_viz is not available on Databricks Serverless Compute, as it's not possible to access the _jdf object of a Spark DataFrame.

License

MIT License

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

Development Setup

git clone https://github.com/montanarograziano/spark_plan_viz.git
cd spark_plan_viz
just install
just pre-commit
just check
just test

Acknowledgments

Built with D3.js for interactive visualizations.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spark_plan_viz-1.1.0.tar.gz (413.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spark_plan_viz-1.1.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file spark_plan_viz-1.1.0.tar.gz.

File metadata

  • Download URL: spark_plan_viz-1.1.0.tar.gz
  • Upload date:
  • Size: 413.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spark_plan_viz-1.1.0.tar.gz
Algorithm Hash digest
SHA256 fb7f11669e115eba36ddab5a6e7cf3ff0abe16af684de8c4ac801bd9e9e1bdd2
MD5 c0ee3fd3a72cc10c67a0f356b9627268
BLAKE2b-256 2047685cd237371d2ae2a697b0d1aa8ded62be35081d54bc43a673eecff72766

See more details on using hashes here.

Provenance

The following attestation bundles were made for spark_plan_viz-1.1.0.tar.gz:

Publisher: release.yml on montanarograziano/spark_plan_viz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spark_plan_viz-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: spark_plan_viz-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spark_plan_viz-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e4f3a73a1778372ebd10ee7cf88236db464ffe20e7afc6cc2d2b158db76e622
MD5 1fa536704d8b35b875179852e32d5be7
BLAKE2b-256 86ec98ffb4781c730f51b7416d0c08fc9beee3d3400af43438b3f11fd6b73309

See more details on using hashes here.

Provenance

The following attestation bundles were made for spark_plan_viz-1.1.0-py3-none-any.whl:

Publisher: release.yml on montanarograziano/spark_plan_viz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page