Skip to main content

A tool for comparing large datasets using DuckDB

Project description

 ____       _ _        _                    
|  _ \  ___| | |_ __ _| |    ___ _ __  ___ 
| | | |/ _ \ | __/ _` | |   / _ \ '_ \/ __|
| |_| |  __/ | || (_| | |__|  __/ | | \__ \
|____/ \___|_|\__\__,_|_____\___|_| |_|___/
                                        

DeltaLens - Data Comparison Tool

DeltaLens is a powerful tool for comparing large datasets using the power of DuckDB as the comparison engine. It supports data transformations, automated field-level matching, and detailed comparison reporting.

flowchart LR
    Trades_1@{ shape: doc, label: "new_system_trades.csv" }
    Trades_2@{ shape: doc, label: "lagecy_system_trades.csv" }
    Config@{ shape: doc, label: "config.json" }
    Config-->TableQueryGenerator
    Trades_2 -->|load|DuckDB
    Trades_1 -->|load|DuckDB
    subgraph DeltaLens.py
        TableQueryGenerator@{ shape: subproc, label: "QueryGenerator" }
        TableQueryGenerator-->|generate compare queries|DuckDB
        DuckDB@{ shape: lin-cyl, label: "DuckDB" }
        DuckDB-->Exporter
        Exporter@{ shape: subproc, label: "Exporter" }
       
    end
    Exporter-->|export|Sqlite
    Sqlite@{ shape: lin-cyl, label: "results.sqlite" }

Features

  • Compare CSV datasets with configurable primary keys
  • Apply SQL transformations to data before comparison
  • Generate detailed field-level match statistics
  • Export results to SQLite and CSV for analysis
  • Support for larger than memory datasets
  • Support for reference datasets
  • Docker support for containerized execution
  • CLI and Python API interfaces
  • Data Pipeline and CI/CD friendly

Installation

Install from PyPI:

pip install delta-lens

see data_compare_legislators.ipynb for example.

Basic Usage

Command Line Interface

# Basic comparison
deltalens --config data/compare.config.json --run-name daily_compare

# Full options
deltalens \
  --config data/compare.config.json \
  --run-name daily_compare \
  --output-dir ./results \
  --persistent \
  --continue-on-error \
  --export-sqlite \
  --export-csv \
  --export-sampling-threshold 5000 \
  --export-mismatches-only \
  --log-level DEBUG

Or Pull the Docker image:

docker run unclepaul84/deltalens:latest

Using DeltaLens in Jupyter Notebooks

DeltaLens can be used interactively in Jupyter notebooks for data comparison analysis. See data_compare_legislators.ipynb

Configuration

Create a compare.config.json file:

{  
    "defaults":{},
    "entities": [
        {
            "entityName":"trade",
            "leftSide": {
                "title": "legacy",
                "inputFile":"data/legacy_system_trades.csv"
                
                

            },
            "rightSide": {
                "title": "new",
                "inputFile":"data/new_system_trades.csv"
            },
            "primaryKeys": ["trade_id"]
        
        }     
    ]
}

Environment Variables

Variable Description Default
DELTALENS_CONFIG Path to config file compare.config.json
DELTALENS_RUN_NAME Name for comparison run compare_YYYY-MM-DD
DELTALENS_OUTPUT_DIR Output directory .
DELTALENS_PERSISTENT Use persistent storage false
DELTALENS_EXPORT_SQLITE Export to SQLite true
DELTALENS_EXPORT_SAMPLING_THRESHOLD rowcount at which to start sampling 10000
DELTALENS_EXPORT_CSV export to gzipped csv true
DELTALENS_EXPORT_MISMATCHES_ONLY Export mismatched rows only true

Output Files

The tool generates several output files:

  • [run_name].duckdb: DuckDB database with comparison results (if persistent mode enabled)
  • [run_name].sqlite: SQLite export of comparison results (if enabled)

Resulting Tables include:

  • entity_compare_results: Overall comparison summary
  • [entity]_compare: Detailed record-level comparison
  • [entity]_compare_field_summary: Field-level match statistics

Development

Docker

# Run with docker-compose
docker-compose up

# Run with custom arguments
docker-compose run deltalens --run-name custom_run --log-level DEBUG

Generating Sample Data

DeltaLens includes a script to generate sample trade data for testing and demonstration purposes.

Sample Data Generator

The script creates two CSV files with randomized trade data:

  • legacy_system_trades.csv: Original trade data with modifications
  • new_system_trades.csv: Copy of original data with known differences
cd data
# Generate sample data (creates 2GB files by default)
python create_test_datasets.py
# Install development dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt

# Run tests
pytest -v

# Run tests with coverage
pytest --cov=delta_lens -v

License

MIT License

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

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

delta_lens-0.1.9.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

delta_lens-0.1.9-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file delta_lens-0.1.9.tar.gz.

File metadata

  • Download URL: delta_lens-0.1.9.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for delta_lens-0.1.9.tar.gz
Algorithm Hash digest
SHA256 c127cfd7f9ea4f3cf3373101dabe2557a32063ebb7a6322a677011034d40b4ca
MD5 b14a6a2b33460b4da90920efcaf3f8b4
BLAKE2b-256 166fd2558e4b5d68b44cf3589c69556997e2f425a549bad68eb4edb461221e53

See more details on using hashes here.

File details

Details for the file delta_lens-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: delta_lens-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for delta_lens-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 2d54d36c8ee24dfdfb4bb5a812298bb1abac5e7e2f0f8379236daae63ee5d8fc
MD5 5eb4361fa61425a787e5fbab5d0acdfb
BLAKE2b-256 859d6f3ed489eb1b3903129de344ec44bbff492abe9871ecac80df99f30872c6

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