BREAKING CHANGE: Check if remote table exists when opening (with caching) (#1214)

- make open table behaviour consistent:
- remote tables will check if the table exists by calling /describe and
throwing an error if the call doesn't succeed
- this is similar to the behaviour for local tables where we will raise
an exception when opening the table if the local dataset doesn't exist
- The table names are cached in the client with a TTL
- Also fixes a small bug where if the remote error response was
deserialized from JSON as an object, we'd print it resulting in the
unhelpful error message: `Error: Server Error, status: 404, message: Not
Found: [object Object]`
This commit is contained in:
Bert
2024-04-10 11:54:47 -04:00
committed by GitHub
parent 8a1227030a
commit 25dea4e859
5 changed files with 76 additions and 13 deletions

View File

@@ -42,6 +42,7 @@ import {
Float16,
Int64
} from 'apache-arrow'
import type { RemoteRequest, RemoteResponse } from '../middleware'
const expect = chai.expect
const assert = chai.assert
@@ -913,7 +914,22 @@ describe('Remote LanceDB client', function () {
}
// Search
const table = await con.openTable('vectors')
const table = await con.withMiddleware(new (class {
async onRemoteRequest(req: RemoteRequest, next: (req: RemoteRequest) => Promise<RemoteResponse>) {
// intercept call to check if the table exists and make the call succeed
if (req.uri.endsWith('/describe/')) {
return {
status: 200,
statusText: 'OK',
headers: new Map(),
body: async () => ({})
}
}
return await next(req)
}
})()).openTable('vectors')
try {
await table.search([0.1, 0.3]).execute()
} catch (err) {