Reference library

Big data & Spark

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

4 matches
Big data & Spark easy

How to Explode an Array Column in Python

This code demonstrates a mock explode operation that converts an array column into multiple rows, similar to Spark's explode function.

explode arrays pyspark
Python
import json 

def explode_array_column(data, column):
    """Mock explode: split array column into multiple rows."""
    exploded = []
    for row in data:
        values = row.get(column, [])
        for value in values:
            new_row = dict(row)
            new_row[column] = value
            exploded.append(n…
13 0 Open
Big data & Spark easy

How to Mock a User-Defined Function (UDF) in Python

Wrap a real UDF implementation with call logging to simulate and track invocations in a data pipeline.

udf mock testing
Python
from typing import Any, Callable


# Mock a user-defined function (UDF) that was previously complex or external
def mock_udf(name: str, implementation: Callable[..., Any], *, calls: list[Any]) -> Callable[..., Any]:
    """Wrap a real implementation with call logging to simulate a UDF."""
    def wrapper(*args: Any, *…
13 0 Open
Big data & Spark easy

How to Pivot and Group Aggregate in Python

Group records by a key, collect values, and apply an aggregate function (like sum) to build a pivot-style summary dictionary.

pivot group-by aggregation
Python
from collections import defaultdict

def pivot_group_aggregate(records, group_key, value_key, agg_func):
    groups = defaultdict(list)
    for record in records:
        groups[record[group_key]].append(record[value_key])
    return {key: agg_func(values) for key, values in groups.items()}

if __name__ == "__main__":…
13 0 Open
Big data & Spark easy

How to select specific columns in Python with SQLite

A reusable function that connects to a SQLite database and returns only the requested columns from a given table.

sqlite sql database
Python
import sqlite3

def select_pruned_columns(db_path, table, columns):
    with sqlite3.connect(db_path) as conn:
        cursor = conn.cursor()
        col_list = ", ".join(columns)
        query = f"SELECT {col_list} FROM {table}"
        return cursor.execute(query).fetchall()

if __name__ == "__main__":
    conn = sq…
15 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.