Skip to content
Skills Library
Data & analytics · Building & coding

spark

/spark

Expert Apache Spark assistance covering PySpark, Spark SQL, DataFrame transformations, broadcast joins, and cluster optimization. Use when processing petabyte distributed data and running big data ETL pipelines.

Licence
MIT
Last repository change
01.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
1
Deprecation

No signals detected. Repository changed on 01.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Expert Apache Spark assistance covering PySpark, Spark SQL, DataFrame transformations, broadcast joins, and cluster optimization. Use when processing petabyte distributed data and running big data ETL pipelines.

Original author description

Expert Apache Spark assistance covering PySpark, Spark SQL, DataFrame transformations, broadcast joins, and cluster optimization. Use when processing petabyte distributed data and running big data ETL pipelines.

How it works

  1. When to Use
  2. Quick Start
  3. Core Concepts
  4. Common Patterns
  5. Best Practices
  6. Troubleshooting
  7. References
Original SKILL.md headings · 145 lines, 581 words
SKILL.md preview
---
name: spark
description: Expert Apache Spark assistance covering PySpark, Spark SQL, DataFrame transformations, broadcast joins, and cluster optimization. Use when processing petabyte distributed data and running big data ETL pipelines.
---

# Apache Spark

Apache Spark is a multi-language engine for executing data engineering, data science, and machine learning on single-node machines or large distributed clusters with Spark Connect.

## When to Use

- **Petabyte-Scale Distributed Data Processing**: Transforming massive datasets across cloud clusters with Apache Spark 3.5+.
- **Real-Time Streaming Pipelines**: Low-latency stream processing with Spark Structured Streaming.
- **Enterprise Lakehouse Architectures**: Querying and updating Delta Lake, Apache Iceberg, and Apache Hudi tables.
- **Distributed SQL & Complex Analytical Aggregations**: Distributed joins, window functions, and analytics with Catalyst Optimizer.

## Quick Start

```python
from pyspark.sql import SparkSession
from pyspark.sql.functions import col, avg

spark = SparkSession.builder \
    .appName("AnalyticsETL") \
    .config("spark.sql.shuffle.partitions", "200") \
    .getOrCreate()

df = spark.read.parquet("s3a://data-lake/sales/")
summary = df.groupBy("country").agg(avg("amount").alias("avg_spent"))
summary.write.mode("overwrite").parquet("s3a://data-lake/reports/summary/")
```

## Core Concepts

### Structured DataFrame Transformations & Window Functions

Distributed analytical querying with PySpark:

```python
from pyspark.sql import SparkSession
from pyspark.sql import functions as F
from pyspark.sql.window import Window

spark = SparkSession.builder \
    .appName("CustomerAnalytics2026") \
    .config("spark.sql.adaptive.enabled", "true") \
    .config("spark.sql.shuffle.partitions", "200") \
    .getOrCreate()

# Read partitioned Parquet from cloud storage
df = spark.read.parquet("s3a://data-lake/transactions/")

# Define window partitioned by customer ordered by timestamp
customer_window = Window.partitionBy("customer_id").orderBy("transaction_time")

# Compute cumulative spend and previous transaction date
enhanced_df = df.filter(F.col("status") == "COMPLETED") \
    .withColumn("running_total", F.sum("amount").over(customer_window)) \
    .withColumn("prev_transaction_time", F.lag("transaction_time", 1).over(customer_window)) \
    .withColumn("days_since_last", F.datediff(F.col("transaction_time"), F.col("prev_transaction_time")))

enhanced_df.write \
    .mode("overwrite") \
    .partitionBy("region") \
    .parquet("s3a://data-lake/marts/customer_summary/")
```

### Broadcast Joins for Skewed Dimensions

Optimizing distributed joins between large fact tables and small dimension lookup tables:

```python
# Broadcast small dimension table to all executors, eliminating expensive shuffles
dimension_df = spark.read.parquet("s3a://data-lake/dimensions/merchant_tiers/")

joined_df = df.join(
    F.broadcast(dimension_df),
    on="merchant_id",
    how="inner"
)
```

### Spark Structured Streaming from Kafka

Continuous stream processing with checkpointing:

```python
stream_df = spark.readStream \
    .format("kafka") \
    .option("kafka.bootstrap.servers", "kafka:9092") \
    .option("subscribe", "telemetry-events") \
    .load()

parsed_stream = stream_df.selectExpr("CAST(value AS STRING) as json_payload")

query = parsed_stream.writeStream \
    .format("parquet") \
    .option("path", "s3a://data-lake/raw_stream/") \
    .option("checkpointLocation", "s3a://data-lake/checkpoints/telemetry/") \
    .trigger(processingTime="1 minute") \
    .start()
```

