Data ScienceData engineering for data science

Spark transformations and actions with an execution plan

PK
Pankit Kumar
Sr. Data Scientist at Parexel (a Goldman Sachs–backed company) · 20 September 2026 · 2 min read
Technically reviewed by Ishaan Sharma
In this article (5 sections)

Spark transformations describe a new dataset and are generally lazy; an action requests a result or write and triggers execution. The physical work depends on the optimized plan, partitioning and data. Counting API calls is not a performance analysis.

A static plan with an honest evidence state

The data-engineering lab records a proposed flow: read Parquet, filter date, select account and amount, group by account, sum amount, then write a partitioned feature table.

python
from data_engineering_cases import spark_plan_case

result = spark_plan_case()
assert result["action_count"] == 1
assert result["pyspark_executed"] is False
print(result["plan"])

The plan marks groupBy as a shuffle boundary and avoids caching until reuse is measured. PySpark is not installed, so there is no explain output, job time or shuffle metric.

Read plans before tuning

In a real environment, inspect logical and physical plans. Look for filters pushed near reads, column pruning, exchanges, join strategy and repeated scans. Use the Spark UI for task skew, shuffle size, spills and executor failures.

Caching consumes memory and can slow a one-use dataset. Cache only when repeated computation and measurements justify it, and unpersist deliberately. Avoid accidental actions such as repeated counts during debugging.

Verify output semantics

Define the feature grain and write mode. Reconcile counts, unique keys and sums against a small local fixture. An optimized job that duplicates entities is still wrong.

The Data Science course separates documented Spark semantics from executed distributed evidence.

Exercise

Run the plan in a reviewed PySpark environment. Save explain output and Spark UI metrics, then test column pruning and one measured cache decision.

Continue learning

This article is part of the Data engineering for data science sequence. Use the neighbouring tasks when you need the prerequisite or the next application.

Reference: Spark RDD programming guide on transformations and actions.

PK
Pankit Kumar
Lead Instructor, NeuraPath Academy

Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.

This article is part of our Data Science programme — 6 months. From data foundations to machine learning, deep learning and deployment.

Explore Data Science
Counselling is free · no obligation

Not sure which programme fits?

Tell us your background and we will map it to the right entry point — including saying so when a cheaper programme is the better fit. A counsellor replies within one working day.