Reference library

Big data & Spark

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

4 matches
Big data & Spark medium

How to implement a tumbling window aggregation in Python

Build a mock tumbling window aggregator in Python that groups streaming events into fixed time intervals and computes count, sum, and average per window.

tumbling-window streaming aggregation
Python
import time
from collections import deque

class TumblingWindow:
    def __init__(self, duration_seconds):
        self.duration = duration_seconds
        self.buffer = deque()
        self.window_start = None

    def add(self, item):
        current_time = time.time()
        if self.window_start is None:
         …
13 0 Open
Big data & Spark medium

Mock Predicate Pushdown in Python for Big Data Queries

Simulate predicate pushdown by applying filters at the storage layer before materializing rows, showing how big data engines optimize queries.

big-data query-optimization predicate-pushdown
Python
class Query:
    def __init__(self, table, rows):
        self.table = table
        self.rows = rows

    def filter(self, predicate):
        return Query(
            self.table,
            [row for row in self.rows if all(predicate(row) for predicate in predicate)]
        )

    def filter_pushdown(self, predica…
15 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…
13 0 Open
Big data & Spark easy

Sliding Window Streaming Mock in Python

A simple Python class that maintains a sliding window of recent streaming values and computes the running average.

streaming sliding-window averages
Python
import time
import random

class StreamingMock:
    """Produces a stream of numbers using a sliding window."""
    
    def __init__(self, window_size=5):
        self.window = []
        self.window_size = window_size
        
    def push(self, value):
        """Add a value, sliding the window forward."""
        s…
12 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.