-
Notifications
You must be signed in to change notification settings - Fork 10
add lance writer #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Hynek Kydlíček (hynky1999)
wants to merge
7
commits into
main
Choose a base branch
from
codex/add-lance-writer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add lance writer #120
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3c84489
add lance writer
hynky1999 dd1076b
add lance schema evolution
hynky1999 f0c9682
Merge remote-tracking branch 'origin/main' into codex/add-lance-writer
hynky1999 a016f78
carry lance fragment identity on rows
hynky1999 3c8e41b
validate lance fragment coverage in reducer
hynky1999 ab37d27
simplify lance column buffering
hynky1999 d980d51
harden distributed Lance commits
hynky1999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| --- | ||
| title: "Lance" | ||
| description: "Read immutable Lance dataset versions as fragment-aligned Refiner shards" | ||
| --- | ||
|
|
||
| # Lance | ||
|
|
||
| Lance support is optional: | ||
|
|
||
| ```bash | ||
| pip install macrodata-refiner[lance] | ||
| ``` | ||
|
|
||
| Use `load_lance(...)` to read a pinned Lance dataset version: | ||
|
|
||
| ```python | ||
| import refiner as mdr | ||
|
|
||
| pipeline = mdr.load_lance( | ||
| "s3://my-bucket/hands.lance", | ||
| version=42, | ||
| columns=["image", "frame_id"], | ||
| batch_size=128, | ||
| ) | ||
| ``` | ||
|
|
||
| When `version` is omitted, Refiner resolves the latest version once and pins it | ||
| for the pipeline. Column projection is pushed into Lance, and `batch_size` | ||
| controls the streamed Arrow batch size. Use `blob_handling` to select Lance's | ||
| blob materialization behavior when reading blob columns. | ||
|
|
||
| `load_lance` uses Lance's native storage layer. It rejects configured fsspec | ||
| filesystem objects and `storage_options`; provide a URI whose endpoint and | ||
| credentials are available to Lance instead. | ||
|
|
||
| Each Lance fragment becomes one Refiner shard. A worker may claim and process | ||
| multiple fragments over its lifetime. | ||
|
|
||
| ## Internal Notes | ||
|
|
||
| The source keeps the dataset URI and resolved version on the pipeline. It uses | ||
| ordinary row-range shards to assign fragment indices and attaches protected | ||
| fragment-ID and fragment-local-row-position columns to the rows. The | ||
| `add_columns` writer uses those columns to restore output order and validate | ||
| one-to-one row alignment. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| --- | ||
| title: "Lance" | ||
| description: "Write Lance files, datasets, and distributed schema evolution results" | ||
| --- | ||
|
|
||
| # Lance | ||
|
|
||
| Lance support is optional: | ||
|
|
||
| ```bash | ||
| pip install macrodata-refiner[lance] | ||
| ``` | ||
|
|
||
| ## Standalone files | ||
|
|
||
| Use `write_lance(...)` to create one independent Lance file per finalized | ||
| Refiner shard: | ||
|
|
||
| ```python | ||
| import refiner as mdr | ||
|
|
||
| pipeline = ( | ||
| mdr.read_parquet("s3://my-bucket/raw/*.parquet") | ||
| .write_lance("s3://my-bucket/lance-files/") | ||
| ) | ||
| ``` | ||
|
|
||
| ## Lance datasets | ||
|
|
||
| Use `write_lance_dataset(...)` for committed Lance datasets: | ||
|
|
||
| ```python | ||
| pipeline = ( | ||
| mdr.read_parquet("s3://my-bucket/raw/*.parquet") | ||
| .write_lance_dataset("s3://my-bucket/clean.lance", mode="create") | ||
| ) | ||
| ``` | ||
|
|
||
| Supported modes are `create`, `overwrite`, `append`, and `add_columns`. | ||
| Empty `create` and `overwrite` jobs commit an empty dataset when Refiner can | ||
| determine the output Arrow schema statically; otherwise they fail explicitly. | ||
|
|
||
| Lance opens dataset URIs through its native storage layer. Configured fsspec | ||
| filesystem objects and `storage_options` are therefore rejected instead of | ||
| being silently ignored. Put the endpoint and credentials in the URI or Lance's | ||
| supported environment/configuration. | ||
|
|
||
| ## Adding columns | ||
|
|
||
| Use `add_columns` for row-preserving enrichment such as model inference: | ||
|
|
||
| ```python | ||
| pipeline = ( | ||
| mdr.load_lance( | ||
| "s3://my-bucket/hands.lance", | ||
| version=42, | ||
| columns=["image"], | ||
| ) | ||
| .map( | ||
| detect_hands, | ||
| dtypes={ | ||
| "hand_boxes": mdr.datatype.list(mdr.datatype.float32()), | ||
| "detector_score": mdr.datatype.float32(), | ||
| }, | ||
| ) | ||
| .write_lance_dataset( | ||
| "s3://my-bucket/hands.lance", | ||
| mode="add_columns", | ||
| columns=["hand_boxes", "detector_score"], | ||
| ) | ||
| ) | ||
| ``` | ||
|
|
||
| The `columns` argument is required and only those columns are written. Existing | ||
| columns, including large blob columns, remain referenced by their original | ||
| files. Results may arrive out of order; Refiner restores fragment-local source | ||
| order before writing. Missing or duplicate results fail execution and do not | ||
| create a new dataset version. | ||
|
|
||
| ## Internal Notes | ||
|
|
||
| Workers buffer only the requested output columns plus internal ordering columns | ||
| as Arrow tables. At fragment completion, they reorder those tables with Arrow, | ||
| write uncommitted column files, and record replacement-fragment metadata. The | ||
| reducer commits finalized attempts once against the pinned read version with a | ||
| Lance merge operation. Before committing, it verifies that every non-empty | ||
| fragment in the pinned source version has exactly one finalized result. Cleanup | ||
| records only files created by each attempt, so rejected retries cannot delete | ||
| base dataset files. | ||
|
|
||
| This follows the worker-output/coordinator-commit pattern used by Spark, | ||
| Beam/Dataflow, Daft, and Ray Data. Refiner keeps Lance fragments as its work | ||
| unit because Lance schema evolution is fragment-based; repartitioning first | ||
| would require a keyed join or staging dataset. Hugging Face Datasets generally | ||
| materializes a new dataset revision instead of attaching column files to | ||
| existing fragments. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a caller creates a
DataFolderand later assigns a configured fsspec instance through its publicfssetter,_explicit_fsremainsFalsebecause it only snapshots the constructor argument here. The new Lance checks then accept that folder despite claiming to reject configured handles, pass only its reconstructed URI to Lance, and can fail or target default storage configuration; update the flag wheneverfsis assigned.Useful? React with 👍 / 👎.