mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
refactor(sdk)!: align Optimize results and data options
BREAKING CHANGE: Replace CompactionResult and SDK compaction option types with OptimizeResult and OptimizeDataOptions/OptimizeDataOverrides, rename compaction_options/compactionOptions to data_options/dataOptions, move the Python result module to lancedb.optimize, and use RewriteDataWithOptions for the Rust action.
This commit is contained in:
@@ -78,7 +78,7 @@ from .materialized_view import (
|
||||
)
|
||||
from .view import ViewDescription as ViewDescription
|
||||
from .graph import PropertyGraph, PropertyGraphDescription
|
||||
from .table import AsyncTable, CompactionOptions, Table
|
||||
from .table import AsyncTable, OptimizeDataOptions, Table
|
||||
from .types import BaseTokenizerType
|
||||
from ._lancedb import Session
|
||||
from .namespace import (
|
||||
@@ -676,7 +676,7 @@ __all__ = [
|
||||
"AsyncSqlQuery",
|
||||
"AsyncLanceNamespaceDBConnection",
|
||||
"AsyncTable",
|
||||
"CompactionOptions",
|
||||
"OptimizeDataOptions",
|
||||
"FtsToken",
|
||||
"FunctionColumnAutoRefreshStatus",
|
||||
"FunctionColumnLastRefreshJob",
|
||||
|
||||
@@ -807,14 +807,14 @@ class Table:
|
||||
self, updates: list[dict[str, Any]]
|
||||
) -> UpdateFieldMetadataResult: ...
|
||||
async def optimize_async(
|
||||
self, compaction_options: Optional[Dict[str, Any]] = None
|
||||
self, data_options: Optional[Dict[str, Any]] = None
|
||||
) -> Job: ...
|
||||
async def optimize(
|
||||
self,
|
||||
*,
|
||||
cleanup_since_ms: Optional[int] = None,
|
||||
delete_unverified: Optional[bool] = None,
|
||||
compaction_options: Optional[Dict[str, Any]] = None,
|
||||
data_options: Optional[Dict[str, Any]] = None,
|
||||
action: Optional[str] = None,
|
||||
) -> OptimizeStats: ...
|
||||
async def uri(self) -> str: ...
|
||||
|
||||
@@ -21,7 +21,7 @@ from lancedb.background_loop import LOOP
|
||||
from . import _lancedb
|
||||
from ._lancedb import JobDescription, JobFailureInfo, JobInfo, _append_doc_url
|
||||
from .functions import RefreshColumnResult
|
||||
from .compaction import CompactionResult
|
||||
from .optimize import OptimizeResult
|
||||
from .prewarm import PrewarmDataResult
|
||||
from .remote.errors import HttpError, RetryError
|
||||
|
||||
@@ -863,5 +863,5 @@ def _opened_job(inner: "_lancedb.Job") -> AsyncJob:
|
||||
if inner.job_type == "prewarm_page_cache":
|
||||
return _typed_job(inner, PrewarmDataResult.from_json)
|
||||
if inner.job_type == "compact":
|
||||
return _typed_job(inner, CompactionResult.from_json)
|
||||
return _typed_job(inner, OptimizeResult.from_json)
|
||||
return AsyncJob(inner)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||
|
||||
"""Results of durable remote compaction jobs."""
|
||||
"""Results of durable remote Optimize jobs."""
|
||||
|
||||
from dataclasses import dataclass, fields
|
||||
import json
|
||||
@@ -9,8 +9,8 @@ from typing import Optional
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class CompactionResult:
|
||||
"""Actual committed outcome of one remote compaction invocation.
|
||||
class OptimizeResult:
|
||||
"""Actual committed outcome of one remote Optimize data rewrite.
|
||||
|
||||
``rows_failed`` counts planned live rows that were not committed, including
|
||||
partial progress. ``more_work`` means a bounded run left eligible work for
|
||||
@@ -30,7 +30,7 @@ class CompactionResult:
|
||||
fragments_removed: Optional[int] = None
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, raw: str) -> "CompactionResult":
|
||||
def from_json(cls, raw: str) -> "OptimizeResult":
|
||||
"""Decode a server result, ignoring additive fields from newer servers."""
|
||||
value = json.loads(raw)
|
||||
names = {field.name for field in fields(cls)}
|
||||
@@ -79,8 +79,8 @@ from ..table import (
|
||||
AsyncTable,
|
||||
BlobMode,
|
||||
Branches,
|
||||
CompactionOptions,
|
||||
CompactionResult,
|
||||
OptimizeDataOptions,
|
||||
OptimizeResult,
|
||||
IndexStatistics,
|
||||
Query,
|
||||
Table,
|
||||
@@ -1101,11 +1101,9 @@ class RemoteTable(Table):
|
||||
pass
|
||||
|
||||
def optimize_async(
|
||||
self, *, compaction_options: Optional[CompactionOptions] = None
|
||||
) -> Job[CompactionResult]:
|
||||
return Job(
|
||||
LOOP.run(self._table.optimize_async(compaction_options=compaction_options))
|
||||
)
|
||||
self, *, data_options: Optional[OptimizeDataOptions] = None
|
||||
) -> Job[OptimizeResult]:
|
||||
return Job(LOOP.run(self._table.optimize_async(data_options=data_options)))
|
||||
|
||||
def optimize(
|
||||
self,
|
||||
@@ -1113,7 +1111,7 @@ class RemoteTable(Table):
|
||||
cleanup_older_than: Optional[timedelta] = None,
|
||||
delete_unverified: bool = False,
|
||||
retrain: bool = False,
|
||||
compaction_options: Optional[CompactionOptions] = None,
|
||||
data_options: Optional[OptimizeDataOptions] = None,
|
||||
action: Optional[Literal["rewrite_data"]] = None,
|
||||
) -> OptimizeStats:
|
||||
"""Compact the table's data files via a durable, asynchronous
|
||||
@@ -1133,7 +1131,7 @@ class RemoteTable(Table):
|
||||
cleanup_older_than=cleanup_older_than,
|
||||
delete_unverified=delete_unverified,
|
||||
retrain=retrain,
|
||||
compaction_options=compaction_options,
|
||||
data_options=data_options,
|
||||
action=action,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -51,7 +51,7 @@ from lancedb.sql import QueryParameters, to_parameter_batch
|
||||
from lancedb.background_loop import LOOP, embedding_executor
|
||||
from lancedb.prewarm import PrewarmDataPlan, PrewarmDataResult
|
||||
from lancedb.job import AsyncJob, Job, _typed_job
|
||||
from lancedb.compaction import CompactionResult
|
||||
from lancedb.optimize import OptimizeResult
|
||||
from .dependencies import (
|
||||
_check_for_hugging_face,
|
||||
_check_for_lance,
|
||||
@@ -349,7 +349,7 @@ IndexConfigType = Union[
|
||||
]
|
||||
|
||||
|
||||
class CompactionOptions(TypedDict, total=False):
|
||||
class OptimizeDataOptions(TypedDict, total=False):
|
||||
"""Options that control file compaction during table optimization.
|
||||
|
||||
Unspecified options use Lance's defaults for local tables. Remote tables
|
||||
@@ -373,12 +373,12 @@ class CompactionOptions(TypedDict, total=False):
|
||||
|
||||
>>> desired_fragment_bytes = 750 * 1024 * 1024
|
||||
>>> average_row_bytes = 1_500_000
|
||||
>>> options: CompactionOptions = {
|
||||
>>> options: OptimizeDataOptions = {
|
||||
... "target_rows_per_fragment": max(
|
||||
... 1, desired_fragment_bytes // average_row_bytes
|
||||
... ),
|
||||
... }
|
||||
>>> await table.optimize(compaction_options=options) # doctest: +SKIP
|
||||
>>> await table.optimize(data_options=options) # doctest: +SKIP
|
||||
"""
|
||||
|
||||
target_rows_per_fragment: int
|
||||
@@ -3115,19 +3115,19 @@ class Table(ABC):
|
||||
"""
|
||||
|
||||
def optimize_async(
|
||||
self, *, compaction_options: Optional[CompactionOptions] = None
|
||||
) -> Job[CompactionResult]:
|
||||
self, *, data_options: Optional[OptimizeDataOptions] = None
|
||||
) -> Job[OptimizeResult]:
|
||||
"""Submit remote compaction and return a durable job after acceptance.
|
||||
|
||||
Uses SQL OPTIMIZE with the table handle's branch and namespace. Supports
|
||||
the four per-job settings in
|
||||
[CompactionOptions][lancedb.table.CompactionOptions].
|
||||
[OptimizeDataOptions][lancedb.table.OptimizeDataOptions].
|
||||
Requires a compatible remote server, table Ownership and parent Usage.
|
||||
Local and historical-version handles are unsupported. Existing
|
||||
``optimize()`` retains its return-on-submission behavior remotely.
|
||||
|
||||
``job.wait()`` waits for the actual rewrite and returns
|
||||
[CompactionResult][lancedb.compaction.CompactionResult]. Partial/bounded
|
||||
[OptimizeResult][lancedb.optimize.OptimizeResult]. Partial/bounded
|
||||
runs report uncommitted rows and ``more_work``; unknown file statistics
|
||||
are None. Servers without a result payload raise an error rather than
|
||||
returning fabricated zero statistics. Wait timeouts do not cancel work.
|
||||
@@ -3135,7 +3135,7 @@ class Table(ABC):
|
||||
cancellation use generic HTTP job APIs and their existing permissions.
|
||||
|
||||
>>> job = table.optimize_async( # doctest: +SKIP
|
||||
... compaction_options={"target_rows_per_fragment": 1000})
|
||||
... data_options={"target_rows_per_fragment": 1000})
|
||||
>>> result = job.wait() # doctest: +SKIP
|
||||
>>> print(result.rows_succeeded) # doctest: +SKIP
|
||||
"""
|
||||
@@ -3148,7 +3148,7 @@ class Table(ABC):
|
||||
cleanup_older_than: Optional[timedelta] = None,
|
||||
delete_unverified: bool = False,
|
||||
retrain: bool = False,
|
||||
compaction_options: Optional[CompactionOptions] = None,
|
||||
data_options: Optional[OptimizeDataOptions] = None,
|
||||
action: Optional[Literal["rewrite_data"]] = None,
|
||||
) -> OptimizeStats:
|
||||
"""
|
||||
@@ -3209,11 +3209,11 @@ class Table(ABC):
|
||||
separate index maintenance phase. Omit for Embedded's full cycle.
|
||||
Cannot be combined with cleanup options. Enterprise always submits
|
||||
compaction only; use optimize_async() to retain its durable job.
|
||||
compaction_options: CompactionOptions, optional
|
||||
data_options: OptimizeDataOptions, optional
|
||||
Options that control file compaction. For large rows, derive a lower
|
||||
``target_rows_per_fragment`` from the expected row size to bound later
|
||||
passes. This does not cap the first pass over an existing oversized
|
||||
fragment; see [CompactionOptions][lancedb.table.CompactionOptions].
|
||||
fragment; see [OptimizeDataOptions][lancedb.table.OptimizeDataOptions].
|
||||
|
||||
Notes
|
||||
-----
|
||||
@@ -5849,11 +5849,9 @@ class LanceTable(Table):
|
||||
)
|
||||
|
||||
def optimize_async(
|
||||
self, *, compaction_options: Optional[CompactionOptions] = None
|
||||
) -> Job[CompactionResult]:
|
||||
return Job(
|
||||
LOOP.run(self._table.optimize_async(compaction_options=compaction_options))
|
||||
)
|
||||
self, *, data_options: Optional[OptimizeDataOptions] = None
|
||||
) -> Job[OptimizeResult]:
|
||||
return Job(LOOP.run(self._table.optimize_async(data_options=data_options)))
|
||||
|
||||
def optimize(
|
||||
self,
|
||||
@@ -5861,7 +5859,7 @@ class LanceTable(Table):
|
||||
cleanup_older_than: Optional[timedelta] = None,
|
||||
delete_unverified: bool = False,
|
||||
retrain: bool = False,
|
||||
compaction_options: Optional[CompactionOptions] = None,
|
||||
data_options: Optional[OptimizeDataOptions] = None,
|
||||
action: Optional[Literal["rewrite_data"]] = None,
|
||||
) -> OptimizeStats:
|
||||
"""
|
||||
@@ -5907,11 +5905,11 @@ class LanceTable(Table):
|
||||
separate index maintenance phase. Omit for Embedded's full cycle.
|
||||
Cannot be combined with cleanup options. Enterprise always submits
|
||||
compaction only; use optimize_async() to retain its durable job.
|
||||
compaction_options: CompactionOptions, optional
|
||||
data_options: OptimizeDataOptions, optional
|
||||
Options that control file compaction. For large rows, derive a lower
|
||||
``target_rows_per_fragment`` from the expected row size to bound later
|
||||
passes. This does not cap the first pass over an existing oversized
|
||||
fragment; see [CompactionOptions][lancedb.table.CompactionOptions].
|
||||
fragment; see [OptimizeDataOptions][lancedb.table.OptimizeDataOptions].
|
||||
|
||||
Notes
|
||||
-----
|
||||
@@ -5925,7 +5923,7 @@ class LanceTable(Table):
|
||||
self._table._do_optimize(
|
||||
_optimize_cleanup_since_ms(cleanup_older_than, retrain),
|
||||
delete_unverified,
|
||||
compaction_options,
|
||||
data_options,
|
||||
action,
|
||||
)
|
||||
)
|
||||
@@ -9546,16 +9544,16 @@ class AsyncTable:
|
||||
return self._inner.current_branch()
|
||||
|
||||
async def optimize_async(
|
||||
self, *, compaction_options: Optional[CompactionOptions] = None
|
||||
) -> AsyncJob[CompactionResult]:
|
||||
self, *, data_options: Optional[OptimizeDataOptions] = None
|
||||
) -> AsyncJob[OptimizeResult]:
|
||||
"""Submit remote compaction; await the returned job for actual results.
|
||||
|
||||
See [Table.optimize_async][lancedb.table.Table.optimize_async] for options,
|
||||
permissions, completion semantics and compatibility requirements.
|
||||
"""
|
||||
return _typed_job(
|
||||
await self._inner.optimize_async(compaction_options),
|
||||
CompactionResult.from_json,
|
||||
await self._inner.optimize_async(data_options),
|
||||
OptimizeResult.from_json,
|
||||
)
|
||||
|
||||
async def optimize(
|
||||
@@ -9564,7 +9562,7 @@ class AsyncTable:
|
||||
cleanup_older_than: Optional[timedelta] = None,
|
||||
delete_unverified: bool = False,
|
||||
retrain=False,
|
||||
compaction_options: Optional[CompactionOptions] = None,
|
||||
data_options: Optional[OptimizeDataOptions] = None,
|
||||
action: Optional[Literal["rewrite_data"]] = None,
|
||||
) -> OptimizeStats:
|
||||
"""
|
||||
@@ -9625,11 +9623,11 @@ class AsyncTable:
|
||||
separate index maintenance phase. Omit for Embedded's full cycle.
|
||||
Cannot be combined with cleanup options. Enterprise always submits
|
||||
compaction only; use optimize_async() to retain its durable job.
|
||||
compaction_options: CompactionOptions, optional
|
||||
data_options: OptimizeDataOptions, optional
|
||||
Options that control file compaction. For large rows, derive a lower
|
||||
``target_rows_per_fragment`` from the expected row size to bound later
|
||||
passes. This does not cap the first pass over an existing oversized
|
||||
fragment; see [CompactionOptions][lancedb.table.CompactionOptions].
|
||||
fragment; see [OptimizeDataOptions][lancedb.table.OptimizeDataOptions].
|
||||
|
||||
Notes
|
||||
-----
|
||||
@@ -9642,7 +9640,7 @@ class AsyncTable:
|
||||
return await self._do_optimize(
|
||||
_optimize_cleanup_since_ms(cleanup_older_than, retrain),
|
||||
delete_unverified,
|
||||
compaction_options,
|
||||
data_options,
|
||||
action,
|
||||
)
|
||||
|
||||
@@ -9650,14 +9648,14 @@ class AsyncTable:
|
||||
self,
|
||||
cleanup_since_ms: Optional[int],
|
||||
delete_unverified: bool,
|
||||
compaction_options: Optional[CompactionOptions] = None,
|
||||
data_options: Optional[OptimizeDataOptions] = None,
|
||||
action: Optional[Literal["rewrite_data"]] = None,
|
||||
) -> OptimizeStats:
|
||||
return await self._inner.optimize(
|
||||
action=action,
|
||||
cleanup_since_ms=cleanup_since_ms,
|
||||
delete_unverified=delete_unverified,
|
||||
compaction_options=compaction_options,
|
||||
data_options=data_options,
|
||||
)
|
||||
|
||||
async def list_indices(self) -> Iterable[IndexConfig]:
|
||||
|
||||
@@ -11,7 +11,7 @@ import numpy as np
|
||||
import pyarrow as pa
|
||||
import pytest
|
||||
from lancedb import LanceDBConnection, function
|
||||
from lancedb.compaction import CompactionResult
|
||||
from lancedb.optimize import OptimizeResult
|
||||
from lancedb.index import FTS
|
||||
from lancedb.prewarm import PrewarmDataResult
|
||||
|
||||
@@ -71,7 +71,7 @@ async def test_maintenance_job_result_and_reopen_against_server(
|
||||
if operation == "compact":
|
||||
job = await call(
|
||||
table.optimize_async,
|
||||
compaction_options={
|
||||
data_options={
|
||||
"target_rows_per_fragment": 100,
|
||||
"batch_size": 128,
|
||||
"io_buffer_size": 0,
|
||||
@@ -113,7 +113,7 @@ async def test_maintenance_job_result_and_reopen_against_server(
|
||||
await call(job.refresh)
|
||||
assert await call(job.status) == "finished"
|
||||
if operation == "compact":
|
||||
assert isinstance(result, CompactionResult)
|
||||
assert isinstance(result, OptimizeResult)
|
||||
assert job.job_type == "compact"
|
||||
assert not result.partial_commit and result.rows_failed == 0
|
||||
assert result.completion_percentage == 100
|
||||
|
||||
@@ -7572,7 +7572,7 @@ def test_remote_function_registration_transports_max_concurrency():
|
||||
({}, []),
|
||||
],
|
||||
)
|
||||
async def test_remote_optimize_forwards_per_job_compaction_options(
|
||||
async def test_remote_optimize_forwards_per_job_data_options(
|
||||
asynchronous, options, sql_options
|
||||
):
|
||||
flight = pytest.importorskip("pyarrow.flight")
|
||||
@@ -7593,10 +7593,10 @@ async def test_remote_optimize_forwards_per_job_compaction_options(
|
||||
if asynchronous:
|
||||
db = await lancedb.connect_async(**kwargs)
|
||||
table = await db.create_table("test", [{"id": 1}])
|
||||
stats = await table.optimize(compaction_options=options)
|
||||
stats = await table.optimize(data_options=options)
|
||||
else:
|
||||
table = lancedb.connect(**kwargs).create_table("test", [{"id": 1}])
|
||||
stats = table.optimize(compaction_options=options)
|
||||
stats = table.optimize(data_options=options)
|
||||
assert len(server.tickets) == 1
|
||||
assert b"OPTIMIZE" in server.tickets[0]
|
||||
assert all(option in server.tickets[0] for option in sql_options)
|
||||
@@ -7620,7 +7620,7 @@ def test_remote_optimize_does_not_drop_options_after_server_rejection():
|
||||
server = OldServer()
|
||||
with _mock_remote_table_with_sql(server) as table:
|
||||
with pytest.raises(Exception, match="max_source_rows"):
|
||||
table.optimize(compaction_options={"max_source_rows": 500})
|
||||
table.optimize(data_options={"max_source_rows": 500})
|
||||
assert server.tickets
|
||||
assert all(b"max_source_rows = 500" in ticket for ticket in server.tickets)
|
||||
|
||||
@@ -7660,13 +7660,13 @@ def test_remote_optimize_skips_prune_and_index():
|
||||
assert stats.prune.old_versions_removed == 0
|
||||
|
||||
|
||||
def test_remote_optimize_rejects_unsupported_compaction_options_before_submitting():
|
||||
def test_remote_optimize_rejects_unsupported_data_options_before_submitting():
|
||||
"""Regression test: `RemoteTable.optimize()` used to drop
|
||||
`compaction_options` instead of forwarding it to the Rust layer, so a
|
||||
`data_options` instead of forwarding it to the Rust layer, so a
|
||||
non-default value was silently ignored -- the server-side guard against
|
||||
unsupported options never saw it. It should now reach that guard and
|
||||
raise before any SQL statement is submitted."""
|
||||
from lancedb.table import CompactionOptions
|
||||
from lancedb.table import OptimizeDataOptions
|
||||
|
||||
flight = pytest.importorskip("pyarrow.flight")
|
||||
|
||||
@@ -7682,10 +7682,10 @@ def test_remote_optimize_rejects_unsupported_compaction_options_before_submittin
|
||||
)
|
||||
|
||||
server = UnreachableServer()
|
||||
options: CompactionOptions = {"max_source_bytes": 1024}
|
||||
options: OptimizeDataOptions = {"max_source_bytes": 1024}
|
||||
with _mock_remote_table_with_sql(server) as table:
|
||||
with pytest.raises(NotImplementedError, match="CompactionOptions"):
|
||||
table.optimize(compaction_options=options)
|
||||
with pytest.raises(NotImplementedError, match="OptimizeDataOptions"):
|
||||
table.optimize(data_options=options)
|
||||
|
||||
assert server.tickets == []
|
||||
|
||||
@@ -7695,7 +7695,7 @@ def test_remote_optimize_rejects_explicit_pruning_before_submitting():
|
||||
an explicit pruning request (`cleanup_older_than`), returning success
|
||||
with zero bytes removed even though nothing was pruned. It should now
|
||||
raise before any SQL statement is submitted, the same way a non-default
|
||||
`compaction_options` does."""
|
||||
`data_options` does."""
|
||||
from datetime import timedelta
|
||||
|
||||
flight = pytest.importorskip("pyarrow.flight")
|
||||
@@ -8472,7 +8472,7 @@ async def test_remote_compaction_job_result_and_reopen(asynchronous, outcome):
|
||||
db = await lancedb.connect_async(**kwargs)
|
||||
table = await db.create_table("test", [{"id": 1}])
|
||||
job = await table.optimize_async(
|
||||
compaction_options={"target_rows_per_fragment": 100}
|
||||
data_options={"target_rows_per_fragment": 100}
|
||||
)
|
||||
assert job.id == "compacting-job" and not polls
|
||||
if outcome in ("missing", "FAILED", "CANCELLED"):
|
||||
@@ -8492,9 +8492,7 @@ async def test_remote_compaction_job_result_and_reopen(asynchronous, outcome):
|
||||
else:
|
||||
db = lancedb.connect(**kwargs)
|
||||
table = db.create_table("test", [{"id": 1}])
|
||||
job = table.optimize_async(
|
||||
compaction_options={"target_rows_per_fragment": 100}
|
||||
)
|
||||
job = table.optimize_async(data_options={"target_rows_per_fragment": 100})
|
||||
assert job.id == "compacting-job" and not polls
|
||||
if outcome in ("missing", "FAILED", "CANCELLED"):
|
||||
with pytest.raises(
|
||||
@@ -8510,9 +8508,9 @@ async def test_remote_compaction_job_result_and_reopen(asynchronous, outcome):
|
||||
stats = job.wait()
|
||||
assert db.open_job(job.id).wait() == stats
|
||||
if outcome in ("counts", "legacy", "partial", "bounded", "no_op"):
|
||||
from lancedb.compaction import CompactionResult
|
||||
from lancedb.optimize import OptimizeResult
|
||||
|
||||
assert isinstance(stats, CompactionResult)
|
||||
assert isinstance(stats, OptimizeResult)
|
||||
assert stats.rows_succeeded == (
|
||||
0 if outcome == "no_op" else 8 if outcome == "partial" else 12
|
||||
)
|
||||
@@ -8574,7 +8572,7 @@ def test_remote_compaction_rejects_boolean_budgets_without_submitting(
|
||||
server = UnusedServer()
|
||||
with _mock_remote_table_with_sql(server) as table:
|
||||
with pytest.raises(ValueError, match="must be an integer, not a bool"):
|
||||
getattr(table, method)(compaction_options={option: value})
|
||||
getattr(table, method)(data_options={option: value})
|
||||
assert server.calls == 0
|
||||
|
||||
|
||||
|
||||
@@ -5452,12 +5452,12 @@ async def test_optimize(mem_db_async: AsyncConnection):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_optimize_compaction_options(mem_db_async: AsyncConnection):
|
||||
async def test_optimize_data_options(mem_db_async: AsyncConnection):
|
||||
table = await mem_db_async.create_table("test", data=[{"x": 1}])
|
||||
await table.add([{"x": 2}])
|
||||
|
||||
stats = await table.optimize(
|
||||
compaction_options={
|
||||
data_options={
|
||||
"target_rows_per_fragment": 1,
|
||||
"batch_size": 1,
|
||||
"num_threads": 1,
|
||||
@@ -5466,18 +5466,18 @@ async def test_optimize_compaction_options(mem_db_async: AsyncConnection):
|
||||
assert stats.compaction.fragments_removed == 0
|
||||
assert stats.compaction.fragments_added == 0
|
||||
|
||||
stats = await table.optimize(compaction_options={"target_rows_per_fragment": 3})
|
||||
stats = await table.optimize(data_options={"target_rows_per_fragment": 3})
|
||||
assert stats.compaction.fragments_removed == 2
|
||||
assert stats.compaction.fragments_added == 1
|
||||
|
||||
with pytest.raises(ValueError, match="Invalid compaction option: unknown"):
|
||||
await table.optimize(compaction_options={"unknown": 1})
|
||||
await table.optimize(data_options={"unknown": 1})
|
||||
|
||||
|
||||
def test_optimize_compaction_options_sync(mem_db: DBConnection):
|
||||
def test_optimize_data_options_sync(mem_db: DBConnection):
|
||||
table = mem_db.create_table("test", data=[{"x": 1}])
|
||||
with pytest.raises(ValueError, match="target_rows_per_fragment must be between"):
|
||||
table.optimize(compaction_options={"target_rows_per_fragment": 0})
|
||||
table.optimize(data_options={"target_rows_per_fragment": 0})
|
||||
|
||||
|
||||
@pytest.mark.parametrize("option", ["max_source_rows", "max_source_bytes"])
|
||||
@@ -5489,7 +5489,7 @@ async def test_optimize_compaction_source_limits(
|
||||
await table.add([{"x": 2}])
|
||||
|
||||
stats = await table.optimize(
|
||||
compaction_options={
|
||||
data_options={
|
||||
"target_rows_per_fragment": 3,
|
||||
option: 1,
|
||||
}
|
||||
@@ -5506,7 +5506,7 @@ async def test_optimize_compaction_data_storage_version(
|
||||
await table.add([{"x": 2}])
|
||||
|
||||
stats = await table.optimize(
|
||||
compaction_options={
|
||||
data_options={
|
||||
"target_rows_per_fragment": 3,
|
||||
"data_storage_version": "2.2",
|
||||
}
|
||||
@@ -5518,7 +5518,7 @@ async def test_optimize_compaction_data_storage_version(
|
||||
await table.add([{"x": 2}])
|
||||
with pytest.raises(ValueError, match="V1 and V2 storage versions cannot be mixed"):
|
||||
await table.optimize(
|
||||
compaction_options={
|
||||
data_options={
|
||||
"target_rows_per_fragment": 3,
|
||||
"data_storage_version": "legacy",
|
||||
}
|
||||
@@ -5531,7 +5531,7 @@ async def test_optimize_compaction_excluded_fragments(mem_db_async: AsyncConnect
|
||||
await table.add([{"x": 2}])
|
||||
|
||||
stats = await table.optimize(
|
||||
compaction_options={
|
||||
data_options={
|
||||
"target_rows_per_fragment": 3,
|
||||
"excluded_fragment_ids": [0],
|
||||
}
|
||||
@@ -5539,7 +5539,7 @@ async def test_optimize_compaction_excluded_fragments(mem_db_async: AsyncConnect
|
||||
assert stats.compaction.fragments_removed == 0
|
||||
assert stats.compaction.fragments_added == 0
|
||||
|
||||
stats = await table.optimize(compaction_options={"target_rows_per_fragment": 3})
|
||||
stats = await table.optimize(data_options={"target_rows_per_fragment": 3})
|
||||
assert stats.compaction.fragments_removed == 2
|
||||
assert stats.compaction.fragments_added == 1
|
||||
|
||||
@@ -5571,12 +5571,12 @@ async def test_optimize_compaction_excluded_fragments(mem_db_async: AsyncConnect
|
||||
],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_optimize_compaction_options_validation(
|
||||
async def test_optimize_data_options_validation(
|
||||
mem_db_async: AsyncConnection, option: str, value: Any, message: str
|
||||
):
|
||||
table = await mem_db_async.create_table("test", data=[{"x": 1}])
|
||||
with pytest.raises(ValueError, match=message):
|
||||
await table.optimize(compaction_options={option: value})
|
||||
await table.optimize(data_options={option: value})
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -198,7 +198,7 @@ def test_remote_optimize_options():
|
||||
cleanup_older_than=age,
|
||||
delete_unverified=True,
|
||||
retrain=True,
|
||||
compaction_options=None,
|
||||
data_options=None,
|
||||
action=None,
|
||||
)
|
||||
|
||||
@@ -275,6 +275,29 @@ def test_remote_optimize_rewrite_action():
|
||||
cleanup_older_than=None,
|
||||
delete_unverified=False,
|
||||
retrain=False,
|
||||
compaction_options=None,
|
||||
data_options=None,
|
||||
action="rewrite_data",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("cls", [Table, LanceTable, RemoteTable])
|
||||
@pytest.mark.parametrize("method", ["optimize", "optimize_async"])
|
||||
def test_optimize_public_options_names(cls, method):
|
||||
parameters = inspect.signature(getattr(cls, method)).parameters
|
||||
assert "data_options" in parameters
|
||||
assert "compaction_options" not in parameters
|
||||
|
||||
|
||||
def test_optimize_public_types():
|
||||
import importlib.util
|
||||
from lancedb.optimize import OptimizeResult
|
||||
from lancedb.table import OptimizeDataOptions
|
||||
|
||||
assert lancedb.OptimizeDataOptions is OptimizeDataOptions
|
||||
assert not hasattr(lancedb, "CompactionOptions")
|
||||
assert importlib.util.find_spec("lancedb.compaction") is None
|
||||
result = OptimizeResult.from_json(
|
||||
'{"partial_commit":false,"rows_succeeded":1,"rows_failed":0,'
|
||||
'"completion_percentage":100}'
|
||||
)
|
||||
assert result.rows_succeeded == 1
|
||||
|
||||
Reference in New Issue
Block a user