From 42d85b172f230ef2bd63689bed0abacc6eb167fd Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Sat, 21 Nov 2026 08:27:30 +0000 Subject: [PATCH] test(python): cover embedded plans over enterprise bases Clarify that persist writes only the plan to an embedded destination while the base table may be Enterprise. Add a loopback regression that persists a plan from a mock remote base, checks the recorded main/v1 snapshot requests, and verifies public sequential and duplicate-offset reads preserve order. --- docs/web/training/permutation.mdx | 9 ++++--- python/python/lancedb/permutation.py | 16 +++++++----- python/python/tests/test_permutation.py | 34 +++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/docs/web/training/permutation.mdx b/docs/web/training/permutation.mdx index 952341ea9..1f2f31596 100644 --- a/docs/web/training/permutation.mdx +++ b/docs/web/training/permutation.mdx @@ -35,6 +35,9 @@ By default a permutation table is stored in memory. Call `persist` before `execu LanceDB connection backed by local files or object storage. The plan becomes an ordinary table, so another process with access to the same storage can open it and use `Permutation.from_tables` to read the same split. +Only the plan destination must be embedded. The base table can be Embedded or Enterprise; an Enterprise base is +pinned through the plan's recorded base branch and version. + ```py Python icon=Python from lancedb.permutation import Permutation, permutation_builder @@ -57,9 +60,9 @@ reopened directly in a worker process. `mode="create"` is the default and fails when the destination table already exists. Pass `mode="overwrite"` to replace it explicitly. Overwriting writes a new table version; readers that already opened the previous version keep -reading that snapshot. Use `namespace_path` to create the plan in a namespace. Persisting to LanceDB Enterprise -connections is not supported yet, because reproducible Enterprise plan ordering requires deterministic remote row -ordering. +reading that snapshot. Use `namespace_path` to create the plan in a namespace. Persisting the plan itself to a +LanceDB Enterprise connection is not supported yet, because reproducible Enterprise plan ordering requires +deterministic remote row ordering. The plan records the base table version and branch in its schema metadata. `Permutation.base_version` and `Permutation.base_branch` read those values without querying the base table; both are `None` for older plans that did diff --git a/python/python/lancedb/permutation.py b/python/python/lancedb/permutation.py index 0369ccec5..ff1cf7b59 100644 --- a/python/python/lancedb/permutation.py +++ b/python/python/lancedb/permutation.py @@ -294,10 +294,12 @@ class PermutationBuilder: """ Store the permutation table in an embedded database. - Persisting a plan makes the same split available to another process or - another machine with access to the destination storage. The plan is an - ordinary LanceDB table containing row ids and split ids; it can be - opened with [open_table][lancedb.db.DBConnection.open_table] and passed to + The base table can be Embedded or Enterprise; this connection is only the + plan destination. Persisting a plan makes the same split available to + another process or another machine with access to the destination storage. + The plan is an ordinary LanceDB table containing row ids and split ids; it + can be opened with [open_table][lancedb.db.DBConnection.open_table] and + passed to [Permutation.from_tables][lancedb.permutation.Permutation.from_tables]. The table returned by ``execute`` keeps the destination connection and namespace context, so it can be pickled and reopened directly. @@ -305,8 +307,10 @@ class PermutationBuilder: Parameters ---------- db: DBConnection - An embedded LanceDB connection. Local files and object storage are - supported; LanceDB Enterprise connections are not supported yet. + An embedded LanceDB connection for the plan destination. Local files + and object storage are supported. The base table may be Embedded or + Enterprise; persisting the plan itself to Enterprise is not supported + yet. table_name: str The name of the permutation table to create. namespace_path: list[str], optional diff --git a/python/python/tests/test_permutation.py b/python/python/tests/test_permutation.py index 22df4570c..928263955 100644 --- a/python/python/tests/test_permutation.py +++ b/python/python/tests/test_permutation.py @@ -222,6 +222,40 @@ def test_base_branch_property_reads_plan_metadata(tmp_path): assert permutation.num_rows == 20 +def test_persist_embedded_plan_for_remote_base(tmp_path): + server = MockPermutationServer(num_rows=8) + db = connect(tmp_path) + + with mock_remote_table(server) as remote: + plan = permutation_builder(remote).persist(db, "plan").execute() + permutation = Permutation.from_tables(remote, plan) + + assert permutation.base_version == 1 + assert permutation.base_branch is None + assert permutation._plan_version == 1 + assert permutation.permutation_table.version == 1 + + sequential_ids = [ + row["id"] + for batch in permutation.iter(3, skip_last_batch=False) + for row in batch + ] + assert sequential_ids == list(range(8)) + assert [row["id"] for row in permutation.__getitems__([5, 1, 5, 3])] == [ + 5, + 1, + 5, + 3, + ] + + # The plan is local, but its build and gathers address the remote base + # at the recorded main/v1 snapshot. + assert server.scans + for body in [*server.scans, *server.takes]: + assert body.get("version") == 1 + assert body.get("branch") is None + + def test_persisted_plan_pickle_reopens_same_snapshot_after_overwrite(tmp_path): from datetime import timedelta import pickle