mirror of
https://github.com/lancedb/lancedb.git
synced 2026-08-18 12:08:35 +00:00
fix: address Windows file store review feedback
This commit is contained in:
@@ -713,20 +713,9 @@ class LanceDBConnection(DBConnection):
|
||||
if not isinstance(uri, Path):
|
||||
scheme = get_uri_scheme(uri)
|
||||
is_local = isinstance(uri, Path) or scheme == "file"
|
||||
if is_local:
|
||||
is_file_uri = isinstance(uri, str) and uri.lower().startswith("file:")
|
||||
if is_local and not is_file_uri:
|
||||
if isinstance(uri, str):
|
||||
# Strip file:// or file:/ scheme if present
|
||||
# file:///path becomes file:/path after URL normalization
|
||||
if uri.startswith("file://"):
|
||||
uri = uri[7:] # Remove "file://"
|
||||
elif uri.startswith("file:/"):
|
||||
uri = uri[5:] # Remove "file:"
|
||||
|
||||
if sys.platform == "win32":
|
||||
# On Windows, a path like /C:/path should become C:/path
|
||||
if len(uri) >= 3 and uri[0] == "/" and uri[2] == ":":
|
||||
uri = uri[1:]
|
||||
|
||||
uri = Path(uri)
|
||||
uri = uri.expanduser().absolute()
|
||||
Path(uri).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@@ -77,6 +77,32 @@ def test_sync_repr_does_not_use_background_loop(tmp_path, monkeypatch):
|
||||
assert repr(table) == f"LanceTable(name='test', _conn={db!r})"
|
||||
|
||||
|
||||
def test_connect_preserves_file_uri_authority(monkeypatch):
|
||||
uri = "file://server/share/database"
|
||||
received = []
|
||||
|
||||
async def fake_connect(passed_uri, *_args):
|
||||
received.append(passed_uri)
|
||||
return SimpleNamespace(uri=passed_uri)
|
||||
|
||||
monkeypatch.setattr("lancedb.db.lancedb_connect", fake_connect)
|
||||
db = lancedb.connect(uri)
|
||||
|
||||
assert received == [uri]
|
||||
assert db.uri == uri
|
||||
|
||||
|
||||
def test_connect_file_uri_lifecycle(tmp_path):
|
||||
uri = (tmp_path / "sync").as_uri()
|
||||
db = lancedb.connect(uri)
|
||||
|
||||
db.create_table("test", data=[{"id": 1}])
|
||||
assert db.table_names() == ["test"]
|
||||
assert db.open_table("test").count_rows() == 1
|
||||
db.drop_table("test")
|
||||
assert db.table_names() == []
|
||||
|
||||
|
||||
def test_ingest_pd(tmp_path):
|
||||
db = lancedb.connect(tmp_path)
|
||||
|
||||
@@ -376,6 +402,35 @@ async def test_connect(tmp_path):
|
||||
assert str(db) == f"ListingDatabase(uri={tmp_path}, read_consistency_interval=5s)"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_connect_async_preserves_file_uri_authority(monkeypatch):
|
||||
uri = "file://server/share/database"
|
||||
received = []
|
||||
|
||||
async def fake_connect(passed_uri, *_args):
|
||||
received.append(passed_uri)
|
||||
return SimpleNamespace(uri=passed_uri)
|
||||
|
||||
monkeypatch.setattr(lancedb, "lancedb_connect", fake_connect)
|
||||
db = await lancedb.connect_async(uri)
|
||||
|
||||
assert received == [uri]
|
||||
assert db.uri == uri
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_connect_async_file_uri_lifecycle(tmp_path):
|
||||
uri = (tmp_path / "async").as_uri()
|
||||
db = await lancedb.connect_async(uri)
|
||||
|
||||
await db.create_table("test", data=[{"id": 1}])
|
||||
assert await db.table_names() == ["test"]
|
||||
table = await db.open_table("test")
|
||||
assert await table.count_rows() == 1
|
||||
await db.drop_table("test")
|
||||
assert await db.table_names() == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_close(mem_db_async: lancedb.AsyncConnection):
|
||||
assert mem_db_async.is_open()
|
||||
|
||||
Reference in New Issue
Block a user