mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 20:44:00 +00:00
feat(sdk)!: submit data prewarm through SQL with durable jobs
This commit is contained in:
@@ -4711,6 +4711,36 @@ describe.each(arrowVersions)(
|
||||
);
|
||||
});
|
||||
|
||||
test("prewarmDataAsync validates options and rejects local tables", async () => {
|
||||
const db = await connect(tmpDir.name);
|
||||
const table = await db.createTable("prewarm_job", [{ id: 1 }]);
|
||||
await expect(table.prewarmDataAsync()).rejects.toThrow(
|
||||
"only supported on remote tables",
|
||||
);
|
||||
await expect(
|
||||
table.prewarmDataAsync({
|
||||
columns: ["id"],
|
||||
filter: "id > 0",
|
||||
concurrency: 2,
|
||||
}),
|
||||
).rejects.toThrow("only supported on remote tables");
|
||||
await expect(
|
||||
table.prewarmDataAsync({ unsupported: 1 } as never),
|
||||
).rejects.toThrow("Unsupported data prewarm option: unsupported");
|
||||
for (const concurrency of [
|
||||
0,
|
||||
-1,
|
||||
1.5,
|
||||
Number.NaN,
|
||||
Number.POSITIVE_INFINITY,
|
||||
4294967296,
|
||||
]) {
|
||||
await expect(table.prewarmDataAsync({ concurrency })).rejects.toThrow(
|
||||
"concurrency must be an integer",
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("full text index on list", async () => {
|
||||
const db = await connect(tmpDir.name);
|
||||
const data = [
|
||||
|
||||
@@ -172,6 +172,7 @@ export {
|
||||
UpdateOptions,
|
||||
OptimizeOptions,
|
||||
CompactionOptions,
|
||||
PrewarmDataOptions,
|
||||
Version,
|
||||
WriteProgress,
|
||||
FtsToken,
|
||||
|
||||
+43
-2
@@ -165,6 +165,16 @@ export interface UpdateOptions {
|
||||
where: string;
|
||||
}
|
||||
|
||||
/** Settings for submitting a durable remote data-cache prewarm job. */
|
||||
export interface PrewarmDataOptions {
|
||||
/** Lance field paths to warm; omitted or empty means every column. */
|
||||
columns?: string[];
|
||||
/** A single SQL predicate for conservative metadata pruning. */
|
||||
filter?: string;
|
||||
/** Positive per-executor concurrency, at most 4294967295. */
|
||||
concurrency?: number;
|
||||
}
|
||||
|
||||
/** Per-invocation compaction settings. Values must be safe integers. */
|
||||
export interface CompactionOptions {
|
||||
/** Positive target rows per output fragment; also affects candidate selection. */
|
||||
@@ -567,8 +577,8 @@ export abstract class Table {
|
||||
* This will load the column data into the page cache so that future queries that
|
||||
* read those columns avoid the initial cold-start latency. This call initiates
|
||||
* prewarming and returns once the request is accepted; the warming itself may
|
||||
* continue in the background. Calling it on already-prewarmed columns is a
|
||||
* no-op on the server.
|
||||
* continue in the background. Submission uses SQL PREWARM and needs Flight
|
||||
* SQL connectivity. Use {@link prewarmDataAsync} to retain the job handle.
|
||||
*
|
||||
* Prewarming is generally useful for columns used in filters or projections.
|
||||
* Large columns (e.g. high-dimensional vectors or binary data) may not be
|
||||
@@ -578,6 +588,28 @@ export abstract class Table {
|
||||
*/
|
||||
abstract prewarmData(columns?: string[]): Promise<void>;
|
||||
|
||||
/**
|
||||
* Submit data prewarm through SQL and return its durable warming-job handle.
|
||||
*
|
||||
* The table handle supplies the branch and namespace. Requires a compatible
|
||||
* SQL PREWARM server and Flight SQL connectivity. Standard authorization
|
||||
* requires table Select and database/namespace Usage. Status/wait use generic
|
||||
* HTTP job APIs; events and cancellation retain their own privileges.
|
||||
* No REST fallback or option-dropping retry is performed. Historical-version
|
||||
* handles are unsupported; call `checkoutLatest()` first.
|
||||
*
|
||||
* Submission returns after acceptance. Use `job.wait()` for completion, or
|
||||
* save `job.id` and reopen it with `db.openJob(id)`. A timeout does not cancel
|
||||
* the job. After `job.refresh()`, `job.spec.table_version` is the pinned version.
|
||||
*
|
||||
* @example
|
||||
* const job = await table.prewarmDataAsync({
|
||||
* columns: ["video"], filter: "quality > 0.7", concurrency: 4,
|
||||
* });
|
||||
* await job.wait();
|
||||
*/
|
||||
abstract prewarmDataAsync(options?: PrewarmDataOptions): Promise<Job>;
|
||||
|
||||
/**
|
||||
* Waits for asynchronous indexing to complete on the table.
|
||||
*
|
||||
@@ -1503,6 +1535,15 @@ export class LocalTable extends Table {
|
||||
await this.inner.prewarmData(columns);
|
||||
}
|
||||
|
||||
async prewarmDataAsync(options?: PrewarmDataOptions): Promise<Job> {
|
||||
for (const key of Object.keys(options ?? {})) {
|
||||
if (!["columns", "filter", "concurrency"].includes(key)) {
|
||||
throw new Error(`Unsupported data prewarm option: ${key}`);
|
||||
}
|
||||
}
|
||||
return new Job(await this.inner.prewarmDataAsync(options));
|
||||
}
|
||||
|
||||
async waitForIndex(
|
||||
indexNames: string[],
|
||||
timeoutSeconds: number,
|
||||
|
||||
@@ -25,6 +25,32 @@ use crate::merge::NativeMergeInsertBuilder;
|
||||
use crate::query::{Query, TakeQuery, VectorQuery};
|
||||
use crate::util::schema_to_buffer;
|
||||
|
||||
/// Settings for durable data-cache prewarm submission.
|
||||
#[napi(object)]
|
||||
pub struct PrewarmDataOptions {
|
||||
pub columns: Option<Vec<String>>,
|
||||
pub filter: Option<String>,
|
||||
pub concurrency: Option<f64>,
|
||||
}
|
||||
|
||||
impl PrewarmDataOptions {
|
||||
fn into_options(self) -> napi::Result<lancedb::table::PrewarmDataOptions> {
|
||||
let mut options =
|
||||
lancedb::table::PrewarmDataOptions::new().columns(self.columns.unwrap_or_default());
|
||||
options.filter = self.filter;
|
||||
if let Some(value) = self.concurrency {
|
||||
if !value.is_finite() || value.fract() != 0.0 || value < 1.0 || value > u32::MAX as f64
|
||||
{
|
||||
return Err(napi::Error::from_reason(
|
||||
"concurrency must be an integer between 1 and 4294967295",
|
||||
));
|
||||
}
|
||||
options.concurrency = Some(value as u32);
|
||||
}
|
||||
Ok(options)
|
||||
}
|
||||
}
|
||||
|
||||
/// Per-invocation file-compaction settings. All numbers must be safe integers.
|
||||
#[napi(object)]
|
||||
pub struct CompactionOptions {
|
||||
@@ -296,6 +322,23 @@ impl Table {
|
||||
.default_error()
|
||||
}
|
||||
|
||||
#[napi(catch_unwind)]
|
||||
pub async fn prewarm_data_async(
|
||||
&self,
|
||||
options: Option<PrewarmDataOptions>,
|
||||
) -> napi::Result<crate::job::Job> {
|
||||
let options = options
|
||||
.map(PrewarmDataOptions::into_options)
|
||||
.transpose()?
|
||||
.unwrap_or_default();
|
||||
let job = self
|
||||
.inner_ref()?
|
||||
.prewarm_data_async(options)
|
||||
.await
|
||||
.default_error()?;
|
||||
Ok(crate::job::Job::new(job))
|
||||
}
|
||||
|
||||
#[napi(catch_unwind)]
|
||||
pub async fn wait_for_index(&self, index_names: Vec<String>, timeout_s: i64) -> Result<()> {
|
||||
let timeout = std::time::Duration::from_secs(timeout_s.try_into().unwrap());
|
||||
|
||||
Reference in New Issue
Block a user