lakefreight 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lakefreight-0.2.0/CHANGELOG.md +43 -0
- lakefreight-0.2.0/CONTRIBUTING.md +62 -0
- lakefreight-0.2.0/LICENSE +21 -0
- lakefreight-0.2.0/MANIFEST.in +5 -0
- lakefreight-0.2.0/PKG-INFO +188 -0
- lakefreight-0.2.0/README.md +150 -0
- lakefreight-0.2.0/docs/architecture.svg +92 -0
- lakefreight-0.2.0/docs/design-decisions.md +116 -0
- lakefreight-0.2.0/docs/migration-guide.md +229 -0
- lakefreight-0.2.0/examples/metadata_sample.csv +18 -0
- lakefreight-0.2.0/examples/profiles_sample.csv +26 -0
- lakefreight-0.2.0/pyproject.toml +64 -0
- lakefreight-0.2.0/setup.cfg +4 -0
- lakefreight-0.2.0/sql/ddl/01_control_tables.sql +77 -0
- lakefreight-0.2.0/sql/ddl/02_seed_config.sql +92 -0
- lakefreight-0.2.0/src/lakefreight/__init__.py +0 -0
- lakefreight-0.2.0/src/lakefreight/__main__.py +5 -0
- lakefreight-0.2.0/src/lakefreight/chunk_planner.py +107 -0
- lakefreight-0.2.0/src/lakefreight/cli.py +82 -0
- lakefreight-0.2.0/src/lakefreight/config.py +85 -0
- lakefreight-0.2.0/src/lakefreight/defaults.toml +45 -0
- lakefreight-0.2.0/src/lakefreight/generate.py +311 -0
- lakefreight-0.2.0/src/lakefreight/handlers.py +210 -0
- lakefreight-0.2.0/src/lakefreight/models.py +60 -0
- lakefreight-0.2.0/src/lakefreight/planning.py +81 -0
- lakefreight-0.2.0/src/lakefreight/py.typed +0 -0
- lakefreight-0.2.0/src/lakefreight/reconcile.py +78 -0
- lakefreight-0.2.0/src/lakefreight/register.py +309 -0
- lakefreight-0.2.0/src/lakefreight/renderer.py +125 -0
- lakefreight-0.2.0/src/lakefreight/store.py +78 -0
- lakefreight-0.2.0/src/lakefreight/templates/copy_unload.sql.j2 +19 -0
- lakefreight-0.2.0/src/lakefreight.egg-info/PKG-INFO +188 -0
- lakefreight-0.2.0/src/lakefreight.egg-info/SOURCES.txt +41 -0
- lakefreight-0.2.0/src/lakefreight.egg-info/dependency_links.txt +1 -0
- lakefreight-0.2.0/src/lakefreight.egg-info/entry_points.txt +2 -0
- lakefreight-0.2.0/src/lakefreight.egg-info/requires.txt +20 -0
- lakefreight-0.2.0/src/lakefreight.egg-info/top_level.txt +1 -0
- lakefreight-0.2.0/stepfunctions/extract_lane.asl.json +149 -0
- lakefreight-0.2.0/tests/test_chunk_planner.py +52 -0
- lakefreight-0.2.0/tests/test_cli.py +42 -0
- lakefreight-0.2.0/tests/test_generate.py +105 -0
- lakefreight-0.2.0/tests/test_register.py +148 -0
- lakefreight-0.2.0/tests/test_renderer.py +111 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to lakefreight are recorded here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.2.0] - 2026-11-25
|
|
8
|
+
|
|
9
|
+
First release published to PyPI.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `lakefreight register`: registers a table's unloaded Parquet files as a Delta Lake or Apache Iceberg table without rewriting them. Only files named in a committed manifest are included, and the newest manifest per chunk wins. Refuses incomplete tables, files with the wrong size, schema drift between chunks, and nanosecond timestamps.
|
|
14
|
+
- `delta` and `iceberg` install extras.
|
|
15
|
+
- Manifests record `chunks_in_table` and `written_at`, so readers can check completeness and choose between reruns.
|
|
16
|
+
|
|
17
|
+
- `lakefreight config` shows the settings in use and writes an editable `lakefreight.toml`.
|
|
18
|
+
- Packaging for PyPI: default settings, templates and `py.typed` ship in the wheel, and a release workflow publishes with trusted publishing.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- Default settings ship inside the package. Settings are read from `--config`, then `$LAKEFREIGHT_CONFIG`, then `./lakefreight.toml`, then the built-in defaults. The repository's `config/defaults.toml` is gone.
|
|
23
|
+
|
|
24
|
+
- Timestamp columns are unloaded at microsecond precision (`TIMESTAMP_NTZ(6)`), and `TIME` columns as text, so Spark, Databricks and Iceberg v2 can read the files.
|
|
25
|
+
|
|
26
|
+
## [0.1.0] - 2026-11-25
|
|
27
|
+
|
|
28
|
+
First public release.
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
|
|
32
|
+
- `lakefreight plan`: generates Snowflake `COPY INTO` unload SQL and a work-item list from a metadata CSV, with no database connection.
|
|
33
|
+
- Chunk planner that packs months into even-sized chunks, with predicates that cover every value including NULL dates.
|
|
34
|
+
- Sensitivity routing into `RESTRICTED`, `PII` and `INTERNAL` zones that fails closed on missing classification.
|
|
35
|
+
- Detokenization of restricted columns through a cross-reference table, with row-count and unmatched-token reconciliation.
|
|
36
|
+
- Control-table DDL and a seed script for Snowflake.
|
|
37
|
+
- AWS Lambda handlers and a Step Functions state machine for running work items at scale. Not yet run against live services.
|
|
38
|
+
- Claude Code skill for generating extract SQL.
|
|
39
|
+
- Migration guide and design decision records.
|
|
40
|
+
|
|
41
|
+
[Unreleased]: https://github.com/sidbhaumik/lakefreight/compare/v0.2.0...HEAD
|
|
42
|
+
[0.2.0]: https://github.com/sidbhaumik/lakefreight/compare/v0.1.0...v0.2.0
|
|
43
|
+
[0.1.0]: https://github.com/sidbhaumik/lakefreight/releases/tag/v0.1.0
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Contributing to lakefreight
|
|
2
|
+
|
|
3
|
+
Thanks for your interest. Bug reports, documentation fixes and new features are all welcome.
|
|
4
|
+
|
|
5
|
+
## Set up
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/sidbhaumik/lakefreight.git
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
cd lakefreight && python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
You need Python 3.11 or later. No Snowflake or AWS account is needed to develop or test the planning and SQL generation code.
|
|
16
|
+
|
|
17
|
+
## Before you open a pull request
|
|
18
|
+
|
|
19
|
+
Run the same checks as CI:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
.venv/bin/ruff check src tests
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
.venv/bin/ruff format --check src tests
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
.venv/bin/python -m pytest -q
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
- Add or update tests for any change in behaviour. The SQL renderer and chunk planner are the core of the project; changes there need tests that show the generated SQL.
|
|
34
|
+
- Add a line under `[Unreleased]` in `CHANGELOG.md`.
|
|
35
|
+
- Keep pull requests to one change each.
|
|
36
|
+
|
|
37
|
+
## Design rules
|
|
38
|
+
|
|
39
|
+
These are deliberate. Please don't change them without opening an issue first; [docs/design-decisions.md](docs/design-decisions.md) explains each one.
|
|
40
|
+
|
|
41
|
+
- Sensitivity routing fails closed: missing classification is treated as sensitive.
|
|
42
|
+
- Chunk predicates must cover every value of the chunk column, including NULL.
|
|
43
|
+
- Joins that replace values use `LEFT JOIN`, and reconciliation counts come from the un-joined source.
|
|
44
|
+
- A manifest is written only after reconciliation passes.
|
|
45
|
+
|
|
46
|
+
## Releasing
|
|
47
|
+
|
|
48
|
+
Maintainers only. Releases are published to PyPI by GitHub Actions using trusted publishing.
|
|
49
|
+
|
|
50
|
+
1. Move the `[Unreleased]` entries in `CHANGELOG.md` under a new version heading with today's date, and update the comparison links at the bottom.
|
|
51
|
+
2. Set the same version in `pyproject.toml`.
|
|
52
|
+
3. Merge to `main` and wait for CI to pass.
|
|
53
|
+
4. Optional: run the Release workflow by hand to publish to TestPyPI and check the result.
|
|
54
|
+
5. Create a GitHub release with the tag `v<version>`. Publishing the release uploads the package to PyPI. The workflow refuses a tag that doesn't match the version in `pyproject.toml`.
|
|
55
|
+
|
|
56
|
+
## Reporting a bug
|
|
57
|
+
|
|
58
|
+
Open an issue with the command you ran, a minimal metadata CSV that reproduces the problem, what you expected, and what happened. Remove any real table names or data first.
|
|
59
|
+
|
|
60
|
+
## Security
|
|
61
|
+
|
|
62
|
+
Do not report security problems in a public issue. Use GitHub's private vulnerability reporting on this repository instead.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sidbhaumik
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lakefreight
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Bulk-move warehouse tables into open lakehouse files on cloud storage, for any engine to read
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/sidbhaumik/lakefreight
|
|
7
|
+
Project-URL: Documentation, https://github.com/sidbhaumik/lakefreight/tree/main/docs
|
|
8
|
+
Project-URL: Issues, https://github.com/sidbhaumik/lakefreight/issues
|
|
9
|
+
Keywords: snowflake,s3,parquet,data-migration,lakehouse,databricks,redshift,bigquery,delta-lake,iceberg
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Topic :: Database
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: jinja2>=3.1
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
24
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
25
|
+
Requires-Dist: pyarrow>=14; extra == "dev"
|
|
26
|
+
Requires-Dist: deltalake>=1.0; extra == "dev"
|
|
27
|
+
Requires-Dist: pyiceberg[sql-sqlite]>=0.9; extra == "dev"
|
|
28
|
+
Provides-Extra: delta
|
|
29
|
+
Requires-Dist: pyarrow>=14; extra == "delta"
|
|
30
|
+
Requires-Dist: deltalake>=1.0; extra == "delta"
|
|
31
|
+
Provides-Extra: iceberg
|
|
32
|
+
Requires-Dist: pyarrow>=14; extra == "iceberg"
|
|
33
|
+
Requires-Dist: pyiceberg>=0.9; extra == "iceberg"
|
|
34
|
+
Provides-Extra: pipeline
|
|
35
|
+
Requires-Dist: snowflake-connector-python>=3.12; extra == "pipeline"
|
|
36
|
+
Requires-Dist: boto3>=1.34; extra == "pipeline"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# lakefreight
|
|
40
|
+
|
|
41
|
+
[](https://github.com/sidbhaumik/lakefreight/actions/workflows/ci.yml)
|
|
42
|
+
[](https://pypi.org/project/lakefreight/)
|
|
43
|
+
[](https://github.com/sidbhaumik/lakefreight/blob/main/pyproject.toml)
|
|
44
|
+
[](https://github.com/sidbhaumik/lakefreight/blob/main/LICENSE)
|
|
45
|
+
[](https://github.com/astral-sh/ruff)
|
|
46
|
+
|
|
47
|
+
**Bulk-move warehouse tables into open lakehouse files on cloud storage, so any engine can read them.**
|
|
48
|
+
|
|
49
|
+
lakefreight unloads thousands of tables from a source warehouse into Parquet files on object storage, in a layout that Databricks, Snowflake, Redshift and BigQuery can all load or query. It plans the work from your metadata, keeps sensitive data in separate zones, and reconciles every extract before it is released.
|
|
50
|
+
|
|
51
|
+
It is built for the hard version of the job: thousands of tables, petabytes of data, many years of history, a fixed deadline, and a hand-off to storage owned by another cloud account in another region. The same method works for much smaller moves.
|
|
52
|
+
|
|
53
|
+
## Support matrix
|
|
54
|
+
|
|
55
|
+
| | Supported today | On the roadmap |
|
|
56
|
+
|---|---|---|
|
|
57
|
+
| **Source** | Snowflake | Other warehouses |
|
|
58
|
+
| **Target storage** | Amazon S3 | Google Cloud Storage, Azure Data Lake Storage |
|
|
59
|
+
| **File format** | Parquet, with a manifest and schema sidecar per table | |
|
|
60
|
+
| **Table format** | Delta Lake or Apache Iceberg, registered over the same Parquet files without rewriting them | Incremental re-registration after a re-extract |
|
|
61
|
+
| **Readers** | Any engine that reads Parquet, Delta or Iceberg: Databricks, Snowflake, Redshift, BigQuery | One-step registration in each engine's catalog |
|
|
62
|
+
| **Orchestration** | AWS Step Functions | |
|
|
63
|
+
|
|
64
|
+
**Status:** alpha. SQL generation, chunk planning, zone routing, reconciliation rules and table registration are unit tested; registered Delta and Iceberg tables are read back with delta-rs, pyiceberg and DuckDB in the tests. The Snowflake and AWS execution path (control-table DDL, Lambda handlers, state machine) and reads from Spark or Databricks have not yet been run against live services.
|
|
65
|
+
|
|
66
|
+
## What it does
|
|
67
|
+
|
|
68
|
+

|
|
69
|
+
|
|
70
|
+
- **Generates extract SQL from metadata.** One `COPY INTO` per table, or per date chunk for large tables. Nothing is hand-written.
|
|
71
|
+
- **Routes by sensitivity.** Three zones, each with its own stage, bucket location, key and role:
|
|
72
|
+
- `RESTRICTED`: tables with tokenized identifiers, such as government ID numbers, that must leave in clear form
|
|
73
|
+
- `PII`: tables with other personal data
|
|
74
|
+
- `INTERNAL`: tables explicitly classified as non-sensitive
|
|
75
|
+
|
|
76
|
+
Unknown classification is treated as sensitive.
|
|
77
|
+
- **Splits large tables into even chunks.** Months are packed to a target size, and the predicates cover every possible value, including NULL dates.
|
|
78
|
+
- **Detokenizes restricted columns** through a cross-reference table, with checks that the join neither drops nor duplicates rows.
|
|
79
|
+
- **Reconciles before release.** A manifest is written only when the unloaded row count equals the source count; the receiving side loads only what has a manifest.
|
|
80
|
+
- **Restarts at chunk level.** Every table or chunk is a tracked work item.
|
|
81
|
+
- **Registers open table formats.** `lakefreight register` turns a table's unloaded files into a Delta Lake or Apache Iceberg table without rewriting them. Only files named in a committed manifest are included; it refuses incomplete tables, files still replicating, schema drift between chunks, and nanosecond timestamps that Spark and Iceberg v2 can't read.
|
|
82
|
+
|
|
83
|
+
## Install
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pip install lakefreight
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Add the extra for the table format you want to register:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pip install "lakefreight[delta]"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install "lakefreight[iceberg]"
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Then create a settings file to edit, and run `lakefreight --help` for the commands:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
lakefreight config --write
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Try it in two minutes
|
|
106
|
+
|
|
107
|
+
No Snowflake or AWS account needed. Clone the repo for the sample data; this generates extract SQL for five sample tables from a fictional travel company:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
git clone https://github.com/sidbhaumik/lakefreight.git
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
cd lakefreight && python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
.venv/bin/lakefreight plan --metadata examples/metadata_sample.csv --profiles examples/profiles_sample.csv --out generated
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Output:
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
5 tables -> 17 work items in generated/
|
|
125
|
+
status: NEEDS_PROFILE 1, READY 16
|
|
126
|
+
ready by zone: INTERNAL 1, PII 2, RESTRICTED 13
|
|
127
|
+
note: TRAVEL.WEB.CLICK_EVENTS: chunk column EVENT_TS: confirm it prunes before using it
|
|
128
|
+
note: TRAVEL.LEGACY.MISC_NOTES: table PII/RESTRICTED flag missing; treated as sensitive
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Open `generated/RESTRICTED/TRAVEL.BOOKINGS.RESERVATION/0002_202203_202204.sql` to see an unload with the xref join and its two reconciliation queries.
|
|
132
|
+
|
|
133
|
+
To register a table's unloaded files as Delta Lake (Iceberg works the same way with `--format iceberg`, a catalog and a table name):
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
.venv/bin/lakefreight register --format delta --table-root s3://my-egress/internal/TRAVEL/BOOKINGS/RESERVATION
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Run the tests:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
.venv/bin/python -m pytest -q
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Documentation
|
|
146
|
+
|
|
147
|
+
| Document | Read it when |
|
|
148
|
+
|---|---|
|
|
149
|
+
| [Migration guide](https://github.com/sidbhaumik/lakefreight/blob/main/docs/migration-guide.md) | You have a migration like this to run and want the method, step by step |
|
|
150
|
+
| [Design decisions](https://github.com/sidbhaumik/lakefreight/blob/main/docs/design-decisions.md) | You want to know why it is built this way, and what was rejected |
|
|
151
|
+
|
|
152
|
+
## Claude skill
|
|
153
|
+
|
|
154
|
+
The repo includes a [Claude Code skill](https://github.com/sidbhaumik/lakefreight/blob/main/.claude/skills/generate-extract-sql/SKILL.md) that drives the generator. Open the repo in Claude Code and ask, for example, "generate extract SQL for the tables in my_metadata.csv". Claude normalizes the file, runs the generator, and reports which tables need a decision.
|
|
155
|
+
|
|
156
|
+
## Repository layout
|
|
157
|
+
|
|
158
|
+
| Path | Purpose |
|
|
159
|
+
|---|---|
|
|
160
|
+
| `src/lakefreight/cli.py` | The `lakefreight` command |
|
|
161
|
+
| `src/lakefreight/generate.py` | `lakefreight plan`: metadata CSV in, SQL files out |
|
|
162
|
+
| `src/lakefreight/chunk_planner.py` | Packs months into chunks with gap-free predicates |
|
|
163
|
+
| `src/lakefreight/renderer.py` | Renders the unload, source-count and unmatched-token SQL |
|
|
164
|
+
| `src/lakefreight/templates/copy_unload.sql.j2` | The `COPY INTO` template |
|
|
165
|
+
| `src/lakefreight/reconcile.py` | Pass/fail rules, manifest and schema sidecar |
|
|
166
|
+
| `src/lakefreight/planning.py` | Creates work items in Snowflake from the control tables |
|
|
167
|
+
| `src/lakefreight/handlers.py` | Lambda handlers: list, submit, poll, reconcile |
|
|
168
|
+
| `src/lakefreight/register.py` | `lakefreight register`: Delta Lake or Iceberg metadata over the unloaded files |
|
|
169
|
+
| `stepfunctions/extract_lane.asl.json` | State machine, one execution per lane |
|
|
170
|
+
| `sql/ddl/` | Control tables and the script that seeds them from metadata |
|
|
171
|
+
| `src/lakefreight/defaults.toml` | Default settings: thresholds, zones, lanes, xref names. `lakefreight config --write` makes an editable copy |
|
|
172
|
+
| `examples/` | Sample metadata and month profiles |
|
|
173
|
+
| `.claude/skills/` | The Claude skill |
|
|
174
|
+
|
|
175
|
+
## Not included
|
|
176
|
+
|
|
177
|
+
- Infrastructure as code: buckets, KMS keys, replication rules, stages, storage integrations, IAM, Lambda packaging.
|
|
178
|
+
- A single-pass `PARTITION BY` unload for large tables with no date column.
|
|
179
|
+
- Replication tracking, egress purge, and the delta pass for tables that change during the migration.
|
|
180
|
+
- Adding a re-extracted chunk to a table that is already registered. Today, delete the table metadata and register again.
|
|
181
|
+
|
|
182
|
+
## Contributing
|
|
183
|
+
|
|
184
|
+
See [CONTRIBUTING.md](https://github.com/sidbhaumik/lakefreight/blob/main/CONTRIBUTING.md). Changes are listed in [CHANGELOG.md](https://github.com/sidbhaumik/lakefreight/blob/main/CHANGELOG.md).
|
|
185
|
+
|
|
186
|
+
## License
|
|
187
|
+
|
|
188
|
+
[MIT](https://github.com/sidbhaumik/lakefreight/blob/main/LICENSE)
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# lakefreight
|
|
2
|
+
|
|
3
|
+
[](https://github.com/sidbhaumik/lakefreight/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/lakefreight/)
|
|
5
|
+
[](https://github.com/sidbhaumik/lakefreight/blob/main/pyproject.toml)
|
|
6
|
+
[](https://github.com/sidbhaumik/lakefreight/blob/main/LICENSE)
|
|
7
|
+
[](https://github.com/astral-sh/ruff)
|
|
8
|
+
|
|
9
|
+
**Bulk-move warehouse tables into open lakehouse files on cloud storage, so any engine can read them.**
|
|
10
|
+
|
|
11
|
+
lakefreight unloads thousands of tables from a source warehouse into Parquet files on object storage, in a layout that Databricks, Snowflake, Redshift and BigQuery can all load or query. It plans the work from your metadata, keeps sensitive data in separate zones, and reconciles every extract before it is released.
|
|
12
|
+
|
|
13
|
+
It is built for the hard version of the job: thousands of tables, petabytes of data, many years of history, a fixed deadline, and a hand-off to storage owned by another cloud account in another region. The same method works for much smaller moves.
|
|
14
|
+
|
|
15
|
+
## Support matrix
|
|
16
|
+
|
|
17
|
+
| | Supported today | On the roadmap |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| **Source** | Snowflake | Other warehouses |
|
|
20
|
+
| **Target storage** | Amazon S3 | Google Cloud Storage, Azure Data Lake Storage |
|
|
21
|
+
| **File format** | Parquet, with a manifest and schema sidecar per table | |
|
|
22
|
+
| **Table format** | Delta Lake or Apache Iceberg, registered over the same Parquet files without rewriting them | Incremental re-registration after a re-extract |
|
|
23
|
+
| **Readers** | Any engine that reads Parquet, Delta or Iceberg: Databricks, Snowflake, Redshift, BigQuery | One-step registration in each engine's catalog |
|
|
24
|
+
| **Orchestration** | AWS Step Functions | |
|
|
25
|
+
|
|
26
|
+
**Status:** alpha. SQL generation, chunk planning, zone routing, reconciliation rules and table registration are unit tested; registered Delta and Iceberg tables are read back with delta-rs, pyiceberg and DuckDB in the tests. The Snowflake and AWS execution path (control-table DDL, Lambda handlers, state machine) and reads from Spark or Databricks have not yet been run against live services.
|
|
27
|
+
|
|
28
|
+
## What it does
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
- **Generates extract SQL from metadata.** One `COPY INTO` per table, or per date chunk for large tables. Nothing is hand-written.
|
|
33
|
+
- **Routes by sensitivity.** Three zones, each with its own stage, bucket location, key and role:
|
|
34
|
+
- `RESTRICTED`: tables with tokenized identifiers, such as government ID numbers, that must leave in clear form
|
|
35
|
+
- `PII`: tables with other personal data
|
|
36
|
+
- `INTERNAL`: tables explicitly classified as non-sensitive
|
|
37
|
+
|
|
38
|
+
Unknown classification is treated as sensitive.
|
|
39
|
+
- **Splits large tables into even chunks.** Months are packed to a target size, and the predicates cover every possible value, including NULL dates.
|
|
40
|
+
- **Detokenizes restricted columns** through a cross-reference table, with checks that the join neither drops nor duplicates rows.
|
|
41
|
+
- **Reconciles before release.** A manifest is written only when the unloaded row count equals the source count; the receiving side loads only what has a manifest.
|
|
42
|
+
- **Restarts at chunk level.** Every table or chunk is a tracked work item.
|
|
43
|
+
- **Registers open table formats.** `lakefreight register` turns a table's unloaded files into a Delta Lake or Apache Iceberg table without rewriting them. Only files named in a committed manifest are included; it refuses incomplete tables, files still replicating, schema drift between chunks, and nanosecond timestamps that Spark and Iceberg v2 can't read.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install lakefreight
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Add the extra for the table format you want to register:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install "lakefreight[delta]"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install "lakefreight[iceberg]"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Then create a settings file to edit, and run `lakefreight --help` for the commands:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
lakefreight config --write
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Try it in two minutes
|
|
68
|
+
|
|
69
|
+
No Snowflake or AWS account needed. Clone the repo for the sample data; this generates extract SQL for five sample tables from a fictional travel company:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
git clone https://github.com/sidbhaumik/lakefreight.git
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
cd lakefreight && python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
.venv/bin/lakefreight plan --metadata examples/metadata_sample.csv --profiles examples/profiles_sample.csv --out generated
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Output:
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
5 tables -> 17 work items in generated/
|
|
87
|
+
status: NEEDS_PROFILE 1, READY 16
|
|
88
|
+
ready by zone: INTERNAL 1, PII 2, RESTRICTED 13
|
|
89
|
+
note: TRAVEL.WEB.CLICK_EVENTS: chunk column EVENT_TS: confirm it prunes before using it
|
|
90
|
+
note: TRAVEL.LEGACY.MISC_NOTES: table PII/RESTRICTED flag missing; treated as sensitive
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Open `generated/RESTRICTED/TRAVEL.BOOKINGS.RESERVATION/0002_202203_202204.sql` to see an unload with the xref join and its two reconciliation queries.
|
|
94
|
+
|
|
95
|
+
To register a table's unloaded files as Delta Lake (Iceberg works the same way with `--format iceberg`, a catalog and a table name):
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
.venv/bin/lakefreight register --format delta --table-root s3://my-egress/internal/TRAVEL/BOOKINGS/RESERVATION
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Run the tests:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
.venv/bin/python -m pytest -q
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Documentation
|
|
108
|
+
|
|
109
|
+
| Document | Read it when |
|
|
110
|
+
|---|---|
|
|
111
|
+
| [Migration guide](https://github.com/sidbhaumik/lakefreight/blob/main/docs/migration-guide.md) | You have a migration like this to run and want the method, step by step |
|
|
112
|
+
| [Design decisions](https://github.com/sidbhaumik/lakefreight/blob/main/docs/design-decisions.md) | You want to know why it is built this way, and what was rejected |
|
|
113
|
+
|
|
114
|
+
## Claude skill
|
|
115
|
+
|
|
116
|
+
The repo includes a [Claude Code skill](https://github.com/sidbhaumik/lakefreight/blob/main/.claude/skills/generate-extract-sql/SKILL.md) that drives the generator. Open the repo in Claude Code and ask, for example, "generate extract SQL for the tables in my_metadata.csv". Claude normalizes the file, runs the generator, and reports which tables need a decision.
|
|
117
|
+
|
|
118
|
+
## Repository layout
|
|
119
|
+
|
|
120
|
+
| Path | Purpose |
|
|
121
|
+
|---|---|
|
|
122
|
+
| `src/lakefreight/cli.py` | The `lakefreight` command |
|
|
123
|
+
| `src/lakefreight/generate.py` | `lakefreight plan`: metadata CSV in, SQL files out |
|
|
124
|
+
| `src/lakefreight/chunk_planner.py` | Packs months into chunks with gap-free predicates |
|
|
125
|
+
| `src/lakefreight/renderer.py` | Renders the unload, source-count and unmatched-token SQL |
|
|
126
|
+
| `src/lakefreight/templates/copy_unload.sql.j2` | The `COPY INTO` template |
|
|
127
|
+
| `src/lakefreight/reconcile.py` | Pass/fail rules, manifest and schema sidecar |
|
|
128
|
+
| `src/lakefreight/planning.py` | Creates work items in Snowflake from the control tables |
|
|
129
|
+
| `src/lakefreight/handlers.py` | Lambda handlers: list, submit, poll, reconcile |
|
|
130
|
+
| `src/lakefreight/register.py` | `lakefreight register`: Delta Lake or Iceberg metadata over the unloaded files |
|
|
131
|
+
| `stepfunctions/extract_lane.asl.json` | State machine, one execution per lane |
|
|
132
|
+
| `sql/ddl/` | Control tables and the script that seeds them from metadata |
|
|
133
|
+
| `src/lakefreight/defaults.toml` | Default settings: thresholds, zones, lanes, xref names. `lakefreight config --write` makes an editable copy |
|
|
134
|
+
| `examples/` | Sample metadata and month profiles |
|
|
135
|
+
| `.claude/skills/` | The Claude skill |
|
|
136
|
+
|
|
137
|
+
## Not included
|
|
138
|
+
|
|
139
|
+
- Infrastructure as code: buckets, KMS keys, replication rules, stages, storage integrations, IAM, Lambda packaging.
|
|
140
|
+
- A single-pass `PARTITION BY` unload for large tables with no date column.
|
|
141
|
+
- Replication tracking, egress purge, and the delta pass for tables that change during the migration.
|
|
142
|
+
- Adding a re-extracted chunk to a table that is already registered. Today, delete the table metadata and register again.
|
|
143
|
+
|
|
144
|
+
## Contributing
|
|
145
|
+
|
|
146
|
+
See [CONTRIBUTING.md](https://github.com/sidbhaumik/lakefreight/blob/main/CONTRIBUTING.md). Changes are listed in [CHANGELOG.md](https://github.com/sidbhaumik/lakefreight/blob/main/CHANGELOG.md).
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
[MIT](https://github.com/sidbhaumik/lakefreight/blob/main/LICENSE)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1150 430" width="1150" height="430" role="img" aria-labelledby="title desc">
|
|
2
|
+
<title id="title">lakefreight architecture</title>
|
|
3
|
+
<desc id="desc">Metadata drives a chunk planner that creates work items. Step Functions runs them in lanes; Snowflake unloads Parquet into three sensitivity zones. Each chunk is reconciled; passing chunks get a manifest, are replicated to the target account, and are registered as Delta Lake or Iceberg tables for Databricks, Snowflake, Redshift and BigQuery. Failing chunks are marked failed and retried.</desc>
|
|
4
|
+
<defs>
|
|
5
|
+
<marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse">
|
|
6
|
+
<path d="M0,0 L10,5 L0,10 z" fill="#57606a"/>
|
|
7
|
+
</marker>
|
|
8
|
+
<style>
|
|
9
|
+
.box { fill: #f6f8fa; stroke: #57606a; stroke-width: 1.5; }
|
|
10
|
+
.zone { fill: #ddf4ff; stroke: #0969da; stroke-width: 1.5; }
|
|
11
|
+
.ok { fill: #dafbe1; stroke: #1a7f37; stroke-width: 1.5; }
|
|
12
|
+
.bad { fill: #ffebe9; stroke: #cf222e; stroke-width: 1.5; }
|
|
13
|
+
.t { font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif; font-size: 14px; fill: #1f2328; text-anchor: middle; }
|
|
14
|
+
.s { font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif; font-size: 12px; fill: #57606a; text-anchor: middle; }
|
|
15
|
+
.b { font-weight: 600; }
|
|
16
|
+
.line { stroke: #57606a; stroke-width: 1.5; fill: none; marker-end: url(#arrow); }
|
|
17
|
+
</style>
|
|
18
|
+
</defs>
|
|
19
|
+
<rect width="1150" height="430" fill="#ffffff"/>
|
|
20
|
+
|
|
21
|
+
<!-- Row 1: plan and unload, left to right -->
|
|
22
|
+
<rect class="box" x="20" y="30" width="190" height="76" rx="8"/>
|
|
23
|
+
<text class="t b" x="115" y="60">Metadata table</text>
|
|
24
|
+
<text class="s" x="115" y="80">columns, sizes,</text>
|
|
25
|
+
<text class="s" x="115" y="96">PII and restricted flags</text>
|
|
26
|
+
|
|
27
|
+
<rect class="box" x="250" y="30" width="190" height="76" rx="8"/>
|
|
28
|
+
<text class="t b" x="345" y="62">Chunk planner</text>
|
|
29
|
+
<text class="s" x="345" y="84">even, gap-free date chunks</text>
|
|
30
|
+
|
|
31
|
+
<rect class="box" x="480" y="30" width="190" height="76" rx="8"/>
|
|
32
|
+
<text class="t b" x="575" y="62">Work items</text>
|
|
33
|
+
<text class="s" x="575" y="84">one per table or chunk</text>
|
|
34
|
+
|
|
35
|
+
<rect class="box" x="710" y="30" width="190" height="76" rx="8"/>
|
|
36
|
+
<text class="t b" x="805" y="62">Step Functions</text>
|
|
37
|
+
<text class="s" x="805" y="84">lanes by size and sensitivity</text>
|
|
38
|
+
|
|
39
|
+
<rect class="box" x="940" y="30" width="190" height="76" rx="8"/>
|
|
40
|
+
<text class="t b" x="1035" y="62">COPY INTO</text>
|
|
41
|
+
<text class="s" x="1035" y="84">Snowflake writes Parquet</text>
|
|
42
|
+
|
|
43
|
+
<path class="line" d="M210,68 H248"/>
|
|
44
|
+
<path class="line" d="M440,68 H478"/>
|
|
45
|
+
<path class="line" d="M670,68 H708"/>
|
|
46
|
+
<path class="line" d="M900,68 H938"/>
|
|
47
|
+
<path class="line" d="M1035,106 V158"/>
|
|
48
|
+
|
|
49
|
+
<!-- Row 2: verify and hand off, right to left -->
|
|
50
|
+
<rect class="zone" x="940" y="160" width="190" height="96" rx="8"/>
|
|
51
|
+
<text class="t b" x="1035" y="186">S3 egress zones</text>
|
|
52
|
+
<text class="s" x="1035" y="208">RESTRICTED</text>
|
|
53
|
+
<text class="s" x="1035" y="225">PII</text>
|
|
54
|
+
<text class="s" x="1035" y="242">INTERNAL</text>
|
|
55
|
+
|
|
56
|
+
<rect class="box" x="710" y="170" width="190" height="76" rx="8"/>
|
|
57
|
+
<text class="t b" x="805" y="202">Reconcile</text>
|
|
58
|
+
<text class="s" x="805" y="224">rows unloaded = source rows?</text>
|
|
59
|
+
|
|
60
|
+
<rect class="ok" x="480" y="170" width="190" height="76" rx="8"/>
|
|
61
|
+
<text class="t b" x="575" y="202">Write manifest</text>
|
|
62
|
+
<text class="s" x="575" y="224">the commit marker</text>
|
|
63
|
+
|
|
64
|
+
<rect class="box" x="250" y="170" width="190" height="76" rx="8"/>
|
|
65
|
+
<text class="t b" x="345" y="202">S3 replication</text>
|
|
66
|
+
<text class="s" x="345" y="224">to the target account</text>
|
|
67
|
+
|
|
68
|
+
<rect class="box" x="20" y="170" width="190" height="76" rx="8"/>
|
|
69
|
+
<text class="t b" x="115" y="202">lakefreight register</text>
|
|
70
|
+
<text class="s" x="115" y="224">Delta Lake or Iceberg</text>
|
|
71
|
+
|
|
72
|
+
<path class="line" d="M940,208 H902"/>
|
|
73
|
+
<path class="line" d="M710,208 H672"/>
|
|
74
|
+
<text class="s" x="691" y="198">yes</text>
|
|
75
|
+
<path class="line" d="M480,208 H442"/>
|
|
76
|
+
<path class="line" d="M250,208 H212"/>
|
|
77
|
+
|
|
78
|
+
<!-- Failure branch -->
|
|
79
|
+
<rect class="bad" x="710" y="300" width="190" height="60" rx="8"/>
|
|
80
|
+
<text class="t b" x="805" y="326">Mark failed</text>
|
|
81
|
+
<text class="s" x="805" y="346">retried on the next run</text>
|
|
82
|
+
<path class="line" d="M805,246 V298"/>
|
|
83
|
+
<text class="s" x="822" y="276">no</text>
|
|
84
|
+
|
|
85
|
+
<!-- Readers -->
|
|
86
|
+
<rect class="box" x="20" y="300" width="420" height="60" rx="8"/>
|
|
87
|
+
<text class="t b" x="230" y="326">Any engine reads the tables</text>
|
|
88
|
+
<text class="s" x="230" y="346">Databricks · Snowflake · Redshift · BigQuery</text>
|
|
89
|
+
<path class="line" d="M115,246 V298"/>
|
|
90
|
+
|
|
91
|
+
<text class="s" x="575" y="410">Files without a manifest, such as failed attempts, are never released or registered.</text>
|
|
92
|
+
</svg>
|