mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 20:44:00 +00:00
feat(sdk): add durable compaction jobs with typed results
This commit is contained in:
@@ -456,7 +456,7 @@ Rejects a table that exists but is not a materialized view.
|
||||
### dropMaterializedViewAsync()
|
||||
|
||||
```ts
|
||||
abstract dropMaterializedViewAsync(name, namespacePath?): Promise<Job>
|
||||
abstract dropMaterializedViewAsync(name, namespacePath?): Promise<Job<void>>
|
||||
```
|
||||
|
||||
Start dropping the materialized view named `name` and return its job.
|
||||
@@ -473,7 +473,7 @@ Rejects a table that exists but is not a materialized view.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`Job`](Job.md)>
|
||||
`Promise`<[`Job`](Job.md)<`void`>>
|
||||
|
||||
***
|
||||
|
||||
@@ -532,7 +532,7 @@ Drop an existing table.
|
||||
### dropTableAsync()
|
||||
|
||||
```ts
|
||||
abstract dropTableAsync(name, namespacePath?): Promise<Job>
|
||||
abstract dropTableAsync(name, namespacePath?): Promise<Job<void>>
|
||||
```
|
||||
|
||||
Start dropping a table and return its cleanup job.
|
||||
@@ -548,7 +548,7 @@ on the returned job to know when cleanup has finished.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`Job`](Job.md)>
|
||||
`Promise`<[`Job`](Job.md)<`void`>>
|
||||
|
||||
***
|
||||
|
||||
@@ -579,7 +579,7 @@ catalog removal; physical cleanup continues in the background.
|
||||
### dropViewAsync()
|
||||
|
||||
```ts
|
||||
abstract dropViewAsync(name, namespacePath?): Promise<Job>
|
||||
abstract dropViewAsync(name, namespacePath?): Promise<Job<void>>
|
||||
```
|
||||
|
||||
Drop a view and return its SQL query job.
|
||||
@@ -594,7 +594,7 @@ catalog removal; physical cleanup continues in the background.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`Job`](Job.md)>
|
||||
`Promise`<[`Job`](Job.md)<`void`>>
|
||||
|
||||
***
|
||||
|
||||
@@ -729,7 +729,7 @@ state and error behavior; options control page size and the starting token.
|
||||
### openJob()
|
||||
|
||||
```ts
|
||||
abstract openJob(jobId): Promise<Job>
|
||||
abstract openJob<T>(jobId): Promise<Job<T>>
|
||||
```
|
||||
|
||||
Open a server-side job by id, returning a handle with its record already
|
||||
@@ -740,13 +740,17 @@ The returned [Job](Job.md) answers for its own state, specification,
|
||||
result, failure and event history, so there is no separate
|
||||
connection-level call for any of them.
|
||||
|
||||
#### Type Parameters
|
||||
|
||||
• **T** = `void`
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **jobId**: `string`
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`Job`](Job.md)>
|
||||
`Promise`<[`Job`](Job.md)<`T`>>
|
||||
|
||||
***
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
[@lancedb/lancedb](../globals.md) / Job
|
||||
|
||||
# Class: Job
|
||||
# Class: Job<T>
|
||||
|
||||
A handle to an operation that may still be running.
|
||||
|
||||
@@ -20,6 +20,10 @@ extra round trip on every call:
|
||||
- Registry details are null until one of those runs. Query handles report
|
||||
jobType "query" immediately.
|
||||
|
||||
## Type Parameters
|
||||
|
||||
• **T** = `void`
|
||||
|
||||
## Accessors
|
||||
|
||||
### creationMs
|
||||
@@ -241,7 +245,7 @@ printing it.
|
||||
### wait()
|
||||
|
||||
```ts
|
||||
wait(progressCallback?): Promise<void>
|
||||
wait(progressCallback?): Promise<T>
|
||||
```
|
||||
|
||||
Wait until the operation reaches a terminal state.
|
||||
@@ -259,4 +263,4 @@ callback exception does not reject `wait`.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`void`>
|
||||
`Promise`<`T`>
|
||||
|
||||
@@ -305,6 +305,40 @@ It is a no-op when no writers are cached.
|
||||
|
||||
***
|
||||
|
||||
### compactAsync()
|
||||
|
||||
```ts
|
||||
compactAsync(_options?): Promise<Job<CompactionResult>>
|
||||
```
|
||||
|
||||
Submit remote compaction and return its durable job after acceptance.
|
||||
|
||||
Uses SQL OPTIMIZE, inheriting branch and namespace from this table. Requires
|
||||
a compatible remote server and table Ownership plus parent Usage. Local and
|
||||
historical-version handles are unsupported. Existing optimize() behavior is unchanged.
|
||||
Waiting tracks the rewrite itself and returns actual row/file statistics.
|
||||
Missing result payloads are errors; older workers can omit file counts.
|
||||
Status, progress, events and cancellation reuse the generic HTTP job APIs.
|
||||
Reopen with db.openJob<CompactionResult>(job.id!). A wait timeout does not cancel work.
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **\_options?**: [`CompactionOptions`](../interfaces/CompactionOptions.md)
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`Job`](Job.md)<[`CompactionResult`](../interfaces/CompactionResult.md)>>
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const job = await table.compactAsync({ targetRowsPerFragment: 1000 });
|
||||
const result = await job.wait();
|
||||
console.log(result.rowsSucceeded, result.fragmentsRemoved);
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### compactRTE()
|
||||
|
||||
```ts
|
||||
@@ -423,7 +457,7 @@ await table.createIndex("my_float_col");
|
||||
### createIndexAsync()
|
||||
|
||||
```ts
|
||||
abstract createIndexAsync(column, options?): Promise<Job>
|
||||
abstract createIndexAsync(column, options?): Promise<Job<void>>
|
||||
```
|
||||
|
||||
Create an index, returning a handle to the indexing job.
|
||||
@@ -444,7 +478,7 @@ account for the replacement caveat described in [Table.createIndex](Table.md#cre
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`Job`](Job.md)>
|
||||
`Promise`<[`Job`](Job.md)<`void`>>
|
||||
|
||||
***
|
||||
|
||||
@@ -1076,7 +1110,7 @@ Prewarm one or more columns of data in the table.
|
||||
### prewarmDataAsync()
|
||||
|
||||
```ts
|
||||
abstract prewarmDataAsync(options?): Promise<Job>
|
||||
abstract prewarmDataAsync(options?): Promise<Job<void>>
|
||||
```
|
||||
|
||||
Submit data prewarm through SQL and return its durable warming-job handle.
|
||||
@@ -1098,7 +1132,7 @@ the job. After `job.refresh()`, `job.spec.table_version` is the pinned version.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`Job`](Job.md)>
|
||||
`Promise`<[`Job`](Job.md)<`void`>>
|
||||
|
||||
#### Example
|
||||
|
||||
@@ -1238,7 +1272,7 @@ number of rows filled and the new version number of the table.
|
||||
### refreshColumnAsync()
|
||||
|
||||
```ts
|
||||
abstract refreshColumnAsync(column, options?): Promise<Job>
|
||||
abstract refreshColumnAsync(column, options?): Promise<Job<void>>
|
||||
```
|
||||
|
||||
Like [Table#refreshColumn](Table.md#refreshcolumn), but returns a handle to the refresh
|
||||
@@ -1285,7 +1319,7 @@ LanceDB Enterprise it is the server's backfill job.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`Job`](Job.md)>
|
||||
`Promise`<[`Job`](Job.md)<`void`>>
|
||||
|
||||
#### Example
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@
|
||||
- [ColumnAlteration](interfaces/ColumnAlteration.md)
|
||||
- [ColumnOrdering](interfaces/ColumnOrdering.md)
|
||||
- [CompactionOptions](interfaces/CompactionOptions.md)
|
||||
- [CompactionResult](interfaces/CompactionResult.md)
|
||||
- [CompactionStats](interfaces/CompactionStats.md)
|
||||
- [ConnectNamespaceOptions](interfaces/ConnectNamespaceOptions.md)
|
||||
- [ConnectionOptions](interfaces/ConnectionOptions.md)
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
[**@lancedb/lancedb**](../README.md) • **Docs**
|
||||
|
||||
***
|
||||
|
||||
[@lancedb/lancedb](../globals.md) / CompactionResult
|
||||
|
||||
# Interface: CompactionResult
|
||||
|
||||
Actual committed outcome of one remote compaction job.
|
||||
|
||||
## Properties
|
||||
|
||||
### completionPercentage
|
||||
|
||||
```ts
|
||||
completionPercentage: number;
|
||||
```
|
||||
|
||||
Percentage of planned live rows committed, from 0 to 100.
|
||||
|
||||
***
|
||||
|
||||
### filesAdded
|
||||
|
||||
```ts
|
||||
filesAdded: null | number;
|
||||
```
|
||||
|
||||
Data files added by committed rewrites; null if an older worker omitted it.
|
||||
|
||||
***
|
||||
|
||||
### filesRemoved
|
||||
|
||||
```ts
|
||||
filesRemoved: null | number;
|
||||
```
|
||||
|
||||
Data files removed by committed rewrites; null if an older worker omitted it.
|
||||
|
||||
***
|
||||
|
||||
### fragmentsAdded
|
||||
|
||||
```ts
|
||||
fragmentsAdded: null | number;
|
||||
```
|
||||
|
||||
Fragments added by committed rewrites; null if an older worker omitted it.
|
||||
|
||||
***
|
||||
|
||||
### fragmentsRemoved
|
||||
|
||||
```ts
|
||||
fragmentsRemoved: null | number;
|
||||
```
|
||||
|
||||
Fragments removed by committed rewrites; null if an older worker omitted it.
|
||||
|
||||
***
|
||||
|
||||
### moreWork
|
||||
|
||||
```ts
|
||||
moreWork: boolean;
|
||||
```
|
||||
|
||||
A bounded run left eligible work for another invocation.
|
||||
|
||||
***
|
||||
|
||||
### partialCommit
|
||||
|
||||
```ts
|
||||
partialCommit: boolean;
|
||||
```
|
||||
|
||||
Some planned groups were not committed.
|
||||
|
||||
***
|
||||
|
||||
### rowsFailed
|
||||
|
||||
```ts
|
||||
rowsFailed: number;
|
||||
```
|
||||
|
||||
Planned live rows not committed by this job.
|
||||
|
||||
***
|
||||
|
||||
### rowsSucceeded
|
||||
|
||||
```ts
|
||||
rowsSucceeded: number;
|
||||
```
|
||||
|
||||
Live source rows in committed rewrite groups.
|
||||
@@ -1432,3 +1432,5 @@ that accepts `python_bundle.resources`.
|
||||
|
||||
Caches, hidden paths, symlinks and unsafe paths are excluded. Use `pip=` or
|
||||
`conda=` for platform-specific dependencies and `models=` for large model snapshots.
|
||||
|
||||
::: lancedb.compaction.CompactionResult
|
||||
|
||||
@@ -63,6 +63,73 @@ separately from [`cleanup`](/maintenance/cleanup). The two are distinct jobs
|
||||
even though `optimize()` bundles both in one LanceDB Embedded call.
|
||||
</Note>
|
||||
|
||||
## Track on-demand Enterprise compaction {#compaction-jobs}
|
||||
|
||||
On compatible Enterprise deployments, `compact_async()` / `compactAsync()`
|
||||
submits SQL `OPTIMIZE ... REWRITE DATA` and returns a durable job handle.
|
||||
The table handle supplies the namespace and branch. The existing remote
|
||||
`optimize()` call keeps returning after submission with placeholder statistics;
|
||||
use the job-returning API to wait for the actual rewrite and obtain its result.
|
||||
|
||||
<CodeGroup>
|
||||
```python Python
|
||||
from datetime import timedelta
|
||||
|
||||
job = table.compact_async(
|
||||
compaction_options={"target_rows_per_fragment": 1000, "batch_size": 128}
|
||||
)
|
||||
result = job.wait(timeout=timedelta(minutes=10))
|
||||
print(result.rows_succeeded, result.fragments_removed, result.fragments_added)
|
||||
|
||||
# Resume from another process with the same connection settings.
|
||||
result = db.open_job(job.id).wait()
|
||||
```
|
||||
```typescript TypeScript
|
||||
import type { CompactionResult } from "@lancedb/lancedb";
|
||||
|
||||
const job = await table.compactAsync({
|
||||
targetRowsPerFragment: 1000, batchSize: 128,
|
||||
});
|
||||
const result = await job.wait();
|
||||
console.log(result.rowsSucceeded, result.fragmentsRemoved, result.fragmentsAdded);
|
||||
|
||||
if (job.id !== null) {
|
||||
await (await db.openJob<CompactionResult>(job.id)).wait();
|
||||
}
|
||||
```
|
||||
```rust Rust
|
||||
use lancedb::table::{CompactionResult, optimize::CompactionOverrides};
|
||||
|
||||
let job = table.compact_async(CompactionOverrides {
|
||||
target_rows_per_fragment: Some(1000),
|
||||
batch_size: Some(128),
|
||||
..Default::default()
|
||||
}).await?;
|
||||
let result = job.wait().await?;
|
||||
println!("Committed {} rows", result.rows_succeeded);
|
||||
|
||||
if let Some(id) = job.id() {
|
||||
db.open_job(id).await?.into_typed::<CompactionResult>()?.wait().await?;
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
The result describes this job's committed rewrites, not a comparison of table
|
||||
versions that could include concurrent writes. `partial_commit` identifies an
|
||||
incomplete commit; `rows_failed` counts planned rows left uncommitted.
|
||||
`more_work` means a bounded run left eligible work for another invocation.
|
||||
A genuine no-op reports zero file/fragment counts; counts omitted by an older
|
||||
worker are `None` in Python/Rust or `null` in TypeScript. A server that publishes
|
||||
no compaction result raises an error when waiting, rather than fabricating zero
|
||||
statistics.
|
||||
|
||||
Submission requires Flight SQL connectivity and, under Standard authorization,
|
||||
table Ownership plus Usage on the database and namespace hierarchy. Status,
|
||||
progress, events, and cancellation use the generic HTTP job APIs and their
|
||||
existing permissions. A wait timeout or dropping the handle does not cancel
|
||||
the job. Local tables and historical-version checkouts are unsupported by the
|
||||
job-returning API; ordinary embedded `optimize()` remains available.
|
||||
|
||||
## Retraining indexes {#retrain}
|
||||
|
||||
Folding new rows into an index preserves the structure the index was trained on.
|
||||
|
||||
Reference in New Issue
Block a user