Metadata-Version: 2.4
Name: open-sparkdq
Version: 0.1.10
Summary: Plug-and-play Data Quality + Unit Testing for PySpark (batch & streaming) with YAML config, profiling, and optional OpenTelemetry hooks.
Author-email: Aashish Kumar <aashish72.it@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Aashish Kumar
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/aashish72it/open-spark-dlh-dq
Project-URL: Issues, https://github.com/aashish72it/open-spark-dlh-dq/issues
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyspark<3.6,>=3.3
Requires-Dist: pyyaml>=6.0
Requires-Dist: chispa>=0.9.2
Requires-Dist: jsonschema>=4.0
Requires-Dist: pydeequ>=1.2.0
Provides-Extra: otel
Requires-Dist: opentelemetry-sdk>=1.24.0; extra == "otel"
Requires-Dist: opentelemetry-api>=1.24.0; extra == "otel"
Provides-Extra: docs
Requires-Dist: mkdocs; extra == "docs"
Requires-Dist: mkdocs-material; extra == "docs"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# open-spark-dlh-dq

Open source Plug-and-play Data Quality for Apache Spark (Batch + Streaming) with YAML checks, profiling, and OpenTelemetry.

---

## 📌 Project Overview
`open-spark-dlh-dq` is an open-source Python library providing a **Data Quality (DQ) framework for Apache Spark**.

It supports:

- ✅ **Batch & Streaming DQ** with declarative YAML suites
- ✅ **Custom checks** via Python (`dq_check`, `unit_test`)
- ✅ **CLI execution** for datasets in directories or Spark DataFrames
- ✅ **Inline checks** in PySpark scripts
- ✅ **Format support**: Parquet, CSV, Iceberg, Delta, JSON, ORC
- ✅ **Profiler & OpenTelemetry** for observability

Built on **PySpark**, **PyDeequ**, and **Chispa**, this library enables robust data validation pipelines.

---

## ✅ Features

- **Batch DQ**: Validate static datasets using YAML or inline rules.
- **Streaming DQ**: Apply checks on micro-batches via `foreachBatch`.
- **Custom Checks**: Extend with Python functions in `user_checks/`.
- **CLI Tool**: Run suites via `sparkdq run --yaml <suite.yml>`.
- **Profiler**: Generate summary stats and quantiles.
- **OpenTelemetry**: Capture spans and traces for test cases.

---

## 📂 Repository Structure

<pre>

open-spark-dlh-dq/
├─ pyproject.toml
├─ README.md
├─ LICENSE
│
├─ sparkdq/
│  ├─ cli/main.py                          # CLI entry point
│  ├─ config/                              # YAML loader, env vars, schema binding
│  ├─ core/                                # Models, registry, Spark session, runner
│  │  └─ validators/                       # Built-in + custom validator classes
│  ├─ profiling/profiler.py                # Profiling utilities
│  ├─ resources/open_spark_dlh_dq.yml      # Default YAML suite
│  ├─ observability/otel.py                # OpenTelemetry integration
│  └─ integrations/streaming.py            # foreachBatch wrapper
│
├─ user_checks/                            # User-defined checks
│  └─ example_checks.py
│
├─ examples/                               # Usage examples
│  ├─ suites/orders_dq.yml
│  ├─ batch_example.py
│  └─ streaming_example.py
│
└─ tests/                                  # Unit tests
   ├─ test_yaml_loader.py
   ├─ test_chispa_integration.py
   ├─ test_pydeequ_integration.py
   ├─ test_runner.py
   ├─ test_validators.py
   ├─ test_validator_contracts.py
   └─ test_cli.py

</pre>

---

## 🛠 Usage

### **Run CLI with YAML suite**
```bash
sparkdq run --yaml ./sparkdq/resources/open_spark_dlh_dq.yml --suite-name orders_dq --format text
```

### **Inline checks in PySpark**
```python
from sparkdq.core.runner import run_suite
from sparkdq.config.loader import load_yaml_suite

suite = load_yaml_suite("./sparkdq/resources/open_spark_dlh_dq.yml")
df = spark.read.parquet("./data/orders")
run_suite(df, suite)
```

### **Streaming example**
```bash
python examples/streaming_example.py
```

---

## 🧩 Custom Checks
Add Python methods in `user_checks/example_checks.py`:
```python
from sparkdq.core.registry import dq_check, unit_test

@dq_check("amount_positive")
def amount_positive(df):
    return df.filter(df.amount > 0).count() == df.count()
```
Reference them in YAML:
```yaml
test_cases:
  - name: amount_positive
    type: dq_check
```

---

## 📊 Profiler & OpenTelemetry
Enable profiling and observability in your pipeline:
```python
from sparkdq.profiling.profiler import profile_df
profile_df(df)
```

OpenTelemetry spans can be enabled via `sparkdq/observability/otel.py`.

---

## 🔨 Build & Publish

### **Build for PyPI (Windows)**
```powershell
./build.ps1
```

### **Build for PyPI (Linux)**
```bash
./build.sh
```

### **Example Repository to understand how to use**

https://github.com/aashish72it/spark-test


