mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
fix(sdk): align Optimize behavior and inherit Embedded policy
This commit is contained in:
@@ -6007,9 +6007,7 @@ describe("durable compaction validation", () => {
|
||||
test("rejects local tables and unknown options", async () => {
|
||||
const db = await connect(`memory://compaction-job-${Date.now()}`);
|
||||
const table = await db.createTable("test", [{ id: 1 }]);
|
||||
await expect(table.optimizeAsync()).rejects.toThrow(
|
||||
"only supported on remote tables",
|
||||
);
|
||||
await expect(table.optimizeAsync()).rejects.toThrow("LanceDB Enterprise");
|
||||
await expect(
|
||||
table.optimizeAsync({ unrecognizedLimit: 1 } as never),
|
||||
).rejects.toThrow("Unsupported Optimize option");
|
||||
@@ -6080,7 +6078,7 @@ describe("Optimize action selection", () => {
|
||||
expect(stats.prune.oldVersionsRemoved).toBe(0);
|
||||
expect((await table.listVersions()).length).toBeGreaterThan(before.length);
|
||||
expect((await table.indexStats("id_idx"))?.numUnindexedRows).toBe(2);
|
||||
await table.optimize();
|
||||
await table.optimize({ targetRowsPerFragment: 100 });
|
||||
expect((await table.indexStats("id_idx"))?.numUnindexedRows).toBe(0);
|
||||
await table.checkout(1);
|
||||
expect(await table.countRows()).toBe(1);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||
|
||||
/** Actual committed outcome of one remote Optimize data rewrite. */
|
||||
/** Actual committed outcome of one Enterprise Optimize data rewrite. */
|
||||
export interface OptimizeResult {
|
||||
/** A bounded run left eligible work for another invocation. */
|
||||
moreWork: boolean;
|
||||
|
||||
@@ -187,9 +187,9 @@ export interface PrewarmDataOptions {
|
||||
}
|
||||
|
||||
/** Flat Optimize settings for submission and durable jobs.
|
||||
* Remote jobs support data rewrites; cleanup options are Embedded-only. */
|
||||
* Enterprise jobs support data rewrites; cleanup options are Embedded-only. */
|
||||
export interface OptimizeOptions {
|
||||
/** Positive target rows per output fragment. Omitted remote values inherit table policy. */
|
||||
/** Positive target rows per output fragment. Omitted Enterprise values inherit table policy. */
|
||||
targetRowsPerFragment?: number;
|
||||
/** Positive live-source-row budget across whole rewrite tasks. */
|
||||
maxSourceRows?: number;
|
||||
@@ -199,7 +199,9 @@ export interface OptimizeOptions {
|
||||
batchSize?: number;
|
||||
/** @deprecated Pass rewrite settings directly on OptimizeOptions. */
|
||||
compactionOptions?: CompactionOptions;
|
||||
/** Run only data rewriting, retaining history and skipping separate index maintenance. */
|
||||
/** Select only data rewriting, retaining history and skipping separate index maintenance.
|
||||
* For convenience calls, omit for Embedded's full rewrite/prune/index cycle.
|
||||
* Enterprise, durable jobs, and previews support rewriting only. */
|
||||
action?: "rewrite_data";
|
||||
/** Embedded: remove versions committed before this cutoff. Defaults to seven days ago.
|
||||
* Cannot be combined with action="rewrite_data" or used with durable Optimize jobs. */
|
||||
@@ -1319,10 +1321,10 @@ export abstract class Table {
|
||||
*/
|
||||
abstract restore(): Promise<void>;
|
||||
/**
|
||||
* Submit remote Optimize and return its durable job after acceptance.
|
||||
* Submit Enterprise Optimize 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
|
||||
* a compatible Enterprise server and table Ownership plus parent Usage. Embedded 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.
|
||||
@@ -1337,7 +1339,7 @@ export abstract class Table {
|
||||
async optimizeAsync(
|
||||
_options?: OptimizeOptions,
|
||||
): Promise<Job<OptimizeResult>> {
|
||||
throw new Error("Optimize jobs are only supported on remote tables");
|
||||
throw new Error("Optimize jobs are only supported in LanceDB Enterprise");
|
||||
}
|
||||
|
||||
/** @deprecated Use optimizeAsync() instead. */
|
||||
|
||||
+6
-1
@@ -1057,7 +1057,12 @@ impl Table {
|
||||
.transpose()?
|
||||
.unwrap_or_default();
|
||||
let stats = if rewrite_only {
|
||||
inner.optimize(overrides).await
|
||||
inner
|
||||
.optimize(lancedb::table::OptimizeAction::RewriteData {
|
||||
options: overrides.into(),
|
||||
remap_options: None,
|
||||
})
|
||||
.await
|
||||
} else {
|
||||
inner
|
||||
.optimize_full_with_overrides(overrides, None, before_timestamp, delete_unverified)
|
||||
|
||||
Reference in New Issue
Block a user