Reusable PySpark common utility functions for data pipelines
Project description
PYSPARK-COMMON-UTILITIES
PYSPARK-COMMON-UTILITIES are reusable components which are small functionalities that are commonly part of data pipelines. We are creating functions for these that can be used when required.
Data Validation
A simple and flexible set of utilities for validating PySpark DataFrame schemas through composable validation rules.
Overview
This library provides a declarative way to define and enforce schema requirements on PySpark DataFrames. Instead of writing manual checks scattered throughout your code, you can define validation rules once and reuse them across your data pipeline.
Key Features
- Composable Rules: Build complex schema validations by chaining simple rules together
- Clear Reporting: Get detailed validation reports with pass/fail status for each rule
- Flexible Validation: Choose between soft validation (returns report) or strict validation (raises exception)
- Early Exit Option: Stop validation on first error or run all checks to see all issues at once
Quick Start
# Create your DataFrame
data = [(1, "Alice"), (2, "Bob")]
df = spark.createDataFrame(data, ["id", "name"])
# Define your schema validation rules
schema = (
SchemaDefinition()
.add_rule(ColumnExistsRule("id"))
.add_rule(ColumnTypeRule("id", LongType()))
.add_rule(NoExtraColumnsRule(allowed_columns=["id", "name"]))
)
# Validate
validator = DataFrameValidator(schema)
report = validator.validate(df, stop_on_first_error=False)
print(report)
# Output:
# Validation Report - VALID
# ============================================
# ✓ - Column id exists
# ✓ - Correct type: LongType()
# ✓ - All columns are allowed
#
# Total: 3 checks - 0 errors
Available Rules
- ColumnExistsRule: Checks if a column exists in the DataFrame
- ColumnTypeRule: Validates that a column has the expected data type
- NoExtraColumnsRule: Ensures no unexpected columns are present
Validation Methods
validate(df, stop_on_first_error=False)
Returns a detailed validation report with all results.
If stop_on_first_error=True, validation halts on the first failure.
strict_validate(df, stop_on_first_error=True)
Raises NotValidSchemaException if validation fails, useful for enforcing schema requirements in production pipelines.
try:
validator.strict_validate(df)
except NotValidSchemaException as e:
print(e)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyspark_common_utilities-0.1.7.tar.gz.
File metadata
- Download URL: pyspark_common_utilities-0.1.7.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f74510d374c141967552bce669fd0b3dd1ec19bc23237e798eccd5588e237ff9
|
|
| MD5 |
252116a2b2dc0a34ae288f6a8a0ec4a7
|
|
| BLAKE2b-256 |
f1444813aeef3e675232266c112690f622f083f5acff6d5286c552f19f9813c1
|
File details
Details for the file pyspark_common_utilities-0.1.7-py3-none-any.whl.
File metadata
- Download URL: pyspark_common_utilities-0.1.7-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7d3a9bd575f9054ca8a3a61c0bfc15a67ad0ed029489a760fc507c10c6aa2c2
|
|
| MD5 |
5dbad49b0cdad0671f427d011bafc0aa
|
|
| BLAKE2b-256 |
3577bb365a4d0c398ce6e98f824502bc54443d56ecbf858bb06190e5ed58d6f4
|