feat: add a filterable count_rows to all the lancedb APIs (#913)

A `count_rows` method that takes a filter was recently added to
`LanceTable`. This PR adds it everywhere else except `RemoteTable` (that
will come soon).
This commit is contained in:
Weston Pace
2024-02-08 09:40:29 -08:00
committed by GitHub
parent f53aace89c
commit d2e71c8b08
11 changed files with 86 additions and 30 deletions

View File

@@ -372,7 +372,7 @@ export interface Table<T = number[]> {
/**
* Returns the number of rows in this table.
*/
countRows: () => Promise<number>
countRows: (filter?: string) => Promise<number>
/**
* Delete rows from this table.
@@ -840,8 +840,8 @@ export class LocalTable<T = number[]> implements Table<T> {
/**
* Returns the number of rows in this table.
*/
async countRows (): Promise<number> {
return tableCountRows.call(this._tbl)
async countRows (filter?: string): Promise<number> {
return tableCountRows.call(this._tbl, filter)
}
/**

View File

@@ -294,6 +294,7 @@ describe('LanceDB client', function () {
})
assert.equal(table.name, 'vectors')
assert.equal(await table.countRows(), 10)
assert.equal(await table.countRows('vector IS NULL'), 0)
assert.deepEqual(await con.tableNames(), ['vectors'])
})
@@ -369,6 +370,7 @@ describe('LanceDB client', function () {
const table = await con.createTable('f16', data)
assert.equal(table.name, 'f16')
assert.equal(await table.countRows(), total)
assert.equal(await table.countRows('id < 5'), 5)
assert.deepEqual(await con.tableNames(), ['f16'])
assert.deepEqual(await table.schema, schema)