fix: add dataset path hint and sync open_table location (#5128)

## Summary

- Expose `location=` on sync `LanceDBConnection.open_table()`, matching
the existing async entry point while leaving remote and namespace APIs
unchanged.
- When a `ListingDatabase` connection URI ends in `.lance`, append a
parent-directory and table-stem hint to the derived-URI `TableNotFound`
error. The error classification and source chain are preserved, and no
extra storage probes are made.

Context: OSS-2858 remains canceled. This is only the narrow embedded DX
follow-up; it does not add a top-level `lancedb.open_table(uri)` API.

## Verification

- Rust targeted listing tests for the `.lance` hint and the
explicit-location path.
- Python sync `open_table` tests for `location=` and the `.lance` hint.
- Pickle round-trip of a sync `location=` table after #5114.
- `cargo check --features remote --tests --examples`, `cargo fmt
--check`, Ruff format/check.
This commit is contained in:
Xuanwo
2026-11-20 22:08:29 +08:00
committed by GitHub
parent 9799686986
commit 85f966a9a9
5 changed files with 227 additions and 21 deletions
+6
View File
@@ -2197,6 +2197,7 @@ class LanceDBConnection(DBConnection):
namespace_path: Optional[List[str]] = None,
storage_options: Optional[Dict[str, str]] = None,
index_cache_size: Optional[int] = None,
location: Optional[str] = None,
branch: Optional[str] = None,
version: Optional[int] = None,
) -> LanceTable:
@@ -2209,6 +2210,10 @@ class LanceDBConnection(DBConnection):
namespace_path: List[str], optional
The namespace to open the table from. When non-empty, the
table is resolved through the directory namespace client.
location: str, optional
The explicit location (URI) of the table. If provided, the table will be
opened from this location instead of deriving it from the database URI
and table name.
branch: str, optional
If provided, open a handle scoped to this branch instead of the
default branch. Reads and writes operate in the branch's context.
@@ -2242,6 +2247,7 @@ class LanceDBConnection(DBConnection):
namespace_path=namespace_path,
storage_options=storage_options,
index_cache_size=index_cache_size,
location=location,
)
except (RuntimeError, ValueError) as e:
if namespace_path and (
+29
View File
@@ -869,6 +869,35 @@ def test_open_table_sync(tmp_db: lancedb.DBConnection):
tmp_db.open_table("does_not_exist")
def test_open_table_sync_with_location(tmp_path):
db = lancedb.connect(tmp_path / "db")
db.create_table("test", data=[{"id": 0}])
dataset_path = tmp_path / "db" / "test.lance"
other_db = lancedb.connect(tmp_path / "other")
opened = other_db.open_table("test", location=str(dataset_path))
assert opened.name == "test"
assert opened.count_rows() == 1
def test_open_table_sync_lance_dataset_path_hint(tmp_path):
data_dir = tmp_path / "data"
lancedb.connect(data_dir).create_table("embeddings", data=[{"id": 0}])
dataset_db = lancedb.connect(data_dir / "embeddings.lance")
with pytest.raises(ValueError) as exc_info:
dataset_db.open_table("embeddings")
message = str(exc_info.value)
assert "Table 'embeddings' was not found" in message
assert "points to a Lance dataset rather than a database directory" in message
assert f"parent directory '{data_dir}'" in message
assert "open table 'embeddings' instead" in message
with pytest.raises(ValueError) as exc_info:
dataset_db.open_table("missing", location=str(tmp_path / "missing.lance"))
assert "points to a Lance dataset" not in str(exc_info.value)
@pytest.mark.asyncio
async def test_open_table(tmp_path):
from conftest import pandas_string_type