mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
feat(python): support table checkout by timestamp (#5221)
Python callers can pass a `datetime` to `Table.checkout()` and `AsyncTable.checkout()` to read several tables as of a single cutoff. Each table is pinned to the highest retained version on its current branch whose reported commit timestamp is at or before the cutoff. A cutoff before all retained versions raises `ValueError`. The Rust `Table::checkout_as_of` method scans the branch's retained history and compares the commit timestamps at the precision supplied by the backend. On Embedded it resolves and checks out the version on the same dataset. If a concurrent tag checkout moves the handle to another branch, it retries there before pinning the handle. On Enterprise it follows all version-history pages on the same branch before checking out the selected version. Servers that report only whole milliseconds can group commits on opposite sides of a cutoff. For an exact reread, record both the branch and version of each input after checkout, then reopen the table with both values. Python interprets naive datetimes in the system's local time zone and honors explicit UTC offsets. The website guide includes a draft paragraph for the SDK release. Closes #2293. ## Validation - Built the Windows x64 native extension from this checkout with the repository's `ci` profile and CPython 3.12. - `test_table.py` passed 558 tests with 20 skips. `test_remote_db.py` passed 759 tests with 2 skips using its HTTP test server. - The new tests cover two tables at one cutoff, pinning after later writes, recovery with `checkout_latest()`, a cutoff before the first version, non-UTC input, tied commits, and a commit one nanosecond past the cutoff. All three also passed with `TZ=EST5EDT`. - A real Embedded handle switching branches during timestamp lookup selected the wrong branch version in 40/40 attempts before the concurrency fix and the expected version in 40/40 attempts afterward. The Rust regression test forces that interleaving with a filesystem-backed table. - A two-page Enterprise HTTP fixture reproduced checkout at v1 with the previous SDK and confirmed checkout at v2 after the fix. The Rust regression asserts the branch and continuation token on page two and reads back the pinned version. A separate test covers empty intermediate pages and repeated tokens. - Both Rust branch checkout tests and the `Table::checkout_as_of` doctest passed with the `remote` feature enabled. - Python SDK Ruff checks and formatting, Pyright, Rust formatting, and Vale passed. Repository-wide Ruff reports 59 existing diagnostics in the unchanged `docs/web-tests` files. --------- Co-authored-by: lipeih <lipeihan@eazytec.com>
This commit is contained in:
@@ -1710,6 +1710,24 @@ First, let's see all the versions we've created:
|
||||
</CodeBlock>
|
||||
</CodeGroup>
|
||||
|
||||
{/*
|
||||
Draft for the Python timestamp checkout release.
|
||||
|
||||
In Python, pass a `datetime` to `table.checkout(cutoff)` to read a table as of
|
||||
that instant. The backend reports the commit times in the current branch's
|
||||
version history. Checkout selects the highest retained version whose reported
|
||||
time is at or before the cutoff. To read several tables as of the same time,
|
||||
capture one cutoff with `datetime.now(timezone.utc)` and pass it to each table.
|
||||
If no retained version qualifies, `checkout()` raises `ValueError`.
|
||||
|
||||
Some Enterprise servers report commit times in whole milliseconds. Two commits
|
||||
on opposite sides of the cutoff can then share a timestamp, and `checkout()`
|
||||
selects the higher version. For reproducible reports, record
|
||||
`table.current_branch()` and `table.version` for each input after checkout.
|
||||
To read the same snapshot again, pass both values to
|
||||
`db.open_table(name, branch=branch, version=version)`.
|
||||
*/}
|
||||
|
||||
#### Restore a Version Snapshot {#versioning-restore-a-version-snapshot}
|
||||
|
||||
Now let's restore a captured version snapshot:
|
||||
|
||||
Reference in New Issue
Block a user