## Common Patterns

### Broadcast Join for Skewed Dimensions

**Problem**: Joining a small lookup table with a massive distributed fact table causes slow shuffle exchanges across executors.

**Solution**:
Broadcast the small table to all worker nodes:

```python
from pyspark.sql.functions import broadcast

large_fact_df = spark.read.parquet("events/")
small_dim_df = spark.read.csv("country_codes.csv", header=True)

# Broadcast join eliminates shuffle network overhead
result_df = large_fact_df.join(broadcast(small_dim_df), "country_id")
```

## Best Practices

**Do**:

- Enable Adaptive Query Execution (`spark.sql.adaptive.enabled=true`) for automatic partition coalescing and join optimization.
- Use `F.broadcast()` when joining a large DataFrame with a small table (< 100MB) to eliminate shuffle overhead.
- Always specify an explicit `checkpointLocation` on durable cloud storage for Structured Streaming jobs.
- Cache or persist (`df.persist()`) intermediate DataFrames only when reused multiple times in the same job.

**Don't**:

- Collect massive DataFrames to the driver node (`df.collect()`); write directly to cloud storage.
- Use Python UDFs (`@udf`) if native `pyspark.sql.functions` exist; native functions avoid JVM-Python serialization overhead.
- Leave small file problems unaddressed; use Delta Lake `OPTIMIZE` or coalesce partitions before writing.

## Troubleshooting

| Error                                                                        | Cause                                                           | Solution                                                                       |
| :--------------------------------------------------------------------------- | :-------------------------------------------------------------- | :----------------------------------------------------------------------------- |
| `java.lang.OutOfMemoryError: Java heap space on Executor`                    | Data skew or partition sizes too large for executor memory.     | Increase `spark.executor.memory` or salt skewed keys before grouping.          |
| `Container killed by YARN for exceeding memory limits`                       | Off-heap overhead or Python process exceeding memory threshold. | Increase `spark.yarn.executor.memoryOverhead` to 1GB+.                         |
| `Total size of serialized results is bigger than spark.driver.maxResultSize` | Calling `.collect()` on massive distributed DataFrame.          | Write output to disk or use `.take(100)` instead of collecting entire dataset. |

## References

- [Apache Spark](https://spark.apache.org/)

Versions

RepositoryScoreLicence
This page · G1Joshi/Agent-Skills100MIT
nimadorostkar/Claude-Skills-collection100MIT
chrishuffman5/domain-expert100MIT
devnomad-byte/techneering100MIT
wishworldbetter/seedex-skills100MIT
a-lottes/aspark90MIT
NirDiamant/Agentic_Engineering90Apache-2.0
dkbnull/hello-skill86MIT

Database snapshot: 13.11.2026 · package version 270777e5487d (SHA-256 digest of the entire package)

Downloads in the last 30 days: 2 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100apache-spark
    Apache Spark is a distributed engine for batch, SQL and streaming data processing, used from Python through PySpark. Use when a user asks to process big data, run distributed computations, build ETL pipelines, analyse data at scale, read Parquet from S3, or stream from Kafka with PySpark.
  • 100apache-spark
    Knowledge base from \"Learning Spark, 2nd Edition\" by Damji, Wenig, Das & Lee. Use when working with Apache Spark / PySpark, preparing for the Databricks Certified Associate Developer for Apache Spark exam, or applying the authors' frameworks for Spark architecture, DataFrame…
  • 100spark-engineer
    Use when writing Spark jobs, debugging performance issues, or configuring cluster settings for Apache Spark applications, distributed data processing pipelines, or big data workloads. Invoke to write DataFrame transformations, optimize Spark SQL queries, implement RDD pipelines,…
  • 100pyspark-etl
    Best practices for building performant, testable PySpark ETL pipelines with Spark SQL and Apache Iceberg. Use when writing or reviewing PySpark jobs, designing joins and window functions, working with map/array higher-order functions, or building idempotent cumulative/snapshot table merges.
  • 100spark-engineer
    Use when writing Spark jobs, debugging performance issues, or configuring cluster settings for Apache Spark applications, distributed data processing pipelines, or big data workloads. Invoke to write DataFrame transformations, optimize Spark SQL queries, implement RDD pipelines,…
  • 100apache-spark-dataframes-transformations
    Use this skill when building distributed big data transformations using Spark DataFrames, Catalyst optimization, and dataset actions.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.