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:
@@ -2351,3 +2351,47 @@ describe("lazy resource listings", () => {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("remote compaction job results", () => {
|
||||
test.each([true, false])(
|
||||
"reopens typed compaction result (counts=%s)",
|
||||
async (counts) => {
|
||||
await withMockDatabase(
|
||||
(request, response) => {
|
||||
expect(request.url).toBe("/v1/jobs/describe");
|
||||
const result = JSON.parse(`{
|
||||
"partial_commit": false,
|
||||
"rows_succeeded": 12,
|
||||
"rows_failed": 0,
|
||||
"completion_percentage": 100
|
||||
}`);
|
||||
if (counts) {
|
||||
Object.assign(
|
||||
result,
|
||||
JSON.parse(`{
|
||||
"files_added": 1,
|
||||
"files_removed": 3,
|
||||
"fragments_added": 1,
|
||||
"fragments_removed": 3
|
||||
}`),
|
||||
);
|
||||
}
|
||||
response.writeHead(200, { "Content-Type": "application/json" });
|
||||
response.end(
|
||||
`{"job_id":"compacting-job","job_type":"compact","job_state":"DONE","result":${JSON.stringify(result)}}`,
|
||||
);
|
||||
},
|
||||
async (db) => {
|
||||
const job =
|
||||
await db.openJob<import("../lancedb").CompactionResult>(
|
||||
"compacting-job",
|
||||
);
|
||||
const result = await job.wait();
|
||||
expect(result.rowsSucceeded).toBe(12);
|
||||
expect(result.moreWork).toBe(false);
|
||||
expect(result.fragmentsRemoved).toBe(counts ? 3 : null);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -5818,3 +5818,19 @@ describe("computed columns", () => {
|
||||
expect(rows.map((r) => r.doubled).sort()).toEqual([10, 2]);
|
||||
});
|
||||
});
|
||||
|
||||
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.compactAsync()).rejects.toThrow(
|
||||
"only supported on remote tables",
|
||||
);
|
||||
await expect(
|
||||
table.compactAsync({ unrecognizedLimit: 1 } as never),
|
||||
).rejects.toThrow("Unsupported compaction option");
|
||||
await expect(
|
||||
table.compactAsync({ targetRowsPerFragment: 0 }),
|
||||
).rejects.toThrow("safe integer");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user