mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
feat(functions): add row failure recovery APIs (#5048)
Function failures currently require callers to assemble row predicates
and manage retry/version/quarantine state themselves. Add exact
failed-row retry and Function upgrades through the Rust and Python
refresh APIs, plus Python helpers for grouped causes, failing input
rows, quarantine, and per-row producing-version metadata.
```python
errors = table.function_errors(column="sharpness")
errors.summary()
errors.rows(columns=["frame_index", "frame"])
table.retry_failed("sharpness", function_version="2").wait()
table.quarantine_failed("sharpness", after_attempts=3)
table.retry_failed("sharpness", include_quarantined=True).wait()
table.function_provenance("sharpness")
```
`upgrade_column(..., recompute="failed" | "all" | "none")` keeps the
column available while selecting the intended work. `history=True` reads
retained past errors. Capability checks reject these operations on
servers that cannot honor the workflow, before any refresh is submitted.
Includes synchronous/asynchronous API and older-server compatibility
coverage. Formatting applied; local builds and tests were not run.
This commit is contained in:
@@ -29,7 +29,6 @@ from ._lancedb import (
|
||||
)
|
||||
from ._lancedb import FunctionErrorFragment as FunctionErrorFragment
|
||||
from ._lancedb import FunctionErrorRecord as FunctionErrorRecord
|
||||
from ._lancedb import FunctionErrors as FunctionErrors
|
||||
from ._lancedb import GpuClass as GpuClass
|
||||
from ._lancedb import RTEWriteSpec
|
||||
from ._lancedb import tokenize as _tokenize
|
||||
@@ -46,6 +45,11 @@ from .sql import AsyncQuery as AsyncSqlQuery
|
||||
from .sql import Query as SqlQuery
|
||||
from .sql import QueryDescription
|
||||
from .functions import (
|
||||
FunctionErrors as FunctionErrors,
|
||||
AsyncFunctionErrors as AsyncFunctionErrors,
|
||||
FunctionErrorGroup as FunctionErrorGroup,
|
||||
FunctionProvenance as FunctionProvenance,
|
||||
FunctionValueProvenance as FunctionValueProvenance,
|
||||
AssignmentMapping as AssignmentMapping,
|
||||
FunctionArtifactRequest as FunctionArtifactRequest,
|
||||
FunctionApplication as FunctionApplication,
|
||||
@@ -678,6 +682,11 @@ __all__ = [
|
||||
"FunctionColumnLastRefreshJob",
|
||||
"FunctionColumnStatus",
|
||||
"FunctionColumnVersionStatus",
|
||||
"FunctionErrors",
|
||||
"AsyncFunctionErrors",
|
||||
"FunctionErrorGroup",
|
||||
"FunctionProvenance",
|
||||
"FunctionValueProvenance",
|
||||
"col",
|
||||
"Expr",
|
||||
"func",
|
||||
|
||||
@@ -694,6 +694,12 @@ class Table:
|
||||
init_timeout_seconds: Optional[float] = None,
|
||||
num_workers: Optional[int] = None,
|
||||
max_executor_processes_per_worker: Optional[int] = None,
|
||||
retry_errors: bool = False,
|
||||
retry_job_id: Optional[str] = None,
|
||||
retry_error_type: Optional[str] = None,
|
||||
include_quarantined: bool = False,
|
||||
function_version: Optional[str] = None,
|
||||
recompute: Optional[Literal["failed", "all", "none"]] = None,
|
||||
) -> RefreshColumnResult: ...
|
||||
async def refresh_column_async(
|
||||
self,
|
||||
@@ -716,13 +722,36 @@ class Table:
|
||||
init_timeout_seconds: Optional[float] = None,
|
||||
num_workers: Optional[int] = None,
|
||||
max_executor_processes_per_worker: Optional[int] = None,
|
||||
retry_errors: bool = False,
|
||||
retry_job_id: Optional[str] = None,
|
||||
retry_error_type: Optional[str] = None,
|
||||
include_quarantined: bool = False,
|
||||
function_version: Optional[str] = None,
|
||||
recompute: Optional[Literal["failed", "all", "none"]] = None,
|
||||
) -> Job: ...
|
||||
async def function_errors(
|
||||
self,
|
||||
job_id: Optional[str] = None,
|
||||
column: Optional[str] = None,
|
||||
limit: Optional[int] = None,
|
||||
history: bool = False,
|
||||
) -> FunctionErrors: ...
|
||||
async def quarantine_function_errors(
|
||||
self,
|
||||
column: str,
|
||||
*,
|
||||
quarantined: bool = True,
|
||||
job_id: Optional[str] = None,
|
||||
error_type: Optional[str] = None,
|
||||
after_attempts: Optional[int] = None,
|
||||
) -> int: ...
|
||||
async def function_provenance(
|
||||
self,
|
||||
column: str,
|
||||
*,
|
||||
limit: Optional[int] = None,
|
||||
version: Optional[int] = None,
|
||||
) -> str: ...
|
||||
async def column_statuses(
|
||||
self, column: Optional[str] = None
|
||||
) -> list[FunctionColumnStatus]: ...
|
||||
@@ -1128,6 +1157,10 @@ class RefreshColumnResult:
|
||||
version: int
|
||||
|
||||
class FunctionErrorRecord:
|
||||
first_seen_at_millis: Optional[int]
|
||||
last_seen_at_millis: Optional[int]
|
||||
quarantined: bool
|
||||
input: Optional[str]
|
||||
attempts: Optional[int]
|
||||
job_id: str
|
||||
fragment_id: int
|
||||
@@ -1151,6 +1184,8 @@ class FunctionErrorFragment:
|
||||
rows_recorded: int
|
||||
|
||||
class FunctionErrors:
|
||||
workflow_version: Optional[int]
|
||||
error_groups_json: str
|
||||
records: list[FunctionErrorRecord]
|
||||
fragments: list[FunctionErrorFragment]
|
||||
truncated: bool
|
||||
|
||||
@@ -1132,6 +1132,220 @@ class FunctionBinding(_RemoteValue):
|
||||
return reader.read_all().to_pylist()[0]
|
||||
|
||||
|
||||
class FunctionErrorGroup(_RemoteValue):
|
||||
"""A grouped cause among returned Function failures."""
|
||||
|
||||
column: str
|
||||
error_type: str
|
||||
error_message: str
|
||||
rows_failed: _UInt64
|
||||
|
||||
|
||||
class FunctionValueProvenance(_RemoteValue):
|
||||
"""The Function version and job that produced one stored value."""
|
||||
|
||||
column: str
|
||||
job_id: str
|
||||
function_name: str
|
||||
function_version: str
|
||||
row_id: Optional[_UInt64] = None
|
||||
row_address: Optional[_UInt64] = None
|
||||
source_version: _UInt64
|
||||
published_version: _UInt64
|
||||
|
||||
|
||||
class FunctionProvenance(_RemoteValue):
|
||||
"""A bounded per-row producing-version listing for a table snapshot."""
|
||||
|
||||
records: tuple[FunctionValueProvenance, ...]
|
||||
truncated: bool = False
|
||||
|
||||
|
||||
class _FunctionErrors:
|
||||
"""Current Function failures, with grouped causes and source-row lookup.
|
||||
|
||||
Check ``truncated`` and ``fragments`` before treating a listing as complete.
|
||||
``history=True`` on ``table.function_errors`` returns retained past records.
|
||||
"""
|
||||
|
||||
def __init__(self, raw: Any, table: Any, *, history: bool = False):
|
||||
self._raw = raw
|
||||
self._table = table
|
||||
self._history = history
|
||||
self.records = raw.records
|
||||
self.fragments = raw.fragments
|
||||
self.truncated = raw.truncated
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return repr(self._raw)
|
||||
|
||||
def as_sync(self, table: Any) -> FunctionErrors:
|
||||
return FunctionErrors(self._raw, table, history=self._history)
|
||||
|
||||
def summary(self) -> list[FunctionErrorGroup]:
|
||||
"""Group returned failures by column, exception class, and message.
|
||||
|
||||
Raises when records are incomplete, so sampled counts cannot be mistaken
|
||||
for totals. Narrow the request by column or job, or raise its limit.
|
||||
"""
|
||||
if (getattr(self._raw, "workflow_version", None) or 0) < 1:
|
||||
raise NotImplementedError(
|
||||
"The server does not support the current Function failure workflow"
|
||||
)
|
||||
if (
|
||||
self.truncated
|
||||
or self.fragments
|
||||
or any(
|
||||
record.row_offset is None and record.input is None
|
||||
for record in self.records
|
||||
)
|
||||
):
|
||||
raise ValueError(
|
||||
"Function errors are incomplete; narrow the request or raise limit"
|
||||
)
|
||||
groups: dict[tuple[str, str, str], int] = {}
|
||||
for record in self.records:
|
||||
if record.row_offset is None and record.input is None:
|
||||
continue
|
||||
message = record.error_message
|
||||
if record.input is not None:
|
||||
message = message.split("\nSource input: ", 1)[0].split(
|
||||
"\nFunction input ", 1
|
||||
)[0]
|
||||
key = (record.column, record.error_type, message)
|
||||
groups[key] = groups.get(key, 0) + 1
|
||||
return [
|
||||
FunctionErrorGroup(
|
||||
column=column, error_type=kind, error_message=message, rows_failed=count
|
||||
)
|
||||
for (column, kind, message), count in sorted(groups.items())
|
||||
]
|
||||
|
||||
def _identities(self) -> dict[tuple[str, int], list[Any]]:
|
||||
if (getattr(self._raw, "workflow_version", None) or 0) < 1:
|
||||
raise NotImplementedError(
|
||||
"The server does not support the current Function failure workflow"
|
||||
)
|
||||
if self._history:
|
||||
raise ValueError(
|
||||
"Source-row lookup requires current failures; "
|
||||
"read retained history through records"
|
||||
)
|
||||
if self.truncated or self.fragments:
|
||||
raise ValueError(
|
||||
"Function errors are incomplete; narrow the request or raise limit"
|
||||
)
|
||||
result = {}
|
||||
for record in self.records:
|
||||
if record.input is not None or record.row_offset is None:
|
||||
raise ValueError(
|
||||
"This error names a Function invocation; "
|
||||
"inspect its input source identities"
|
||||
)
|
||||
identity = (
|
||||
record.row_id if record.row_id is not None else record.row_address
|
||||
)
|
||||
if identity is None:
|
||||
raise ValueError("This error has no source row identity")
|
||||
key = ("_rowid" if record.row_id is not None else "_rowaddr", identity)
|
||||
result.setdefault(key, []).append(record)
|
||||
return result
|
||||
|
||||
def _predicate(self, identities: dict[tuple[str, int], list[Any]]) -> str:
|
||||
clauses = []
|
||||
for field in ("_rowid", "_rowaddr"):
|
||||
selected = [identity for (kind, identity) in identities if kind == field]
|
||||
if selected:
|
||||
clauses.append(field + " IN (" + ",".join(map(str, selected)) + ")")
|
||||
return " OR ".join(clauses) if clauses else "false"
|
||||
|
||||
def _join_rows(
|
||||
self, rows: pa.Table, identities: dict[tuple[str, int], list[Any]]
|
||||
) -> pa.Table:
|
||||
matches = []
|
||||
indices = []
|
||||
found = set()
|
||||
for index, (row_id, address) in enumerate(
|
||||
zip(rows.column("_rowid").to_pylist(), rows.column("_rowaddr").to_pylist())
|
||||
):
|
||||
for key in (("_rowid", row_id), ("_rowaddr", address)):
|
||||
for record in identities.get(key, []):
|
||||
found.add(key)
|
||||
indices.append(index)
|
||||
matches.append(record)
|
||||
if found != identities.keys():
|
||||
raise ValueError(
|
||||
"Some failed inputs are no longer addressable in this snapshot; "
|
||||
"refresh the error listing or use a historical snapshot"
|
||||
)
|
||||
rows = rows.take(pa.array(indices, type=pa.int64()))
|
||||
fields = [
|
||||
"column",
|
||||
"error_type",
|
||||
"error_message",
|
||||
"attempts",
|
||||
"function_version",
|
||||
"job_id",
|
||||
"first_seen_at_millis",
|
||||
"last_seen_at_millis",
|
||||
"quarantined",
|
||||
]
|
||||
arrays = [
|
||||
pa.array([getattr(record, field) for record in matches]) for field in fields
|
||||
]
|
||||
if "__function_error" in rows.column_names:
|
||||
raise ValueError("Source columns already contain __function_error")
|
||||
return rows.append_column(
|
||||
"__function_error", pa.StructArray.from_arrays(arrays, names=fields)
|
||||
)
|
||||
|
||||
|
||||
class FunctionErrors(_FunctionErrors):
|
||||
"""Current failures with grouped causes and synchronous source-row lookup."""
|
||||
|
||||
def rows(self, columns: Optional[list[str]] = None) -> pa.Table:
|
||||
"""Return current failing inputs with a ``__function_error`` struct.
|
||||
|
||||
Row IDs come from the error records. The server joins stable identities
|
||||
correctly after compaction; callers need no physical-address arithmetic.
|
||||
"""
|
||||
identities = self._identities()
|
||||
predicate = self._predicate(identities)
|
||||
query = (
|
||||
self._table.search()
|
||||
.where(predicate)
|
||||
.with_row_id(True)
|
||||
.with_row_address()
|
||||
.limit(max(1, len(identities)))
|
||||
)
|
||||
selected = list(self._table.schema.names if columns is None else columns)
|
||||
selected.extend(name for name in ("_rowid", "_rowaddr") if name not in selected)
|
||||
query = query.select(selected)
|
||||
return self._join_rows(query.to_arrow(), identities)
|
||||
|
||||
|
||||
class AsyncFunctionErrors(_FunctionErrors):
|
||||
"""Current Function failures returned by an asynchronous table."""
|
||||
|
||||
async def rows(self, columns: Optional[list[str]] = None) -> pa.Table:
|
||||
"""Return current failing inputs with their ``__function_error`` metadata."""
|
||||
identities = self._identities()
|
||||
predicate = self._predicate(identities)
|
||||
query = (
|
||||
self._table.query()
|
||||
.where(predicate)
|
||||
.with_row_id()
|
||||
.with_row_address()
|
||||
.limit(max(1, len(identities)))
|
||||
)
|
||||
selected = list(
|
||||
(await self._table.schema()).names if columns is None else columns
|
||||
)
|
||||
selected.extend(name for name in ("_rowid", "_rowaddr") if name not in selected)
|
||||
query = query.select(selected)
|
||||
return self._join_rows(await query.to_arrow(), identities)
|
||||
|
||||
|
||||
class RefreshColumnResult(_RemoteValue):
|
||||
"""Terminal result of an expression-backed or Function-backed refresh Job.
|
||||
|
||||
@@ -1169,6 +1383,8 @@ class RefreshColumnResult(_RemoteValue):
|
||||
"""Exact table version the refresh read."""
|
||||
|
||||
published_version: Optional[_UInt64] = None
|
||||
error_groups: tuple[FunctionErrorGroup, ...] = ()
|
||||
error_groups_truncated: bool = False
|
||||
"""Table version made visible by the refresh, when one was published."""
|
||||
|
||||
@property
|
||||
@@ -3487,6 +3703,11 @@ __all__ = [
|
||||
"ResolvedEnvironmentProvenance",
|
||||
"ResolvedPackage",
|
||||
"RefreshColumnResult",
|
||||
"FunctionErrors",
|
||||
"AsyncFunctionErrors",
|
||||
"FunctionErrorGroup",
|
||||
"FunctionProvenance",
|
||||
"FunctionValueProvenance",
|
||||
"FunctionDefinition",
|
||||
]
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ from lancedb.index import (
|
||||
)
|
||||
from lancedb.job import Job
|
||||
from lancedb.functions import (
|
||||
FunctionProvenance,
|
||||
FunctionApplication,
|
||||
FunctionRetryPolicy,
|
||||
RefreshColumnResult,
|
||||
@@ -1185,6 +1186,12 @@ class RemoteTable(Table):
|
||||
init_timeout_seconds: Optional[float] = None,
|
||||
num_workers: Optional[int] = None,
|
||||
max_executor_processes_per_worker: Optional[int] = None,
|
||||
retry_errors: bool = False,
|
||||
retry_job_id: Optional[str] = None,
|
||||
retry_error_type: Optional[str] = None,
|
||||
include_quarantined: bool = False,
|
||||
function_version: Optional[str] = None,
|
||||
recompute: Optional[Literal["failed", "all", "none"]] = None,
|
||||
):
|
||||
return LOOP.run(
|
||||
self._table.refresh_column(
|
||||
@@ -1206,6 +1213,12 @@ class RemoteTable(Table):
|
||||
init_timeout_seconds=init_timeout_seconds,
|
||||
num_workers=num_workers,
|
||||
max_executor_processes_per_worker=max_executor_processes_per_worker,
|
||||
retry_errors=retry_errors,
|
||||
retry_job_id=retry_job_id,
|
||||
retry_error_type=retry_error_type,
|
||||
include_quarantined=include_quarantined,
|
||||
function_version=function_version,
|
||||
recompute=recompute,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1230,6 +1243,12 @@ class RemoteTable(Table):
|
||||
init_timeout_seconds: Optional[float] = None,
|
||||
num_workers: Optional[int] = None,
|
||||
max_executor_processes_per_worker: Optional[int] = None,
|
||||
retry_errors: bool = False,
|
||||
retry_job_id: Optional[str] = None,
|
||||
retry_error_type: Optional[str] = None,
|
||||
include_quarantined: bool = False,
|
||||
function_version: Optional[str] = None,
|
||||
recompute: Optional[Literal["failed", "all", "none"]] = None,
|
||||
) -> Job[RefreshColumnResult]:
|
||||
return Job(
|
||||
LOOP.run(
|
||||
@@ -1252,6 +1271,12 @@ class RemoteTable(Table):
|
||||
init_timeout_seconds=init_timeout_seconds,
|
||||
num_workers=num_workers,
|
||||
max_executor_processes_per_worker=max_executor_processes_per_worker,
|
||||
retry_errors=retry_errors,
|
||||
retry_job_id=retry_job_id,
|
||||
retry_error_type=retry_error_type,
|
||||
include_quarantined=include_quarantined,
|
||||
function_version=function_version,
|
||||
recompute=recompute,
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -1261,9 +1286,42 @@ class RemoteTable(Table):
|
||||
job_id: Optional[str] = None,
|
||||
column: Optional[str] = None,
|
||||
limit: Optional[int] = None,
|
||||
history: bool = False,
|
||||
):
|
||||
return LOOP.run(
|
||||
self._table.function_errors(job_id=job_id, column=column, limit=limit)
|
||||
self._table.function_errors(
|
||||
job_id=job_id, column=column, limit=limit, history=history
|
||||
)
|
||||
).as_sync(self)
|
||||
|
||||
def quarantine_failed(
|
||||
self,
|
||||
column: str,
|
||||
*,
|
||||
error_type: Optional[str] = None,
|
||||
job_id: Optional[str] = None,
|
||||
after_attempts: Optional[int] = None,
|
||||
quarantined: bool = True,
|
||||
) -> int:
|
||||
return LOOP.run(
|
||||
self._table.quarantine_failed(
|
||||
column,
|
||||
error_type=error_type,
|
||||
job_id=job_id,
|
||||
after_attempts=after_attempts,
|
||||
quarantined=quarantined,
|
||||
)
|
||||
)
|
||||
|
||||
def function_provenance(
|
||||
self,
|
||||
column: str,
|
||||
*,
|
||||
limit: Optional[int] = None,
|
||||
version: Optional[int] = None,
|
||||
) -> FunctionProvenance:
|
||||
return LOOP.run(
|
||||
self._table.function_provenance(column, limit=limit, version=version)
|
||||
)
|
||||
|
||||
def column_statuses(
|
||||
|
||||
+352
-18
@@ -84,6 +84,9 @@ from .index import (
|
||||
)
|
||||
from .expr import Expr
|
||||
from .functions import (
|
||||
FunctionErrors,
|
||||
AsyncFunctionErrors,
|
||||
FunctionProvenance,
|
||||
FunctionRetryPolicy,
|
||||
FunctionApplication,
|
||||
RefreshColumnResult as RefreshColumnJobResult,
|
||||
@@ -300,7 +303,6 @@ if TYPE_CHECKING:
|
||||
CompactionStats,
|
||||
Tag,
|
||||
AddColumnsResult,
|
||||
FunctionErrors,
|
||||
RefreshColumnResult,
|
||||
AddResult,
|
||||
AlterColumnsResult,
|
||||
@@ -3290,6 +3292,12 @@ class Table(ABC):
|
||||
init_timeout_seconds: Optional[float] = None,
|
||||
num_workers: Optional[int] = None,
|
||||
max_executor_processes_per_worker: Optional[int] = None,
|
||||
retry_errors: bool = False,
|
||||
retry_job_id: Optional[str] = None,
|
||||
retry_error_type: Optional[str] = None,
|
||||
include_quarantined: bool = False,
|
||||
function_version: Optional[str] = None,
|
||||
recompute: Optional[Literal["failed", "all", "none"]] = None,
|
||||
) -> "RefreshColumnResult":
|
||||
"""
|
||||
Fill the rows of a computed column that hold no value yet.
|
||||
@@ -3365,6 +3373,9 @@ class Table(ABC):
|
||||
error_policy: {"fail", "skip"}, optional
|
||||
Action after failure or retry exhaustion. Skip records the error
|
||||
and attempt count, subject to the server's failure limits.
|
||||
Workflow version 1 servers default to skip with a 5% failure ceiling
|
||||
and publish successful output before reporting a threshold failure.
|
||||
Older deployments retain their existing defaults.
|
||||
max_failed_fraction: float, optional
|
||||
Under a skip policy, fail the job once more than this share of
|
||||
rows (0 to 1) has failed. LanceDB Enterprise only.
|
||||
@@ -3382,6 +3393,23 @@ class Table(ABC):
|
||||
max_executor_processes_per_worker: int, optional
|
||||
Cap on executor processes per Function worker. LanceDB
|
||||
Enterprise only.
|
||||
retry_errors: bool, default False
|
||||
Select current failed rows on the server. Cannot be combined with
|
||||
``where``. Requires Enterprise workflow version 1 or later.
|
||||
retry_job_id: str, optional
|
||||
Restrict a failed-row retry to errors recorded by this job.
|
||||
retry_error_type: str, optional
|
||||
Restrict a failed-row retry to this exception class.
|
||||
include_quarantined: bool, default False
|
||||
Explicitly release and include quarantined rows in a failed-row retry.
|
||||
function_version: str, optional
|
||||
Atomically rebind this column's Function to the specified immutable
|
||||
version. Requires Enterprise workflow version 1 or later.
|
||||
recompute: {"failed", "all", "none"}, optional
|
||||
Which rows to recompute during an upgrade. Requires
|
||||
``function_version``; the default is ``all``. ``failed`` selects
|
||||
current failures, and ``none`` preserves existing values. Quarantined
|
||||
rows stay excluded unless explicitly included in a failed-row retry.
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -3412,6 +3440,12 @@ class Table(ABC):
|
||||
init_timeout_seconds: Optional[float] = None,
|
||||
num_workers: Optional[int] = None,
|
||||
max_executor_processes_per_worker: Optional[int] = None,
|
||||
retry_errors: bool = False,
|
||||
retry_job_id: Optional[str] = None,
|
||||
retry_error_type: Optional[str] = None,
|
||||
include_quarantined: bool = False,
|
||||
function_version: Optional[str] = None,
|
||||
recompute: Optional[Literal["failed", "all", "none"]] = None,
|
||||
) -> Job[RefreshColumnJobResult]:
|
||||
"""
|
||||
Like :meth:`refresh_column`, but returns a handle to the refresh job
|
||||
@@ -3486,6 +3520,9 @@ class Table(ABC):
|
||||
error_policy: {"fail", "skip"}, optional
|
||||
Action after failure or retry exhaustion. Skip records the error
|
||||
and attempt count, subject to the server's failure limits.
|
||||
Workflow version 1 servers default to skip with a 5% failure ceiling
|
||||
and publish successful output before reporting a threshold failure.
|
||||
Older deployments retain their existing defaults.
|
||||
max_failed_fraction: float, optional
|
||||
Under a skip policy, fail the job once more than this share of
|
||||
rows (0 to 1) has failed. LanceDB Enterprise only.
|
||||
@@ -3503,6 +3540,23 @@ class Table(ABC):
|
||||
max_executor_processes_per_worker: int, optional
|
||||
Cap on executor processes per Function worker. LanceDB
|
||||
Enterprise only.
|
||||
retry_errors: bool, default False
|
||||
Select current failed rows on the server. Cannot be combined with
|
||||
``where``. Requires Enterprise workflow version 1 or later.
|
||||
retry_job_id: str, optional
|
||||
Restrict a failed-row retry to errors recorded by this job.
|
||||
retry_error_type: str, optional
|
||||
Restrict a failed-row retry to this exception class.
|
||||
include_quarantined: bool, default False
|
||||
Explicitly release and include quarantined rows in a failed-row retry.
|
||||
function_version: str, optional
|
||||
Atomically rebind this column's Function to the specified immutable
|
||||
version. Requires Enterprise workflow version 1 or later.
|
||||
recompute: {"failed", "all", "none"}, optional
|
||||
Which rows to recompute during an upgrade. Requires
|
||||
``function_version``; the default is ``all``. ``failed`` selects
|
||||
current failures, and ``none`` preserves existing values. Quarantined
|
||||
rows stay excluded unless explicitly included in a failed-row retry.
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -3525,22 +3579,104 @@ class Table(ABC):
|
||||
'finished'
|
||||
"""
|
||||
|
||||
def retry_failed(
|
||||
self,
|
||||
column: str,
|
||||
*,
|
||||
error_type: Optional[str] = None,
|
||||
job_id: Optional[str] = None,
|
||||
include_quarantined: bool = False,
|
||||
function_version: Optional[str] = None,
|
||||
**options: Any,
|
||||
) -> Job[RefreshColumnJobResult]:
|
||||
"""Start a job for exactly the current failed rows.
|
||||
|
||||
Stable row identities survive compaction. Set ``function_version`` to
|
||||
upgrade and retry failures atomically. ``include_quarantined=True``
|
||||
explicitly releases quarantined rows before retrying them.
|
||||
|
||||
>>> job = table.retry_failed("sharpness") # doctest: +SKIP
|
||||
>>> result = job.wait() # doctest: +SKIP
|
||||
"""
|
||||
return self.refresh_column_async(
|
||||
column,
|
||||
retry_errors=True,
|
||||
retry_error_type=error_type,
|
||||
retry_job_id=job_id,
|
||||
include_quarantined=include_quarantined,
|
||||
function_version=function_version,
|
||||
recompute="failed" if function_version is not None else None,
|
||||
**options,
|
||||
)
|
||||
|
||||
def upgrade_column(
|
||||
self,
|
||||
column: str,
|
||||
*,
|
||||
version: str,
|
||||
recompute: Literal["failed", "all", "none"] = "all",
|
||||
**options: Any,
|
||||
) -> Job[RefreshColumnJobResult]:
|
||||
"""Upgrade a Function binding while keeping its columns available.
|
||||
|
||||
``failed`` recomputes current failures, ``all`` recomputes all live rows,
|
||||
and ``none`` preserves existing values. New and changed rows use the new
|
||||
version; ``function_provenance`` identifies each value's producing version.
|
||||
"""
|
||||
return self.refresh_column_async(
|
||||
column, function_version=version, recompute=recompute, **options
|
||||
)
|
||||
|
||||
def quarantine_failed(
|
||||
self,
|
||||
column: str,
|
||||
*,
|
||||
error_type: Optional[str] = None,
|
||||
job_id: Optional[str] = None,
|
||||
after_attempts: Optional[int] = None,
|
||||
quarantined: bool = True,
|
||||
) -> int:
|
||||
"""Quarantine current failures, or release them with ``quarantined=False``.
|
||||
|
||||
Normal and automatic refreshes skip quarantined rows. ``after_attempts``
|
||||
restricts the selection to rows with at least that many failed calls.
|
||||
Returns the number of selected rows. LanceDB Enterprise only.
|
||||
"""
|
||||
raise NotImplementedError("Function quarantine requires LanceDB Enterprise")
|
||||
|
||||
def function_provenance(
|
||||
self,
|
||||
column: str,
|
||||
*,
|
||||
limit: Optional[int] = None,
|
||||
version: Optional[int] = None,
|
||||
) -> FunctionProvenance:
|
||||
"""Read each returned row's producing Function version and job.
|
||||
|
||||
``version`` selects a table snapshot. Check ``truncated`` before treating
|
||||
the returned records as a complete snapshot. LanceDB Enterprise only.
|
||||
"""
|
||||
raise NotImplementedError("Function provenance requires LanceDB Enterprise")
|
||||
|
||||
@abstractmethod
|
||||
def function_errors(
|
||||
self,
|
||||
job_id: Optional[str] = None,
|
||||
column: Optional[str] = None,
|
||||
limit: Optional[int] = None,
|
||||
history: bool = False,
|
||||
) -> "FunctionErrors":
|
||||
"""
|
||||
The per-row errors Function refreshes recorded on this table.
|
||||
|
||||
A refresh running under a skip policy records each row it skipped
|
||||
with the input that failed and the error. This lists those records,
|
||||
newest job first, plus a summary for any fragment whose per-row
|
||||
detail was capped. LanceDB Enterprise only; reading errors
|
||||
needs read access to the table, since a message carries the value
|
||||
that failed.
|
||||
A refresh running under a skip policy records each row it skipped.
|
||||
On servers advertising workflow version 1 or later, the default lists
|
||||
current unresolved failures, deduplicated by row and Function column,
|
||||
with attempt counts and first/last failure times. ``history=True``
|
||||
returns retained observations, including repaired failures. Older servers
|
||||
keep their legacy listing behavior and reject explicit history requests.
|
||||
LanceDB Enterprise only; reading errors needs table read access because
|
||||
messages can include the input that failed.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -3550,6 +3686,10 @@ class Table(ABC):
|
||||
Only errors on this column.
|
||||
limit: int, optional
|
||||
At most this many records (server default 10000, cap 100000).
|
||||
history: bool, default False
|
||||
Include retained historical errors instead of current failures.
|
||||
Requires Enterprise workflow version 1 or later. Historical records
|
||||
cannot be used with the current-input ``rows()`` helper.
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -5706,6 +5846,12 @@ class LanceTable(Table):
|
||||
init_timeout_seconds: Optional[float] = None,
|
||||
num_workers: Optional[int] = None,
|
||||
max_executor_processes_per_worker: Optional[int] = None,
|
||||
retry_errors: bool = False,
|
||||
retry_job_id: Optional[str] = None,
|
||||
retry_error_type: Optional[str] = None,
|
||||
include_quarantined: bool = False,
|
||||
function_version: Optional[str] = None,
|
||||
recompute: Optional[Literal["failed", "all", "none"]] = None,
|
||||
) -> "RefreshColumnResult":
|
||||
"""Fill a computed column's unfilled rows and recompute those whose
|
||||
inputs changed. See
|
||||
@@ -5730,6 +5876,12 @@ class LanceTable(Table):
|
||||
init_timeout_seconds=init_timeout_seconds,
|
||||
num_workers=num_workers,
|
||||
max_executor_processes_per_worker=max_executor_processes_per_worker,
|
||||
retry_errors=retry_errors,
|
||||
retry_job_id=retry_job_id,
|
||||
retry_error_type=retry_error_type,
|
||||
include_quarantined=include_quarantined,
|
||||
function_version=function_version,
|
||||
recompute=recompute,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -5754,6 +5906,12 @@ class LanceTable(Table):
|
||||
init_timeout_seconds: Optional[float] = None,
|
||||
num_workers: Optional[int] = None,
|
||||
max_executor_processes_per_worker: Optional[int] = None,
|
||||
retry_errors: bool = False,
|
||||
retry_job_id: Optional[str] = None,
|
||||
retry_error_type: Optional[str] = None,
|
||||
include_quarantined: bool = False,
|
||||
function_version: Optional[str] = None,
|
||||
recompute: Optional[Literal["failed", "all", "none"]] = None,
|
||||
) -> Job[RefreshColumnJobResult]:
|
||||
"""Fill a computed column's unfilled rows and recompute those whose
|
||||
inputs changed, returning a handle to the refresh job. See
|
||||
@@ -5780,6 +5938,12 @@ class LanceTable(Table):
|
||||
init_timeout_seconds=init_timeout_seconds,
|
||||
num_workers=num_workers,
|
||||
max_executor_processes_per_worker=max_executor_processes_per_worker,
|
||||
retry_errors=retry_errors,
|
||||
retry_job_id=retry_job_id,
|
||||
retry_error_type=retry_error_type,
|
||||
include_quarantined=include_quarantined,
|
||||
function_version=function_version,
|
||||
recompute=recompute,
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -5789,11 +5953,44 @@ class LanceTable(Table):
|
||||
job_id: Optional[str] = None,
|
||||
column: Optional[str] = None,
|
||||
limit: Optional[int] = None,
|
||||
history: bool = False,
|
||||
) -> "FunctionErrors":
|
||||
"""The per-row errors Function refreshes recorded on this table. See
|
||||
[`Table.function_errors`][lancedb.table.Table.function_errors]."""
|
||||
return LOOP.run(
|
||||
self._table.function_errors(job_id=job_id, column=column, limit=limit)
|
||||
self._table.function_errors(
|
||||
job_id=job_id, column=column, limit=limit, history=history
|
||||
)
|
||||
).as_sync(self)
|
||||
|
||||
def quarantine_failed(
|
||||
self,
|
||||
column: str,
|
||||
*,
|
||||
error_type: Optional[str] = None,
|
||||
job_id: Optional[str] = None,
|
||||
after_attempts: Optional[int] = None,
|
||||
quarantined: bool = True,
|
||||
) -> int:
|
||||
return LOOP.run(
|
||||
self._table.quarantine_failed(
|
||||
column,
|
||||
error_type=error_type,
|
||||
job_id=job_id,
|
||||
after_attempts=after_attempts,
|
||||
quarantined=quarantined,
|
||||
)
|
||||
)
|
||||
|
||||
def function_provenance(
|
||||
self,
|
||||
column: str,
|
||||
*,
|
||||
limit: Optional[int] = None,
|
||||
version: Optional[int] = None,
|
||||
) -> FunctionProvenance:
|
||||
return LOOP.run(
|
||||
self._table.function_provenance(column, limit=limit, version=version)
|
||||
)
|
||||
|
||||
def column_statuses(
|
||||
@@ -8221,6 +8418,12 @@ class AsyncTable:
|
||||
init_timeout_seconds: Optional[float] = None,
|
||||
num_workers: Optional[int] = None,
|
||||
max_executor_processes_per_worker: Optional[int] = None,
|
||||
retry_errors: bool = False,
|
||||
retry_job_id: Optional[str] = None,
|
||||
retry_error_type: Optional[str] = None,
|
||||
include_quarantined: bool = False,
|
||||
function_version: Optional[str] = None,
|
||||
recompute: Optional[Literal["failed", "all", "none"]] = None,
|
||||
) -> RefreshColumnResult:
|
||||
"""
|
||||
Fill the rows of a computed column that hold no value yet.
|
||||
@@ -8296,6 +8499,9 @@ class AsyncTable:
|
||||
error_policy: {"fail", "skip"}, optional
|
||||
Action after failure or retry exhaustion. Skip records the error
|
||||
and attempt count, subject to the server's failure limits.
|
||||
Workflow version 1 servers default to skip with a 5% failure ceiling
|
||||
and publish successful output before reporting a threshold failure.
|
||||
Older deployments retain their existing defaults.
|
||||
max_failed_fraction: float, optional
|
||||
Under a skip policy, fail the job once more than this share of
|
||||
rows (0 to 1) has failed. LanceDB Enterprise only.
|
||||
@@ -8313,6 +8519,23 @@ class AsyncTable:
|
||||
max_executor_processes_per_worker: int, optional
|
||||
Cap on executor processes per Function worker. LanceDB
|
||||
Enterprise only.
|
||||
retry_errors: bool, default False
|
||||
Select current failed rows on the server. Cannot be combined with
|
||||
``where``. Requires Enterprise workflow version 1 or later.
|
||||
retry_job_id: str, optional
|
||||
Restrict a failed-row retry to errors recorded by this job.
|
||||
retry_error_type: str, optional
|
||||
Restrict a failed-row retry to this exception class.
|
||||
include_quarantined: bool, default False
|
||||
Explicitly release and include quarantined rows in a failed-row retry.
|
||||
function_version: str, optional
|
||||
Atomically rebind this column's Function to the specified immutable
|
||||
version. Requires Enterprise workflow version 1 or later.
|
||||
recompute: {"failed", "all", "none"}, optional
|
||||
Which rows to recompute during an upgrade. Requires
|
||||
``function_version``; the default is ``all``. ``failed`` selects
|
||||
current failures, and ``none`` preserves existing values. Quarantined
|
||||
rows stay excluded unless explicitly included in a failed-row retry.
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -8340,6 +8563,77 @@ class AsyncTable:
|
||||
init_timeout_seconds=init_timeout_seconds,
|
||||
num_workers=num_workers,
|
||||
max_executor_processes_per_worker=max_executor_processes_per_worker,
|
||||
retry_errors=retry_errors,
|
||||
retry_job_id=retry_job_id,
|
||||
retry_error_type=retry_error_type,
|
||||
include_quarantined=include_quarantined,
|
||||
function_version=function_version,
|
||||
recompute=recompute,
|
||||
)
|
||||
|
||||
async def retry_failed(
|
||||
self,
|
||||
column: str,
|
||||
*,
|
||||
error_type: Optional[str] = None,
|
||||
job_id: Optional[str] = None,
|
||||
include_quarantined: bool = False,
|
||||
function_version: Optional[str] = None,
|
||||
**options: Any,
|
||||
) -> AsyncJob[RefreshColumnJobResult]:
|
||||
"""Start an exact failed-row retry; see ``Table.retry_failed``."""
|
||||
return await self.refresh_column_async(
|
||||
column,
|
||||
retry_errors=True,
|
||||
retry_error_type=error_type,
|
||||
retry_job_id=job_id,
|
||||
include_quarantined=include_quarantined,
|
||||
function_version=function_version,
|
||||
recompute="failed" if function_version is not None else None,
|
||||
**options,
|
||||
)
|
||||
|
||||
async def upgrade_column(
|
||||
self,
|
||||
column: str,
|
||||
*,
|
||||
version: str,
|
||||
recompute: Literal["failed", "all", "none"] = "all",
|
||||
**options: Any,
|
||||
) -> AsyncJob[RefreshColumnJobResult]:
|
||||
"""Upgrade the Function and choose which rows to recompute."""
|
||||
return await self.refresh_column_async(
|
||||
column, function_version=version, recompute=recompute, **options
|
||||
)
|
||||
|
||||
async def quarantine_failed(
|
||||
self,
|
||||
column: str,
|
||||
*,
|
||||
error_type: Optional[str] = None,
|
||||
job_id: Optional[str] = None,
|
||||
after_attempts: Optional[int] = None,
|
||||
quarantined: bool = True,
|
||||
) -> int:
|
||||
"""Quarantine current failures or release them for later refreshes."""
|
||||
return await self._inner.quarantine_function_errors(
|
||||
column,
|
||||
quarantined=quarantined,
|
||||
error_type=error_type,
|
||||
job_id=job_id,
|
||||
after_attempts=after_attempts,
|
||||
)
|
||||
|
||||
async def function_provenance(
|
||||
self,
|
||||
column: str,
|
||||
*,
|
||||
limit: Optional[int] = None,
|
||||
version: Optional[int] = None,
|
||||
) -> FunctionProvenance:
|
||||
"""Read per-row producing versions at a table snapshot."""
|
||||
return FunctionProvenance.from_json(
|
||||
await self._inner.function_provenance(column, limit=limit, version=version)
|
||||
)
|
||||
|
||||
async def function_errors(
|
||||
@@ -8347,16 +8641,19 @@ class AsyncTable:
|
||||
job_id: Optional[str] = None,
|
||||
column: Optional[str] = None,
|
||||
limit: Optional[int] = None,
|
||||
) -> "FunctionErrors":
|
||||
history: bool = False,
|
||||
) -> "AsyncFunctionErrors":
|
||||
"""
|
||||
The per-row errors Function refreshes recorded on this table.
|
||||
|
||||
A refresh running under a skip policy records each row it skipped
|
||||
with the input that failed and the error. This lists those records,
|
||||
newest job first, plus a summary for any fragment whose per-row
|
||||
detail was capped. LanceDB Enterprise only; reading errors
|
||||
needs read access to the table, since a message carries the value
|
||||
that failed.
|
||||
A refresh running under a skip policy records each row it skipped.
|
||||
On servers advertising workflow version 1 or later, the default lists
|
||||
current unresolved failures, deduplicated by row and Function column,
|
||||
with attempt counts and first/last failure times. ``history=True``
|
||||
returns retained observations, including repaired failures. Older servers
|
||||
keep their legacy listing behavior and reject explicit history requests.
|
||||
LanceDB Enterprise only; reading errors needs table read access because
|
||||
messages can include the input that failed.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -8366,10 +8663,14 @@ class AsyncTable:
|
||||
Only errors on this column.
|
||||
limit: int, optional
|
||||
At most this many records (server default 10000, cap 100000).
|
||||
history: bool, default False
|
||||
Include retained historical errors instead of current failures.
|
||||
Requires Enterprise workflow version 1 or later. Historical records
|
||||
cannot be used with the current-input ``rows()`` helper.
|
||||
|
||||
Returns
|
||||
-------
|
||||
FunctionErrors
|
||||
AsyncFunctionErrors
|
||||
``records``, ``fragments`` and ``truncated``, the last saying
|
||||
whether the listing stopped at its limit.
|
||||
|
||||
@@ -8427,9 +8728,10 @@ class AsyncTable:
|
||||
>>> if errors.truncated: # doctest: +SKIP
|
||||
... print("listing stopped at the limit")
|
||||
"""
|
||||
return await self._inner.function_errors(
|
||||
job_id=job_id, column=column, limit=limit
|
||||
raw = await self._inner.function_errors(
|
||||
job_id=job_id, column=column, limit=limit, history=history
|
||||
)
|
||||
return AsyncFunctionErrors(raw, self, history=history)
|
||||
|
||||
async def column_statuses(
|
||||
self, column: Optional[str] = None
|
||||
@@ -8478,6 +8780,12 @@ class AsyncTable:
|
||||
init_timeout_seconds: Optional[float] = None,
|
||||
num_workers: Optional[int] = None,
|
||||
max_executor_processes_per_worker: Optional[int] = None,
|
||||
retry_errors: bool = False,
|
||||
retry_job_id: Optional[str] = None,
|
||||
retry_error_type: Optional[str] = None,
|
||||
include_quarantined: bool = False,
|
||||
function_version: Optional[str] = None,
|
||||
recompute: Optional[Literal["failed", "all", "none"]] = None,
|
||||
) -> AsyncJob[RefreshColumnJobResult]:
|
||||
"""
|
||||
Like :meth:`refresh_column`, but returns a handle to the refresh job
|
||||
@@ -8552,6 +8860,9 @@ class AsyncTable:
|
||||
error_policy: {"fail", "skip"}, optional
|
||||
Action after failure or retry exhaustion. Skip records the error
|
||||
and attempt count, subject to the server's failure limits.
|
||||
Workflow version 1 servers default to skip with a 5% failure ceiling
|
||||
and publish successful output before reporting a threshold failure.
|
||||
Older deployments retain their existing defaults.
|
||||
max_failed_fraction: float, optional
|
||||
Under a skip policy, fail the job once more than this share of
|
||||
rows (0 to 1) has failed. LanceDB Enterprise only.
|
||||
@@ -8569,6 +8880,23 @@ class AsyncTable:
|
||||
max_executor_processes_per_worker: int, optional
|
||||
Cap on executor processes per Function worker. LanceDB
|
||||
Enterprise only.
|
||||
retry_errors: bool, default False
|
||||
Select current failed rows on the server. Cannot be combined with
|
||||
``where``. Requires Enterprise workflow version 1 or later.
|
||||
retry_job_id: str, optional
|
||||
Restrict a failed-row retry to errors recorded by this job.
|
||||
retry_error_type: str, optional
|
||||
Restrict a failed-row retry to this exception class.
|
||||
include_quarantined: bool, default False
|
||||
Explicitly release and include quarantined rows in a failed-row retry.
|
||||
function_version: str, optional
|
||||
Atomically rebind this column's Function to the specified immutable
|
||||
version. Requires Enterprise workflow version 1 or later.
|
||||
recompute: {"failed", "all", "none"}, optional
|
||||
Which rows to recompute during an upgrade. Requires
|
||||
``function_version``; the default is ``all``. ``failed`` selects
|
||||
current failures, and ``none`` preserves existing values. Quarantined
|
||||
rows stay excluded unless explicitly included in a failed-row retry.
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -8613,6 +8941,12 @@ class AsyncTable:
|
||||
init_timeout_seconds=init_timeout_seconds,
|
||||
num_workers=num_workers,
|
||||
max_executor_processes_per_worker=max_executor_processes_per_worker,
|
||||
retry_errors=retry_errors,
|
||||
retry_job_id=retry_job_id,
|
||||
retry_error_type=retry_error_type,
|
||||
include_quarantined=include_quarantined,
|
||||
function_version=function_version,
|
||||
recompute=recompute,
|
||||
),
|
||||
RefreshColumnJobResult.from_json,
|
||||
)
|
||||
|
||||
@@ -21,6 +21,7 @@ import threading
|
||||
import time
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
from unittest.mock import MagicMock, patch
|
||||
from types import SimpleNamespace
|
||||
import uuid
|
||||
import warnings
|
||||
from packaging.version import Version
|
||||
@@ -2382,7 +2383,7 @@ async def test_remote_refresh_async_returns_typed_terminal_result(
|
||||
result = job.wait(timeout=timedelta(seconds=30))
|
||||
|
||||
assert isinstance(result, lancedb.RefreshColumnResult)
|
||||
assert result.model_dump() == terminal_result
|
||||
assert result.model_dump(exclude_defaults=True) == terminal_result
|
||||
assert result.rows_filled == 12
|
||||
assert result.version == 8
|
||||
|
||||
@@ -7845,3 +7846,211 @@ def test_remote_fts_and_rejects_legacy_server():
|
||||
with query_test_table(handler, vector_columns={}) as table:
|
||||
with pytest.raises(NotImplementedError, match="server version 0.3.0"):
|
||||
table.search("gripper closed", query_type="fts", operator="AND").to_list()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("async_table", [False, True])
|
||||
async def test_function_failure_workflow_uses_exact_retry_and_upgrade_apis(async_table):
|
||||
received = []
|
||||
result = {
|
||||
"rows_assigned": 1000,
|
||||
"rows_failed": 100,
|
||||
"rows_remaining": 0,
|
||||
"source_version": 7,
|
||||
"published_version": 8,
|
||||
"error_groups": [
|
||||
{
|
||||
"column": "derived",
|
||||
"error_type": "RowTimeoutError",
|
||||
"error_message": "timeout",
|
||||
"rows_failed": 100,
|
||||
}
|
||||
],
|
||||
"error_groups_truncated": False,
|
||||
}
|
||||
|
||||
def handler(request):
|
||||
length = int(request.headers.get("Content-Length", 0))
|
||||
body = json.loads(request.rfile.read(length)) if length else {}
|
||||
received.append((request.path, body))
|
||||
status = 200
|
||||
if request.path == "/v1/table/test/describe/":
|
||||
response = {"version": 8, "schema": {"fields": []}}
|
||||
elif request.path == "/v1/table/test/backfill_column":
|
||||
status = 202
|
||||
response = {"job_id": "refresh-1"}
|
||||
elif request.path == "/v1/jobs/describe":
|
||||
response = {
|
||||
"job_id": "refresh-1",
|
||||
"job_type": "function_refresh",
|
||||
"job_state": "DONE",
|
||||
"result": result,
|
||||
}
|
||||
elif request.path == "/v1/table/test/errors/quarantine":
|
||||
response = {"rows_affected": 100}
|
||||
elif request.path == "/v1/table/test/function_provenance":
|
||||
response = {
|
||||
"records": [
|
||||
{
|
||||
"column": "derived",
|
||||
"job_id": "refresh-1",
|
||||
"function_name": "check",
|
||||
"function_version": "2",
|
||||
"row_id": 42,
|
||||
"source_version": 7,
|
||||
"published_version": 8,
|
||||
}
|
||||
],
|
||||
"truncated": False,
|
||||
}
|
||||
elif request.path == "/v1/table/test/errors":
|
||||
response = {
|
||||
"records": [],
|
||||
"fragments": [],
|
||||
"truncated": False,
|
||||
"workflow_version": 1,
|
||||
}
|
||||
else:
|
||||
status = 404
|
||||
response = {}
|
||||
request.send_response(status)
|
||||
request.send_header("Content-Type", "application/json")
|
||||
request.end_headers()
|
||||
request.wfile.write(json.dumps(response).encode())
|
||||
|
||||
retry_options = dict(
|
||||
error_type="ValueError",
|
||||
job_id="first",
|
||||
include_quarantined=True,
|
||||
function_version="2",
|
||||
max_failed_fraction=1.0,
|
||||
)
|
||||
if async_table:
|
||||
async with mock_lancedb_connection_async(handler) as db:
|
||||
table = await db.open_table("test")
|
||||
job = await table.retry_failed("derived", **retry_options)
|
||||
terminal = await job.wait()
|
||||
await table.upgrade_column("derived", version="3", recompute="none")
|
||||
affected = await table.quarantine_failed("derived", after_attempts=3)
|
||||
provenance = await table.function_provenance("derived")
|
||||
errors = await table.function_errors(column="derived", history=True)
|
||||
else:
|
||||
with mock_lancedb_connection(handler) as db:
|
||||
table = db.open_table("test")
|
||||
terminal = table.retry_failed("derived", **retry_options).wait()
|
||||
table.upgrade_column("derived", version="3", recompute="none")
|
||||
affected = table.quarantine_failed("derived", after_attempts=3)
|
||||
provenance = table.function_provenance("derived")
|
||||
errors = table.function_errors(column="derived", history=True)
|
||||
|
||||
refreshes = [body for path, body in received if path.endswith("backfill_column")]
|
||||
assert refreshes == [
|
||||
{
|
||||
"column": "derived",
|
||||
"retry_errors": True,
|
||||
"retry_job_id": "first",
|
||||
"retry_error_type": "ValueError",
|
||||
"include_quarantined": True,
|
||||
"function_version": "2",
|
||||
"recompute": "failed",
|
||||
"max_failed_fraction": 1.0,
|
||||
},
|
||||
{"column": "derived", "function_version": "3", "recompute": "none"},
|
||||
]
|
||||
assert terminal.rows_assigned == 1000
|
||||
assert terminal.error_groups[0].rows_failed == 100
|
||||
assert affected == 100
|
||||
assert provenance.records[0].function_version == "2"
|
||||
assert provenance.records[0].row_id == 42
|
||||
assert errors.summary() == []
|
||||
assert ("/v1/table/test/errors", {"column": "derived", "history": True}) in received
|
||||
|
||||
|
||||
def test_function_error_rows_returns_all_inputs_and_preserves_multiple_column_errors(
|
||||
tmp_path,
|
||||
):
|
||||
db = lancedb.connect(tmp_path)
|
||||
table = db.create_table("inputs", [{"id": index} for index in range(16)])
|
||||
inputs = table.search().select(["id", "_rowid", "_rowaddr"]).limit(16).to_arrow()
|
||||
records = [
|
||||
SimpleNamespace(
|
||||
column="first",
|
||||
row_id=row_id,
|
||||
row_address=999999,
|
||||
row_offset=0,
|
||||
input=None,
|
||||
error_type="ValueError",
|
||||
error_message="corrupt",
|
||||
attempts=3,
|
||||
function_version="1",
|
||||
job_id="first",
|
||||
first_seen_at_millis=100,
|
||||
last_seen_at_millis=200,
|
||||
quarantined=False,
|
||||
)
|
||||
for row_id in inputs.column("_rowid").to_pylist()
|
||||
]
|
||||
duplicate = copy.copy(records[0])
|
||||
duplicate.column = "second"
|
||||
records.append(duplicate)
|
||||
errors = lancedb.FunctionErrors(
|
||||
SimpleNamespace(
|
||||
records=records, fragments=[], truncated=False, workflow_version=1
|
||||
),
|
||||
table,
|
||||
)
|
||||
rows = errors.rows(columns=["id"])
|
||||
assert rows.num_rows == 17
|
||||
assert sorted(set(rows.column("id").to_pylist())) == list(range(16))
|
||||
assert rows.column("__function_error").type.field("column").name == "column"
|
||||
assert [group.rows_failed for group in errors.summary()] == [16, 1]
|
||||
legacy = copy.copy(records[0])
|
||||
legacy.row_id = None
|
||||
legacy.row_address = inputs.column("_rowaddr")[0].as_py()
|
||||
legacy_errors = lancedb.FunctionErrors(
|
||||
SimpleNamespace(
|
||||
records=[legacy], fragments=[], truncated=False, workflow_version=1
|
||||
),
|
||||
table,
|
||||
)
|
||||
assert legacy_errors.rows(columns=["id"]).column("id").to_pylist() == [0]
|
||||
|
||||
incomplete = lancedb.FunctionErrors(
|
||||
SimpleNamespace(
|
||||
records=records, fragments=[], truncated=True, workflow_version=1
|
||||
),
|
||||
table,
|
||||
)
|
||||
with pytest.raises(ValueError, match="incomplete"):
|
||||
incomplete.rows()
|
||||
|
||||
|
||||
def test_exact_function_retries_fail_before_writing_to_older_servers():
|
||||
writes = []
|
||||
|
||||
def handler(request):
|
||||
length = int(request.headers.get("Content-Length", 0))
|
||||
body = request.rfile.read(length) if length else b""
|
||||
if request.path == "/v1/table/test/describe/":
|
||||
response = {"version": 1, "schema": {"fields": []}}
|
||||
elif request.path == "/v1/table/test/errors":
|
||||
response = {"records": [], "fragments": [], "truncated": False}
|
||||
else:
|
||||
writes.append((request.path, body))
|
||||
response = {}
|
||||
request.send_response(200)
|
||||
request.send_header("Content-Type", "application/json")
|
||||
request.end_headers()
|
||||
request.wfile.write(json.dumps(response).encode())
|
||||
|
||||
with mock_lancedb_connection(handler) as db:
|
||||
table = db.open_table("test")
|
||||
with pytest.raises(NotImplementedError, match="server does not support"):
|
||||
table.retry_failed("derived")
|
||||
with pytest.raises(NotImplementedError, match="server does not support"):
|
||||
table.upgrade_column("derived", version="2", recompute="failed")
|
||||
with pytest.raises(NotImplementedError, match="server does not support"):
|
||||
table.function_errors(history=True)
|
||||
with pytest.raises(NotImplementedError, match="server does not support"):
|
||||
table.function_errors().summary()
|
||||
assert writes == []
|
||||
|
||||
Reference in New Issue
Block a user