Error implementations (#232)

Solves #216 by adding a check on table open for existence of the
`.lance` file. Does not check for it for remote connections.
This commit is contained in:
Leon Yee
2023-06-27 16:48:31 -07:00
committed by GitHub
parent 4bc676e26a
commit eb5bcda337
7 changed files with 113 additions and 8 deletions

View File

@@ -252,7 +252,7 @@ class LanceDBConnection:
if data is not None:
tbl = LanceTable.create(self, name, data, schema, mode=mode)
else:
tbl = LanceTable(self, name)
tbl = LanceTable.open(self, name)
return tbl
def open_table(self, name: str) -> LanceTable:
@@ -267,7 +267,7 @@ class LanceDBConnection:
-------
A LanceTable object representing the table.
"""
return LanceTable(self, name)
return LanceTable.open(self, name)
def drop_table(self, name: str):
"""Drop a table from the database.

View File

@@ -308,6 +308,19 @@ class LanceTable:
lance.write_dataset(data, tbl._dataset_uri, mode=mode)
return tbl
@classmethod
def open(cls, db, name):
tbl = cls(db, name)
if tbl._conn.is_managed_remote:
# Not completely sure how to check for remote table existence yet.
return tbl
if not os.path.exists(tbl._dataset_uri):
raise FileNotFoundError(
f"Table {name} does not exist. Please first call db.create_table({name}, data)"
)
return tbl
def delete(self, where: str):
"""Delete rows from the table.