Reference library

Big data & Spark

PySpark jobs, partitioning, batch processing, and large-dataset transform patterns.

3 matches
Big data & Spark easy

How to Broadcast a Small Lookup Table in Python

Simulates broadcasting a small lookup table by iterating key-value pairs and emitting packed rows to subscribers with deterministic output.

broadcast lookup-table dictionary
Python
import random

# Generate a deterministic mock broadcast of a small lookup table
# with 5 keys and random integer values (seeded for reproducibility)

data = {
    "sensor_a": 22,
    "sensor_b": 87,
    "sensor_c": 43,
    "sensor_d": 65,
    "sensor_e": 31,
}

# Simulate a broadcast to subscribers by iterating and p…
14 0 Open
Big data & Spark easy

How to Use Broadcast Variables as Read-Only in PySpark (Mock Example)

Share a lookup dict across Spark executors with a broadcast variable and verify its read-only behavior in a local mock.

pyspark broadcast spark
Python
from pyspark import SparkContext, SparkConf

def main():
    conf = SparkConf().setAppName("BroadcastMock").setMaster("local[2]")
    sc = SparkContext(conf=conf)
    
    lookup = {"a": 1, "b": 2, "c": 3}
    broadcast_lookup = sc.broadcast(lookup)
    
    data = ["a", "b", "c", "a", "unknown"]
    rdd = sc.parallel…
13 0 Open
Big data & Spark easy

Modeling a Hive Metastore Table Schema in Python

A dataclass that mimics a Hive metastore table schema—columns, partition keys, storage format, and location—with helper methods for description and mutation.

hive dataclass metastore
Python
from dataclasses import dataclass, field
from typing import Dict, List, Optional


@dataclass
class HiveTable:
    """Simple mock of a Hive metastore table schema."""
    name: str
    database: str = "default"
    columns: List[Dict[str, str]] = field(default_factory=list)
    partition_keys: List[Dict[str, str]] = f…
14 0 Open

Browse by section

Each section groups closely related Python snippets.

Big data & Spark — Python code examples

What you will find here

This page collects big data & spark snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.