mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
LanceDB SDKs can submit data prewarm jobs, but callers have to issue SQL directly to inspect a plan before warming. The existing text response does not provide a typed pruning contract. This adds metadata-only preview helpers across Rust, Python sync/async, and TypeScript, using a compatible Enterprise server’s structured SQL response. This was accomplished with the following changes: - Add `explain_prewarm_data(PrewarmDataOptions)`, Python `explain_prewarm_data(...)`, and TypeScript `explainPrewarmData(options)`. - Expose `PrewarmDataPlan` and `PrewarmPruningSummary`, preserving zero versus unknown counts and future pruning-mode strings. - Reuse submission options, identifier/filter validation, namespace and branch context, and Azure source-account hint handling. - Validate the versioned JSON response without parsing display text, submitting a warming job, polling HTTP job APIs, or falling back to REST. - Add API documentation, Flight SQL transport tests, Python sync/async response tests, and an opt-in live-service integration test. ### Usage and behaviour ```python plan = table.explain_prewarm_data(["payload"], filter="quality > 0.7") print(plan.table_version, plan.pruning.selected_fragments) ``` The helper returns a plan directly. It requires table Select plus database/namespace Usage and a server supporting `EXPLAIN (FORMAT JSON) PREWARM`. It reads metadata without creating a warming job. Selected ranges are conservative physical candidates; unknown counts remain `None`/`null`. A later submission resolves and plans its own snapshot. Historical-version and Embedded table handles are unsupported.
79 lines
3.0 KiB
TypeScript
79 lines
3.0 KiB
TypeScript
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
|
|
|
/** Reported executor work for a pinned snapshot; unavailable measurements stay null. */
|
|
export interface PrewarmDataResult {
|
|
/** The source snapshot captured by submission. */
|
|
tableVersion: number;
|
|
/** Reported executors targeted, or null when unavailable. */
|
|
executorsTargeted: number | null;
|
|
/** Executors that finished successfully or partially, or null when unavailable. */
|
|
executorsCompleted: number | null;
|
|
/** Subset of completed executors reporting partial warming, or null when unavailable. */
|
|
executorsPartial: number | null;
|
|
/** Reported fragments selected, or null when unavailable. */
|
|
fragmentsSelected: number | null;
|
|
/** Reported ranges completed, or null when unavailable. */
|
|
rangesCompleted: number | null;
|
|
/** Reported bytes read, or null when unavailable. */
|
|
bytesRead: number | null;
|
|
}
|
|
|
|
/** @internal */
|
|
export function decodePrewarmDataResult(value: unknown): PrewarmDataResult {
|
|
// Rust validates the typed wire result before handing it to JavaScript.
|
|
const result = value as Record<string, number | null>;
|
|
return {
|
|
tableVersion: result.table_version as number,
|
|
executorsTargeted: result.executors_targeted ?? null,
|
|
executorsCompleted: result.executors_completed ?? null,
|
|
executorsPartial: result.executors_partial ?? null,
|
|
fragmentsSelected: result.fragments_selected ?? null,
|
|
rangesCompleted: result.ranges_completed ?? null,
|
|
bytesRead: result.bytes_read ?? null,
|
|
};
|
|
}
|
|
|
|
/** Metadata-only snapshot preview; no warming job is submitted. */
|
|
export interface PrewarmDataPlan {
|
|
/** Snapshot used for this preview. A later submission plans its own snapshot. */
|
|
tableVersion: number;
|
|
/** Readable display text. Use pruning for structured facts. */
|
|
plan: string;
|
|
pruning: PrewarmPruningSummary;
|
|
}
|
|
|
|
/** Conservative metadata proof, rather than exact matching rows. */
|
|
export interface PrewarmPruningSummary {
|
|
/** Server-reported proof mode; future servers may add modes. */
|
|
mode: string;
|
|
inputFragments: number;
|
|
selectedFragments: number;
|
|
prunedFragments: number;
|
|
/** Candidate physical intervals, or null when unknown. */
|
|
selectedRowRanges: number | null;
|
|
fallbackReason: string | null;
|
|
}
|
|
|
|
/** @internal */
|
|
export function decodePrewarmDataPlan(value: unknown): PrewarmDataPlan {
|
|
// Rust validates the versioned response before handing it to JavaScript.
|
|
const result = value as {
|
|
[key: string]: unknown;
|
|
pruning: Record<string, number | string | null>;
|
|
};
|
|
return {
|
|
tableVersion: result.table_version as number,
|
|
plan: result.plan as string,
|
|
pruning: {
|
|
mode: result.pruning.mode as string,
|
|
inputFragments: result.pruning.input_fragments as number,
|
|
selectedFragments: result.pruning.selected_fragments as number,
|
|
prunedFragments: result.pruning.pruned_fragments as number,
|
|
selectedRowRanges:
|
|
(result.pruning.selected_row_ranges as number | null) ?? null,
|
|
fallbackReason: (result.pruning.fallback_reason as string | null) ?? null,
|
|
},
|
|
};
|
|
}
|