From 662968559dea0996e187a14173fa31381e363043 Mon Sep 17 00:00:00 2001 From: QianZhu Date: Tue, 7 Nov 2023 17:34:38 -0800 Subject: [PATCH] fix saas open_table and table_names issues (#640) - added check whether a table exists in SaaS open_table - remove prefilter not supported warning in SaaS search - fixed issues for SaaS table_names --- python/lancedb/remote/client.py | 11 ++++------- python/lancedb/remote/db.py | 15 ++++++++++++--- python/lancedb/remote/table.py | 2 -- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/python/lancedb/remote/client.py b/python/lancedb/remote/client.py index 03fec380..30b68e93 100644 --- a/python/lancedb/remote/client.py +++ b/python/lancedb/remote/client.py @@ -155,13 +155,10 @@ class RestfulLanceDBClient: self, limit: int, page_token: Optional[str] = None ) -> Iterable[str]: """List all tables in the database.""" - try: - json = await self.get( - "/v1/table/", {"limit": limit, "page_token": page_token} - ) - return json["tables"] - except StopAsyncIteration: - return [] + if page_token is None: + page_token = "" + json = await self.get("/v1/table/", {"limit": limit, "page_token": page_token}) + return json["tables"] @_check_not_closed async def query(self, table_name: str, query: VectorQuery) -> VectorQueryResult: diff --git a/python/lancedb/remote/db.py b/python/lancedb/remote/db.py index 60387c33..2c53f21f 100644 --- a/python/lancedb/remote/db.py +++ b/python/lancedb/remote/db.py @@ -13,6 +13,7 @@ import asyncio import inspect +import logging import uuid from typing import Iterable, List, Optional, Union from urllib.parse import urlparse @@ -62,7 +63,7 @@ class RemoteDBConnection(DBConnection): Parameters ---------- - last_token: str + page_token: str The last token to start the new page. Returns @@ -95,8 +96,16 @@ class RemoteDBConnection(DBConnection): """ from .table import RemoteTable - # TODO: check if table exists - + # check if table exists + try: + self._loop.run_until_complete( + self._client.post(f"/v1/table/{name}/describe/") + ) + except Exception: + logging.error( + "Table {name} does not exist." + "Please first call db.create_table({name}, data)" + ) return RemoteTable(self, name) @override diff --git a/python/lancedb/remote/table.py b/python/lancedb/remote/table.py index 3f3faa0c..b3064b2a 100644 --- a/python/lancedb/remote/table.py +++ b/python/lancedb/remote/table.py @@ -99,8 +99,6 @@ class RemoteTable(Table): return LanceVectorQueryBuilder(self, query, vector_column_name) def _execute_query(self, query: Query) -> pa.Table: - if query.prefilter: - raise NotImplementedError("Cloud support for prefiltering is coming soon") result = self._conn._client.query(self._name, query) return self._conn._loop.run_until_complete(result).to_arrow()