A tool for comparing large datasets using DuckDB
Project description
____ _ _ _
| _ \ ___| | |_ __ _| | ___ _ __ ___
| | | |/ _ \ | __/ _` | | / _ \ '_ \/ __|
| |_| | __/ | || (_| | |__| __/ | | \__ \
|____/ \___|_|\__\__,_|_____\___|_| |_|___/
DeltaLens - Data Comparison Tool
DeltaLens is a powerful tool for comparing large datasets using 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 for analysis
- Support for reference datasets
- Docker support for containerized execution
- CLI and Python API interfaces
Installation
# Clone the repository
git clone https://github.com/unclepaul84/duck-db-datacompare.git
cd duck-db-datacompare
#create and activate venv
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
Basic Usage
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 modificationsnew_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
Command Line Interface
# Basic comparison
python cli.py --config data/compare.config.json --run-name daily_compare
# Full options
python cli.py \
--config data/compare.config.json \
--run-name daily_compare \
--output-dir ./results \
--persistent \
--continue-on-error \
--export-sqlite \
--sqlite-sample 5000 \
--log-level DEBUG
Docker
# Run with docker-compose
docker-compose up
# Run with custom arguments
docker-compose run deltalens --run-name custom_run --log-level DEBUG
Using DeltaLens in Jupyter Notebooks
DeltaLens can be used interactively in Jupyter notebooks for data comparison analysis. See data_compate.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_LOG_LEVEL |
Logging level | INFO |
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
# Install development dependencies
pip install -r dependencies.txt
pip install -r dev.dependencies.txt
# Run tests
pytest -v
# Run tests with coverage
pytest --cov=delta_lens -v
License
MIT License
Contributing
- Fork the repository
- Create a feature branch
- Submit a pull request
Project details
Release history Release notifications | RSS feed
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 delta_lens-0.1.2.tar.gz.
File metadata
- Download URL: delta_lens-0.1.2.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f06832c07a3fe561095cd9046991265c953ce8859e24e80180d488995f9db330
|
|
| MD5 |
730815a2c223343d0915a0102605c96c
|
|
| BLAKE2b-256 |
03c1ff98840c0d4956877e5764713820ae26ac16bfb3b17de95e23b16782e90f
|
File details
Details for the file delta_lens-0.1.2-py3-none-any.whl.
File metadata
- Download URL: delta_lens-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62f089711af6a05e8a2cd5a40942238715fca3b9da87dfa8521e934f9eb2a554
|
|
| MD5 |
68a7c2c1e9e8ae15bccf519ca9755d91
|
|
| BLAKE2b-256 |
d3ec39ffba90431ebf514f7be576d1646721d68aca1151e9e4bdb95133e6c6cd
|