feat(sdk): add typed Optimize previews

This commit is contained in:
ChilePiquin
2026-11-19 18:05:40 -08:00
parent c89678f21a
commit 4266c883fd
27 changed files with 1148 additions and 97 deletions
+29
View File
@@ -639,6 +639,35 @@ await table.enableRTE({
***
### explainOptimize()
```ts
explainOptimize(_options?): Promise<OptimizePlan>
```
Preview Enterprise data rewriting using the same flat settings as optimizeAsync().
Requires structured SQL preview support, table Ownership and parent Usage.
Creates no maintenance job and does not poll job APIs. Cleanup, separate index
maintenance, Embedded and historical-version handles are unsupported.
A later submission plans its own snapshot.
#### Parameters
* **\_options?**: [`OptimizeOptions`](../interfaces/OptimizeOptions.md)
#### Returns
`Promise`&lt;[`OptimizePlan`](../interfaces/OptimizePlan.md)&gt;
#### Example
```ts
const plan = await table.explainOptimize({ maxSourceRows: 1_000_000 });
console.log(plan.sourceVersion, plan.plannedSourceRows);
```
***
### explainPrewarmData()
```ts
+2
View File
@@ -128,6 +128,8 @@
- [OAuthConfig](interfaces/OAuthConfig.md)
- [OpenTableOptions](interfaces/OpenTableOptions.md)
- [OptimizeOptions](interfaces/OptimizeOptions.md)
- [OptimizePlan](interfaces/OptimizePlan.md)
- [OptimizeResolvedOptions](interfaces/OptimizeResolvedOptions.md)
- [OptimizeResult](interfaces/OptimizeResult.md)
- [OptimizeStats](interfaces/OptimizeStats.md)
- [PrewarmDataOptions](interfaces/PrewarmDataOptions.md)
+91
View File
@@ -0,0 +1,91 @@
[**@lancedb/lancedb**](../README.md) • **Docs**
***
[@lancedb/lancedb](../globals.md) / OptimizePlan
# Interface: OptimizePlan
Data-rewrite preview without creating a maintenance job.
Counts describe planned work, not committed results, runtime, or memory use.
A later submission chooses its own snapshot and may select different work.
## Properties
### branch
```ts
branch: string;
```
***
### effectiveOptions
```ts
effectiveOptions: OptimizeResolvedOptions;
```
***
### moreWork
```ts
moreWork: boolean;
```
***
### namespace
```ts
namespace: string[];
```
***
### operation
```ts
operation: "rewrite_data";
```
***
### plannedFragments
```ts
plannedFragments: number;
```
***
### plannedGroups
```ts
plannedGroups: number;
```
***
### plannedSourceRows
```ts
plannedSourceRows: number;
```
***
### sourceVersion
```ts
sourceVersion: number;
```
***
### table
```ts
table: string;
```
@@ -0,0 +1,43 @@
[**@lancedb/lancedb**](../README.md) • **Docs**
***
[@lancedb/lancedb](../globals.md) / OptimizeResolvedOptions
# Interface: OptimizeResolvedOptions
Effective settings after Enterprise policy resolution.
## Properties
### batchSize
```ts
batchSize: null | number;
```
***
### ioBufferSize
```ts
ioBufferSize: null | number;
```
Zero disables byte-based I/O backpressure; null uses the worker default.
***
### maxSourceRows
```ts
maxSourceRows: null | number;
```
***
### targetRowsPerFragment
```ts
targetRowsPerFragment: number;
```
+4
View File
@@ -1520,6 +1520,10 @@ 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.optimize.OptimizePlan
::: lancedb.optimize.OptimizeResolvedOptions
::: lancedb.optimize.OptimizeResult
::: lancedb.prewarm.PrewarmDataResult
+47
View File
@@ -238,6 +238,11 @@ EXPLAIN OPTIMIZE events REWRITE DATA WITH (
max_source_rows = 1000000
);
EXPLAIN (FORMAT JSON) OPTIMIZE events REWRITE DATA WITH (
target_rows_per_fragment = 100000,
max_source_rows = 1000000
);
DESCRIBE JOB '<job_id>' FORMAT JSON;
```
@@ -245,6 +250,48 @@ The preview uses the execution planner to report the source version, resolved
options, planned groups/fragments/rows, and whether more eligible work remains.
It creates no job. Submission plans against its own snapshot, so concurrent
writes can change the work after a preview. `EXPLAIN ANALYZE` is unsupported.
The explicit JSON form returns a versioned response with `operation: "rewrite_data"`;
plain EXPLAIN retains its existing output. PREWARM uses the same explicit format syntax.
The SDK helpers return a typed `OptimizePlan` using the same flat rewrite settings
as durable submission:
<Tabs>
<Tab title="Python">
```python
plan = table.explain_optimize(max_source_rows=1_000_000, io_buffer_size=0)
print(plan.source_version, plan.planned_source_rows, plan.more_work)
```
Async Python uses `await table.explain_optimize(...)` with the same settings.
</Tab>
<Tab title="TypeScript">
```typescript
const plan = await table.explainOptimize({ maxSourceRows: 1_000_000, ioBufferSize: 0 });
console.log(plan.sourceVersion, plan.plannedSourceRows, plan.moreWork);
```
</Tab>
<Tab title="Rust">
```rust
use lancedb::table::optimize::OptimizeOptions;
let plan = table.explain_optimize(OptimizeOptions {
max_source_rows: Some(1_000_000),
io_buffer_size: Some(0),
..Default::default()
}).await?;
println!("{} {}", plan.source_version, plan.planned_source_rows);
```
</Tab>
</Tabs>
`effective_options` (`effectiveOptions` in TypeScript) contains the resolved
fragment target, source-row budget, I/O buffer size, and batch size. Counts describe
planned work, not committed results, runtime, or a memory estimate. A null optional
setting retains the worker default; an explicit zero I/O buffer remains zero.
Preview covers only data rewriting. Cleanup, separate index maintenance,
Embedded tables, and historical-version handles are unsupported. The helper
requires a server supporting the explicit JSON syntax and fails without falling
back to text parsing, REST, or execution.
JSON job diagnostics include reported maintenance progress and the completed
operation result alongside the existing time profile. While a job runs, its