← Back to Pull requests

[feature] Port Gamma Lake to a Rust core with Python bindings #63

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 10, 2026 15:20 UTC
Author

Description

Replace the pure-Python storage engine with a Delta-backed Rust core exposed through PyO3.

The project now has two supported deliverables:

  • the gamma_lake Rust crate

  • the gamma-lake Python package with its Polars-facing API
  • This intentionally does not introduce a standalone C/C++ API or native SDK.

    Highlights

  • Rust implementations of aligned reads and writes

  • Dense, as-of, sparse, target, and runtime-computed features

  • Copy and merge overlap modes

  • Predicate pushdown and DataFusion table integration

  • Bounded-memory sorting with disk spilling

  • Feature annotations and consolidation

  • Local, S3 (s3://), Azure (az://, abfss://) and GCS (gs://) Delta storage

  • Per-table external locking

  • Transaction logging and automatic rollback of failed writes

  • Bounded re-plan-and-retry of writes that conflict with another writer

  • Tagged rollback that preserves unrelated concurrent writers' commits

  • allow_new_index_values=False rejects writes that would add index keys

  • Removal of the Ray, telemetry and pure-Python I/O modules

  • Rust, Python, compatibility, locking, rollback, and storage conformance tests
  • Public APIs

    GammaFeatureLake keeps the 0.2 contract (Polars in, Polars/LazyFrame out). NativeLake is the thin, lower-level wrapper over the Rust core. The differences are tabulated in [Native-Engine](docs/wiki/Native-Engine.md#gammafeaturelake-or-nativelake).

    Breaking changes

    Full list in CHANGELOG.md and docs/wiki/Migrating-from-0.2.md. Summary:

  • GammaFeatureLake always uses the Rust engine; the run_on_ray_cluster and io fields, the Ray execution path and the ray extra are removed.

  • Unknown configuration fields are rejected; model_copy(update=...) validates the update; DEFAULT_INDEX_SCHEMA is removed.

  • Delta settings move under delta_options=DeltaOptions(...).

  • add_ methods accept Polars DataFrames and return None; the third positional argument is now overlap_mode.

  • Column types: restricted sort-key types; new datetimes stored as us (sub-microsecond values raise UnsupportedError); new time/duration features rejected; arrays stored as lists; categoricals stored as strings. Datetime, time and duration features that 0.2 stored as integers keep their types.

  • A write that conflicts on all 10 attempts raises ConflictError. Two writers adding the same new feature now record versions 0 and 1 instead of two version 0s.

  • Some exception types change (I/O failures that carry an OS error raise the matching OSError subclass); a lake constructed or used before a fork raises RuntimeError in the child instead of hanging.
  • Related issues

  • Supersedes #61: allow_new_index_values covers allow_new_index_rows.

  • Makes #43 moot: the io module it changes is removed.
  • Rollback behavior

    Each row write is recorded in the append-only transaction log.

    If a write fails after committing to one or more Delta tables, Gamma Lake identifies that write's commits by transaction ID and rolls them back while preserving unrelated writers' commits. If rollback cannot safely complete without removing another writer's changes, the transaction remains failed and raises PartialWriteError.

    Review fixes in this round

    1. Field assignment works again. GammaFeatureLake is no longer frozen. Assigning a field drops the cached core handle and revalidates against the new configuration, so fs.enable_runtime_computed_features = True works as on main; main's six assignments in tests/base.py are restored. Assigning or model_copy(update=...)-ing compression/target_file_size moves them into delta_options with the deprecation warning, instead of being ignored. model_copy(update=...) validates the update. copy.copy, copy.deepcopy and model_copy(deep=True) work after the lake is used. As in 0.2, construction checks primary_sort_key against an existing index, and sort_keys is None before initialize(). The deprecation warning points at the caller's line.
    2. Columns 0.2 stored as longs keep their types. 0.2 (through polars-io-tools) stored ms/ns datetimes, durations and times as Delta longs and recorded their Polars types in a [cpl.mapping] block of the table description; the parquet ARROW:schema says int64. The Delta store restores those types from the snapshot it already loads, with no extra I/O. Scans cast them before filtering, so file pruning still applies. Appends, padding and merges write longs back. Copy-mode overlaps and consolidation record the types as 0.2 does, so 0.2 keeps reading them. A new compat scenario covers this: 0.2 writes, 0.3 appends, pads, merges, copies and consolidates, then 0.2 appends again.
    3. Concurrent writers adding different features all succeed again. A write that conflicts is rolled back and re-planned, up to 10 attempts. Between attempts it waits a random time of up to 50 ms, doubling up to 1 s, without holding the in-process write lock. This covers add_
    , add_index_rows, annotate, consolidate_feature_groups and runtime-feature registration. The reviewer's case of 4 processes, plus 8 and 16, now all succeed, with no duplicate keys and no misalignment. Each retry writes the data again.
    4. Wide writes are faster than main. About 80% of planning time was in SipHash HashSets over every index and input key. Keys are now hashed in hash-partitioned groups on threads with foldhash, and unsorted input gets a parallel stable sample sort. Adding a new 4-feature group over a 1M-row index takes 0.23 s per add_features, against 0.79 s before and 0.27 s on main. 16 groups take 3.8 s, against 12.8 s before and 4.3 s on main. Read checksums are identical on main, the old head and this head. There is a new ASV suite, GammaLakeFeatureGroupWriteSuite.
    5. CI configuration.
    - Dependabot's first cargo entry is directory: "/" again, so it no longer overlaps the /rust entry.
    - deny.toml ignores RUSTSEC-2026-0543, -0555 and -0542 (unmaintained chrono, chrono-tz and humantime, which come in through arrow, datafusion, deltalake and object_store).
    - url is bumped to 2.5.9 for RUSTSEC-2026-0592, published 2026-11-20. That version percent-encodes ^, so object store URLs containing ^ are now rejected, as spaces already were.
    6. Smaller items.
    - Error, Op, OverlapMode, SignalType and the option structs (LakeOptions, AddOptions, CreateOptions, DeltaOptions) are #[non_exhaustive]. Build options from Default and set fields.
    - The docs now say which I/O failures raise OSError subclasses; most still raise RuntimeError.
    - Sub-microsecond np.datetime64 bounds round down as 0.2 did, or stay exact on a nanosecond column.
    - The lazy-open and stacklevel items are covered in 1. On the D-unit correction: it is accepted, with no change.

    Integration review: one cross-commit issue was found and fixed. Nanosecond bounds on an index restored as Datetime("ns") would have been rounded to µs.

    Earlier review fixes

  • Fork guard: the process-wide tokio runtime records its pid; reads and writes in a forked child (including while a parent thread holds the write lock) raise RuntimeError.

  • Table commits and annotations run 16 at a time instead of all at once.

  • A pushed-down predicate's DNF size is bounded before expansion. Each top-level conjunct is pushed on its own, and only those that would exceed 64 clauses are dropped, so a selective sort-key filter survives next to large feature conditions.

  • As-of table scans are bounded by the tolerance on the side a match can cross, so a read near the end of a lake no longer loads the whole history.

  • Without a memory_limit, the index and up to 16 tables are prepared concurrently (16-group read: 0.264 s → 0.115 s locally); with a limit they are still sorted one at a time.

  • New read benchmark case with 16 feature groups.

  • DeltaOptions hides inputs (credentials) in validation errors.

  • cargo deny check advisories passes; the remaining ignores are documented in deny.toml.

  • Docs, changelog and README aligned with the code; Pyodide CI step, JS .gitignore entries, unused datafusion dev-dependency and stray junit outputs removed.
  • Release work (version bump, wheel platforms, conda-forge, third-party licenses, sdist contents) is left for a follow-up.

    Type of Change

  • Bug fix

  • New feature

  • Documentation update

  • Refactor / code cleanup

  • CI / build configuration

  • Other (describe below)
  • Checklist

  • Linting passes (make lint): make format && make lint passed

  • Tests pass (make test):

  • - GAMMA_LAKE_OLD_SRC=$PWD/build/old-engine python -m pytest gammalake/tests -q: 335 passed, 0 skipped
    - cd rust && cargo nextest run --workspace: 124 passed
    - cargo test --doc --workspace: 2 passed
    - cargo deny --manifest-path {Cargo.toml,rust/Cargo.toml} --all-features check advisories: ok for both
  • New tests added for new functionality

  • Documentation updated (if applicable)

  • Changelog / version bump (if applicable) — changelog updated; version bump deferred to release work
  • Jira: CCRT-7507

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: timkpaine Review duration: 28858m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #63"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%