Skip to main content

spark-data-quality

What Is This For?

Imagine your pipeline loads 100,000 rows of sales data into a table every day. Before you use that data to make business decisions, you'd want to check:

  • Does the customer_id column have any blank or missing values?
  • Did the table receive all 100,000 rows, or did some get lost and only 50,000 arrived?
  • Is every value in the amount column between 1 and 500,000 (no negatives, no unrealistic numbers)?
  • Does the region column only contain expected values like "North", "South", "East", "West" — or did something like "XYZ123" sneak in?
  • Are there exactly 4 unique regions, not 3 or 50?

Doing these checks manually is impossible at scale. This package automates that process. You define your rules once (in the DQ Engine dashboard), and every time new data arrives, the package checks it against all those rules and tells you what passed and what failed.

If something fails, you know immediately — before bad data reaches your reports, dashboards, or downstream systems.

How It Works

Your Data (DataFrame)
        │
        ▼
┌──────────────────┐        ┌──────────────┐
│  SparkDQAgent    │──GET──>│  DQ Engine   │  "What rules should I check?"
│                  │<───────│              │  (returns assertions)
│  Runs checks     │        │              │
│  using Great     │        │              │
│  Expectations    │──POST─>│              │  "Here are the results"
│                  │        │  Stores &    │
│  Returns summary │        │  displays    │
└──────────────────┘        └──────────────┘
  1. You create a SparkDQAgent and point it to your table using catalog, schema, and table name
  2. The agent fetches rules from the DQ Engine (e.g., "column X must not be null")
  3. You load your data into a Spark DataFrame
  4. The agent runs every rule against your data
  5. Results are saved to the DQ Engine and returned to you

Installation

pip install spark-data-quality

Quick Start

from pyspark.sql import SparkSession
from spark_dq.quality import SparkDQAgent

spark = SparkSession.builder.master("local[*]").getOrCreate()

# 1. Create the agent — just pass your table's catalog, schema, and name
agent = SparkDQAgent(
    catalog="mycatalog",
    schema="myschema",
    table="sales_data",
    data_quality_url="https://your-dq-engine.example.com/api/v1/spark",
    catalog_type="unmanaged",
    trino_host="trino.example.com:443",
    trino_user="service_account",
    trino_pwd="your_password",
)

# 2. Load your data
df = spark.read.format("jdbc") \
    .option("url", "jdbc:trino://trino.example.com:443?SSL=true") \
    .option("driver", "io.trino.jdbc.TrinoDriver") \
    .option("user", "service_account") \
    .option("password", "your_password") \
    .option("query", "SELECT * FROM mycatalog.myschema.sales_data") \
    .load()

# 3. Run checks and review results
results = agent.execute_data_quality(df)

for suite_name, stats in results.items():
    passed = stats["successful_expectations"]
    total  = stats["evaluated_expectations"]
    print(f"{suite_name}: {passed}/{total} passed")

spark.stop()

Key Methods

fetch_table_config()

Fetches the table's configuration from the DQ Engine — this includes all the assertions (rules) defined for your table, the SQL query to load data, and scan limits. The result is cached after the first call, so calling it multiple times does not make extra API requests.

execute_data_quality(df)

The main method. Runs all assertions against your Spark DataFrame using Great Expectations:

  • Fetches config from DQ Engine (if not already fetched)
  • Runs all assertions in parallel for speed
  • Saves results to the DQ Engine (POST /save-results)
  • Returns a summary with pass/fail counts
# Example output
{
    "sales_data_93": {
        "evaluated_expectations": 5,
        "successful_expectations": 5,
        "unsuccessful_expectations": 0,
        "success_percent": 100.0
    }
}
Field What It Means
evaluated_expectations Total number of checks run
successful_expectations How many passed
unsuccessful_expectations How many failed
success_percent Pass rate (100.0 = all passed)

Common Assertion Types

Check Assertion Type
No null values expect_column_values_to_not_be_null
All values unique expect_column_values_to_be_unique
Values in a range expect_column_values_to_be_between
Row count in a range expect_table_row_count_to_be_between
Distinct value count expect_column_unique_value_count_to_be_between
Median in a range expect_column_median_to_be_between
Text matches pattern expect_column_values_to_match_regex
Text length in range expect_column_value_lengths_to_be_between

Requirements

  • Python 3.8+
  • PySpark 3.1.1+
  • Great Expectations 0.18.12
  • A running DQ Engine instance with assertions configured

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spark_data_quality-1.0.14.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

spark_data_quality-1.0.14-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file spark_data_quality-1.0.14.tar.gz.

File metadata

  • Download URL: spark_data_quality-1.0.14.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for spark_data_quality-1.0.14.tar.gz
Algorithm Hash digest
SHA256 558bf2d436dd3e728c3200473b03d09db6b67567f2b40610aa6a1cb5498342fa
MD5 2695d68ebf1e9964a05a615b2abde2ed
BLAKE2b-256 cc19ec263e20c5a3285564cc208f1c30a49fd491473643a4c71c3099c0ce8124

See more details on using hashes here.

Provenance

The following attestation bundles were made for spark_data_quality-1.0.14.tar.gz:

Publisher: ci.yml on saal-core/digixt-quality-package

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spark_data_quality-1.0.14-py3-none-any.whl.

File metadata

File hashes

Hashes for spark_data_quality-1.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 d84a62c25a442b2d1c95842c9693a9ba01823c5ad933e5558490ff096435eadf
MD5 698c23e23b1ebb6965b0c9f60b5566a7
BLAKE2b-256 3fa163d0a63c003c289cab87e1e594fbe8ca839152b638a03f3c8b62f690de59

See more details on using hashes here.

Provenance

The following attestation bundles were made for spark_data_quality-1.0.14-py3-none-any.whl:

Publisher: ci.yml on saal-core/digixt-quality-package

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.1.1

2 files

1.1.0

2 files

This release

1.0.14 This release

2 files

1.0.12

2 files

1.0.11

2 files

1.0.10

2 files

1.0.9

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page