Skip to content

feat: expose migrate_to_non_reusable_field_ids in Python and Java - #11472

Merged
Xuanwo merged 2 commits into
lance-format:mainfrom
vaibhavdabas16:feat/10684-non-reusable-field-id-bindings
Dec 1, 2026
Merged

Xuanwo merged 2 commits into
lance-format:mainfrom
vaibhavdabas16:feat/10684-non-reusable-field-id-bindings

Conversation

@vaibhavdabas16

Copy link
Copy Markdown
Contributor

Part of #10684 (item 1: Python and Java bindings for migrate_to_non_reusable_field_ids).

Dataset::migrate_to_non_reusable_field_ids had no binding, so only Rust callers could stop field IDs from being reused after a column is dropped. This adds:

  • Python: LanceDataset.migrate_to_non_reusable_field_ids(), plus the .pyi stub.
  • Java: Dataset.migrateToNonReusableFieldIds(), plus its JNI function. It takes the dataset write lock, like migrateManifestPathsV2.

Both mirror the existing manifest path migration bindings. The docs repeat the Rust method's warning: every client that writes to the dataset must enforce writer feature flags before the migration runs.

Item 2 of the issue, a create-time option such as WriteParams::enable_non_reusable_field_ids, changes WriteParams, so I'm leaving it for a separate PR.

Tests: both reproduce the example from the issue.

  • Python: test_migrate_to_non_reusable_field_ids[False/True]. It adds b, optionally migrates (checking that a second call is a no-op), drops b and adds c. Without the migration c reuses b's ID 1; with it, c gets ID 2.
  • Java: DatasetTest.testMigrateToNonReusableFieldIds covers the same sequence. After migrating, the re-added column gets ID 3 instead of double_id's dropped ID 2.

Checks run locally:

  • cargo check passes for python/ and for java/lance-jni.
  • ruff, ruff-format and rustfmt pass.
  • I couldn't run the Python or Java tests locally: there's no maturin, JDK or Maven on my machine. They run in CI.

Dataset::migrate_to_non_reusable_field_ids had no binding, so only
Rust callers could stop field IDs from being reused after a column is
dropped. Add LanceDataset.migrate_to_non_reusable_field_ids() and
Dataset.migrateToNonReusableFieldIds(), mirroring the existing
manifest path migration bindings.

Part of lance-format#10684.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added A-python Python bindings A-java Java bindings + JNI enhancement New feature or request labels Nov 25, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gate recommendation: approve.

The bindings reuse the existing Rust migration without introducing a second allocation path. Local Python and Java tests passed, including idempotency, persisted field IDs, and a three-fragment check of data preservation and stale-handle failure handling.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 25, 2026

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both bindings call the existing Rust migration and document the writer feature-flag requirement. With the Python extension built from d4445549, all eight rows across four fragments remained readable after migration, drop/add, append and reopen. Field IDs advanced through 3 without reuse. Repeating the migration on a fresh handle added no version, and a stale migration failed without changing its handle. JNI Rust clippy passed locally. Hosted Java 17 ran all 83 DatasetTest cases with no failures or skips, and the Java 11, 21 and 25 jobs also passed.

Keep both migration APIs and Java base registration. Align documentation with the Rust high-water mark and verify the Java dataset version before and after repeated activation.
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Dec 1, 2026
@Xuanwo
Xuanwo merged commit f3633e8 into lance-format:main Dec 1, 2026
28 checks passed
Xuanwo pushed a commit that referenced this pull request Dec 2, 2026
Part of #10684 (item 2: a create-time option). Item 1, the Python and
Java bindings for `migrate_to_non_reusable_field_ids`, is #11472.

A new dataset could only get non-reusable field IDs through a separate
migration commit after its first write. As the issue notes, a new
dataset has no older writers, so the migration's warning about clients
that ignore writer feature flags doesn't apply to it.

**Changes:**
- `WriteParams::enable_non_reusable_field_ids` (Rust) and
`enable_non_reusable_field_ids=` on `lance.write_dataset` (Python).
- When the write creates the dataset, `InsertBuilder` commits it with
`with_non_reusable_field_id_migration_activation()`, so the first
manifest records the high-water mark and sets
`FLAG_NON_REUSABLE_FIELD_IDS`.
- `CommitBuilder::use_non_reusable_field_ids(bool)` (public, in both
`lance` and `lance-table-runtime`) activates a dataset the commit
creates. One-step writes go through it, and it's the opt-in for
committing a create staged with `execute_uncommitted`.
- `execute_uncommitted` and `execute_uncommitted_stream` reject
`enable_non_reusable_field_ids` on a create, before writing any data
file, because a transaction can't carry it to the commit.
- Like `enable_stable_row_ids`, the option doesn't change an existing
dataset. Appends and overwrites keep its setting, because it may have
older writers. `migrate_to_non_reusable_field_ids` stays the way to opt
in later.

This adds a public field to `WriteParams`, so Rust code that builds it
with an exhaustive struct literal must set it.

**Tests:**
- **Rust:**
`test_enable_non_reusable_field_ids_applies_to_new_datasets`, with cases
`create`, `append_to_existing` and `overwrite_existing`. It checks the
high-water mark and writer flag, then adds, drops and re-adds a column.
The re-added column gets a fresh ID (2) only on the created dataset, and
reuses ID 1 otherwise.
- **Rust:**
`test_staged_create_with_non_reusable_field_ids[stream=false/true]`. A
staged create with the opt-in is rejected with no data files left
behind. A staged create committed with
`use_non_reusable_field_ids(true)` gives the replacement of the dropped
highest-ID column a fresh ID.
- **Python:**
`test_write_dataset_enable_non_reusable_field_ids[False/True]` covers
the same add/drop/add sequence through `write_dataset`.

**Checks run locally:**
- `cargo test -p lance --lib -- non_reusable`: 18 passed.
- `cargo check` passes for `python/`.
- cargo fmt, ruff and ruff-format pass.
- I couldn't run the Python test locally because there's no maturin
build on my machine. The docstring links to
`migrate_to_non_reusable_field_ids`, which #11472 adds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-java Java bindings + JNI A-python Python bindings enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants