Skip to main content

A Python package for validating Spark DataFrames against data quality rules.

Project description

Detailed Usage Instructions for spark-pipelines

Overview

The spark-pipelines package is designed to facilitate data quality validation for Spark DataFrames. By using decorators, users can easily enforce data quality rules on their data loading functions, ensuring that only valid data is processed. This package is particularly useful for data engineers and data scientists who work with large datasets and need to maintain high data quality standards.

Installation

To install the spark-pipelines package, you can use pip:

pip install spark-pipelines

Usage

Basic Example

To get started, you can define your data quality rules in a dictionary format, where the keys are human-readable descriptions of the rules, and the values are SQL filter expressions. Then, you can decorate your data loading functions with the appropriate validation decorator.

Here is a simple example:

from spark_pipelines import DataQuality

dq = DataQuality(
    spark=spark,
    job_name="employee_ingestion_job"
                )

# Define your data quality rules
rules = {
    "Employee ID should be greater than 2": "emp_id > 2",
    "Name should not be null": "fname IS NOT NULL"
}

# Use the expect decorator to validate the DataFrame
@dq.expect(rules)
def load_employee_df():
    return spark.read.table("employee")

# Load the DataFrame and validate it
df = load_employee_df()

Validation Strategies

The package provides several decorators for different validation strategies:

  1. expect: This decorator validates the DataFrame and prints a report of the validation results. If any rule fails, the DataFrame is still returned.

    @DataQuality.expect(rules)
    def load_employee_df():
        return spark.read.table("employee")
    
  2. expect_drop: This decorator validates the DataFrame and returns a filtered DataFrame containing only the valid records. Failed records are excluded.

    @DataQuality.expect_drop(rules)
    def load_employee_df():
        return spark.read.table("employee")
    
  3. expect_fail: This decorator validates the DataFrame and raises an exception if any validation rule fails. This is useful for stopping the pipeline execution when data quality issues are detected.

    @DataQuality.expect_fail(rules)
    def load_employee_df():
        return spark.read.table("employee")
    
  4. expect_quarantine: This decorator validates the DataFrame and optionally quarantines failed records to a specified location or table. You can specify either a path or a table name for storing the quarantined records.

    from spark_pipelines import DataQuality
    dq = DataQuality(
         spark=spark,
         job_name="employee_ingestion_job",
         dq_table_name="data_quality.default.employee_dq",
         quarantine_table="data_quality.default.employee_qr",
         quarantine_format='delta'
                  )
    
    @dq.expect_quarantine(rules)
    def load_employee_df():
        return spark.read.table("employee")
    

Documentation

For more detailed usage examples and explanations of each validation method, refer to the comprehensive documentation available in the docs directory of the package.

Contribution

Contributions to the spark-pipelines package are welcome! Please check the CHANGELOG.md for the history of changes and the LICENSE file for licensing information. If you have suggestions or improvements, feel free to submit a pull request.

By following these instructions, users can effectively utilize the spark-pipelines package to ensure high data quality in their Spark applications.

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

spark-pipelines-1.6.1.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spark_pipelines-1.6.1-py2.py3-none-any.whl (11.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file spark-pipelines-1.6.1.tar.gz.

File metadata

  • Download URL: spark-pipelines-1.6.1.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for spark-pipelines-1.6.1.tar.gz
Algorithm Hash digest
SHA256 a3bb1374c88cfe1e867c1658398b3d6eb0034b14d2b6b81c0dd8feecbe8e755d
MD5 779cae228b59c685b6f96f9209bcf805
BLAKE2b-256 7a1964a58f52b50cbc0ac96fe4e5717e1fc56d545088d17ee05ae55a2995ee41

See more details on using hashes here.

File details

Details for the file spark_pipelines-1.6.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for spark_pipelines-1.6.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e0700e06297ce6d31ce542c226d2ec268d4bc218afcb93ffa1ff6358c9ace494
MD5 41eabc7bed73cfd5599404416ef2184e
BLAKE2b-256 7da38adeb712800ce086d38fd19a825ec9aff5ddd945a0b47ec12cf08843eed5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page