mirror of
https://github.com/lancedb/lancedb.git
synced 2026-01-04 19:02:58 +00:00
feat: support optimize indices in sync API (#1769)
Signed-off-by: BubbleCal <bubble-cal@outlook.com>
This commit is contained in:
@@ -1223,6 +1223,54 @@ async def test_time_travel(db_async: AsyncConnection):
|
||||
await table.restore()
|
||||
|
||||
|
||||
def test_sync_optimize(db):
|
||||
table = LanceTable.create(
|
||||
db,
|
||||
"test",
|
||||
data=[
|
||||
{"vector": [3.1, 4.1], "item": "foo", "price": 10.0},
|
||||
{"vector": [5.9, 26.5], "item": "bar", "price": 20.0},
|
||||
],
|
||||
)
|
||||
|
||||
table.create_scalar_index("price", index_type="BTREE")
|
||||
stats = table.to_lance().stats.index_stats("price_idx")
|
||||
assert stats["num_indexed_rows"] == 2
|
||||
|
||||
table.add([{"vector": [2.0, 2.0], "item": "baz", "price": 30.0}])
|
||||
assert table.count_rows() == 3
|
||||
table.optimize()
|
||||
stats = table.to_lance().stats.index_stats("price_idx")
|
||||
assert stats["num_indexed_rows"] == 3
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_optimize_in_async(db):
|
||||
table = LanceTable.create(
|
||||
db,
|
||||
"test",
|
||||
data=[
|
||||
{"vector": [3.1, 4.1], "item": "foo", "price": 10.0},
|
||||
{"vector": [5.9, 26.5], "item": "bar", "price": 20.0},
|
||||
],
|
||||
)
|
||||
|
||||
table.create_scalar_index("price", index_type="BTREE")
|
||||
stats = table.to_lance().stats.index_stats("price_idx")
|
||||
assert stats["num_indexed_rows"] == 2
|
||||
|
||||
table.add([{"vector": [2.0, 2.0], "item": "baz", "price": 30.0}])
|
||||
assert table.count_rows() == 3
|
||||
try:
|
||||
table.optimize()
|
||||
except Exception as e:
|
||||
assert (
|
||||
"Synchronous method called in asynchronous context. "
|
||||
"If you are writing an asynchronous application "
|
||||
"then please use the asynchronous APIs" in str(e)
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_optimize(db_async: AsyncConnection):
|
||||
table = await db_async.create_table(
|
||||
|
||||
Reference in New Issue
Block a user