Remote data prewarm used REST even though SQL supported filters and concurrency, and both maintenance APIs returned after acceptance without exposing a consistent typed completion handle. Compaction's legacy statistics therefore could not describe the work committed by its durable job. This PR adds job-returning compaction and data-prewarm methods across Rust, Python sync/async and TypeScript, and moves data-prewarm submission to SQL. Legacy methods retain return-after-acceptance behavior; data prewarm now requires a compatible SQL PREWARM server and Flight SQL connectivity. This consolidates #5037, #5055 and #4906. This was accomplished with the following changes: - Added `compact_async()` / `compactAsync()` and `prewarm_data_async()` / `prewarmDataAsync()`, retaining the command receipt's durable job ID. - Added `PrewarmDataOptions` for columns, a metadata-pruning filter and concurrency; both operations inherit database, namespace and branch from the table handle. - Added filter/concurrency arguments to legacy Python `prewarm_data()` and a TypeScript `prewarmData(options)` overload, preserving the columns-array form and discarding the handle after acceptance. - Added typed `CompactionResult` and `PrewarmDataResult` decoding, including reopened jobs; missing result payloads fail explicitly and omitted measurements remain unknown. - Reused the shared Job lifecycle for status, refresh, progress callbacks, cancellation and events; Python maintenance progress bars display rewritten rows or completed executors. - Added TypeScript `wait({ timeoutMs, onProgress })` and Rust `wait_with_options(JobWaitOptions)`, complementing Python's existing timeout argument without cancelling the durable job. - Validated single unambiguous receipts, preserved compaction option presence/default inheritance, and returned actionable unsupported-server errors without dropping options or falling back to REST. - Updated native bindings, API references and maintenance documentation with job methods, result semantics, tuning and compatibility requirements. ### Usage and behaviour **New** = added here; **Enhanced** = existing support extended; **Existing** = already on main. This table describes remote SDK behavior; server-side SQL/CLI capabilities are prerequisites, not additions made by this SDK PR. | Surface | Capability | Compact | Data prewarm | Assessment | | --- | --- | --- | --- | --- | | Rust / Python sync+async / TypeScript | Submission transport | Existing SQL OPTIMIZE | **New:** REST → SQL PREWARM | Both now submit through SQL | | All SDKs | Durable job-returning API | **New:** `compact_async` / `compactAsync` | **New:** `prewarm_data_async` / `prewarmDataAsync` | Same lifecycle model | | All SDKs | Options and target scope | **New handle:** four existing compaction overrides, with omitted fields inherited | **New options:** columns/filter/concurrency | Namespace and branch preserved for both | | Python / TypeScript | Legacy convenience calls | Existing optimize acceptance behavior preserved | **Enhanced:** legacy methods accept filter/concurrency and use SQL | Return after acceptance; no completion wait | | All SDKs | Typed successful result | **New:** committed rows, file/fragment changes, partial commit and `more_work` | **New:** pinned version, fragments and executor outcomes | Different measurements are intentional | | All SDKs | Status / refresh / progress | Existing Job APIs reused by **new** maintenance handle | Existing Job APIs reused by **new** maintenance handle | HTTP monitoring remains | | Python / TypeScript | Progress presentation | **Enhanced:** rewrite rows/groups | **Enhanced:** executor progress | Shared callbacks; Python bars use operation counters | | All SDKs | Bounded wait | Python existing; **new** TS/Rust timeout controls | Same shared timeout support | Timeout stops this wait; job continues | | All SDKs | Reopen and await typed outcome | **New:** compaction result decoding on reopened handle | **New:** prewarm result decoding on reopened handle | Rust selects the typed result explicitly | | All SDKs | Cancel / events | Existing shared APIs available on **new** handle | Same | HTTP underneath; permissions unchanged | | All SDKs | Typed preview helper | Unavailable | Unavailable | General SQL where exposed; no helper added | | Authorization | Submission | Existing table Ownership plus parent Usage | SQL path uses Select plus parent Usage | Intentional difference | | All SDKs | Local / historical handles | New durable API rejects them | New durable API rejects them | Remote current-branch jobs only | ```python from datetime import timedelta # Legacy convenience call: returns None after acceptance. table.prewarm_data(["payload"], filter="id >= 1000", concurrency=4) warm = table.prewarm_data_async(["payload"], filter="id >= 1000", concurrency=4) warmed = warm.wait(timeout=timedelta(minutes=10), progress=print) print(warmed.table_version, warmed.executors_completed) compact = table.compact_async(compaction_options={"max_source_rows": 1000000}) committed = compact.wait(timeout=timedelta(minutes=10), progress=print) print(committed.rows_succeeded, committed.fragments_removed, committed.more_work) reopened_result = db.open_job(compact.id).wait() ``` ```typescript await table.prewarmData({ columns: ["payload"], filter: "id >= 1000", concurrency: 4 }); const job = await table.prewarmDataAsync({ columns: ["payload"], filter: "id >= 1000", concurrency: 4, }); const result = await job.wait({ timeoutMs: 600_000, onProgress: console.log }); ``` ```rust use std::time::Duration; use lancedb::job::JobWaitOptions; let job = table.compact_async(Default::default()).await?; let result = job.wait_with_options( JobWaitOptions::new().timeout(Duration::from_secs(600)), ).await?; ``` Python async tables await both submission and Job methods. Rust's legacy `prewarm_data(columns)` keeps its columns-only signature; use `PrewarmDataOptions` on the new job-returning method for filtering/concurrency. Wait deadlines cover pending status requests and polling delays. Existing `wait()`, TypeScript `wait(callback)` and Rust `wait_with_progress(callback)` remain supported. Status/progress/refresh/cancel/events still use generic HTTP job APIs; those endpoints and their read/event/cancel permissions must remain available. Cancelling or timing out does not roll back committed work. Compaction results describe committed rewrites and include deletion files in file counts. Prewarm results describe work against a pinned snapshot, with partial executors included in completed executors; nonempty byte/range measurements remain unknown. Missing results require compatible server/worker support rather than placeholder zero statistics. Filtering uses conservative metadata pruning, not an exact row-filter scan. ### Testing Six checked-in live Python sync/async cases pass against matching server/worker builds for compaction, job-returning prewarm and legacy filtered submission. Ten additional live Node scenarios pass for legacy/default/options forms, filters/concurrency, empty plans, validation, persisted specifications and readback. Targeted regressions pass: Python remote maintenance (80), shared jobs (82), local prewarm rejection (4); Node remote (107) and prewarm API cases (28), plus the previously exercised Rust remote regressions. Tests cover receipt parsing, typed results, reopening, unknown measurements, timeouts, and legacy calls returning None/undefined without polling. Dependency pins are unchanged. Azure account-hint acknowledgment was verified locally with filesystem storage; real Azure-backed storage still needs deployment-specific validation.
18 KiB
@lancedb/lancedb • Docs
@lancedb/lancedb / Connection
Class: abstract Connection
A LanceDB Connection that allows you to open tables and create new ones.
Connection could be local against filesystem or remote against a server.
A Connection is intended to be a long lived object and may hold open resources such as HTTP connection pools. This is generally fine and a single connection should be shared if it is going to be used many times. However, if you are finished with a connection, you may call close to eagerly free these resources. Any call to a Connection method after it has been closed will result in an error.
Closing a connection is optional. Connections will automatically be closed when they are garbage collected.
Any created tables are independent and will continue to work even if the underlying connection has been closed.
Methods
cancelJob()
abstract cancelJob(jobId): Promise<boolean>
Request cancellation of a server-side job by id.
Resolves to true if the server accepted the cancellation, false if no such job exists. Cancelling an already-terminal job is a no-op success.
Parameters
- jobId:
string
Returns
Promise<boolean>
cloneTable()
abstract cloneTable(
targetTableName,
sourceUri,
options?): Promise<Table>
Clone a table from a source table.
A shallow clone creates a new table that shares the underlying data files with the source table but has its own independent manifest. This allows both the source and cloned tables to evolve independently while initially sharing the same data, deletion, and index files.
Parameters
-
targetTableName:
stringThe name of the target table to create. -
sourceUri:
stringThe URI of the source table to clone from. -
options? Clone options.
-
options.isShallow?:
booleanWhether to perform a shallow clone (defaults to true). -
options.sourceTag?:
stringThe tag of the source table to clone. -
options.sourceVersion?:
numberThe version of the source table to clone. -
options.targetNamespacePath?:
string[] The namespace path for the target table (defaults to root namespace).
Returns
Promise<Table>
close()
abstract close(): void
Close the connection, releasing any underlying resources.
It is safe to call this method multiple times.
Any attempt to use the connection after it is closed will result in an error.
Returns
void
createEmptyTable()
createEmptyTable(name, schema, options)
abstract createEmptyTable(
name,
schema,
options?): Promise<Table>
Creates a new empty Table
Parameters
-
name:
stringThe name of the table. -
schema:
SchemaLikeThe schema of the table -
options?:
Partial<CreateTableOptions> Additional options (backwards compatibility)
Returns
Promise<Table>
createEmptyTable(name, schema, namespacePath, options)
abstract createEmptyTable(
name,
schema,
namespacePath?,
options?): Promise<Table>
Creates a new empty Table
Parameters
-
name:
stringThe name of the table. -
schema:
SchemaLikeThe schema of the table -
namespacePath?:
string[] The namespace path to create the table in (defaults to root namespace) -
options?:
Partial<CreateTableOptions> Additional options
Returns
Promise<Table>
createMaterializedView()
abstract createMaterializedView(
name,
source,
options?): Promise<MaterializedView>
Define a materialized view named name over the table source.
LanceDB Embedded creation and refresh require a source build with the
experimental-functions Cargo feature, disabled in published packages.
LanceDB Enterprise operations do not require this feature.
The view is populated before creation returns. Set withNoData to create
only its definition and empty backing table. The view is a normal table:
it can be queried, indexed and searched, and it appears in tableNames.
Parameters
-
name:
string -
source:
string -
options?
-
options.limit?:
number -
options.select?:
MaterializedViewSelect -
options.where?:
string -
options.withNoData?:
boolean
Returns
Promise<MaterializedView>
createNamespace()
abstract createNamespace(namespacePath, options?): Promise<CreateNamespaceResponse>
Create a new namespace at the given path.
Parameters
-
namespacePath:
string[] The namespace path to create. -
options?:
Partial<CreateNamespaceOptions> Creationmode("create" | "exist_ok" | "overwrite") and optionalpropertiesto attach to the namespace.
Returns
Promise<CreateNamespaceResponse>
The properties of the created namespace and an optional transaction id.
createTable()
createTable(options, namespacePath)
abstract createTable(options, namespacePath?): Promise<Table>
Creates a new Table and initialize it with new data.
Parameters
-
options:
object&Partial<CreateTableOptions> The options object. -
namespacePath?:
string[] The namespace path to create the table in (defaults to root namespace)
Returns
Promise<Table>
createTable(name, data, options)
abstract createTable(
name,
data,
options?): Promise<Table>
Creates a new Table and initialize it with new data.
Parameters
-
name:
stringThe name of the table. -
data:
TableLike|Record<string,unknown>[] Non-empty Array of Records to be inserted into the table -
options?:
Partial<CreateTableOptions> Additional options (backwards compatibility)
Returns
Promise<Table>
createTable(name, data, namespacePath, options)
abstract createTable(
name,
data,
namespacePath?,
options?): Promise<Table>
Creates a new Table and initialize it with new data.
Parameters
-
name:
stringThe name of the table. -
data:
TableLike|Record<string,unknown>[] Non-empty Array of Records to be inserted into the table -
namespacePath?:
string[] The namespace path to create the table in (defaults to root namespace) -
options?:
Partial<CreateTableOptions> Additional options
Returns
Promise<Table>
createView()
abstract createView(
name,
query,
namespacePath?): Promise<ViewDescription>
Create a view: a named query the database plans on every read.
The query is planned once, at creation, so one that cannot be planned is rejected now rather than at the first read. A view holds no rows, and its readers see its sources as they are at read time.
There is no replace: a name already taken is an error, and changing a view is a drop followed by a create.
Parameters
-
name:
string -
query:
string -
namespacePath?:
string[]
Returns
Promise<ViewDescription>
describeNamespace()
abstract describeNamespace(namespacePath): Promise<DescribeNamespaceResponse>
Describe a namespace, returning its properties.
Parameters
- namespacePath:
string[] The namespace path to describe, in parent → child order, e.g.["analytics", "sales"].
Returns
Promise<DescribeNamespaceResponse>
The namespace's properties (may be undefined if the namespace has none).
describeView()
abstract describeView(name, namespacePath?): Promise<ViewDescription>
What this database records about the view named name: its defining
query and the schema that query resolved to.
Parameters
-
name:
string -
namespacePath?:
string[]
Returns
Promise<ViewDescription>
display()
abstract display(): string
Return a brief description of the connection
Returns
string
dropAllTables()
abstract dropAllTables(namespacePath?): Promise<void>
Drop all tables in the database.
Parameters
- namespacePath?:
string[] The namespace path to drop tables from (defaults to root namespace).
Returns
Promise<void>
dropMaterializedView()
abstract dropMaterializedView(name, namespacePath?): Promise<void>
Drop the materialized view named name.
Remote drops wait for the SQL command to remove the catalog binding. Physical cleanup continues in the background.
Rejects a table that exists but is not a materialized view.
Parameters
-
name:
string -
namespacePath?:
string[]
Returns
Promise<void>
dropMaterializedViewAsync()
abstract dropMaterializedViewAsync(name, namespacePath?): Promise<Job<void>>
Start dropping the materialized view named name and return its job.
Remote jobs have type query and use the SQL query ID as id. Waiting
confirms catalog removal; physical cleanup continues in the background.
Rejects a table that exists but is not a materialized view.
Parameters
-
name:
string -
namespacePath?:
string[]
Returns
Promise<Job<void>>
dropNamespace()
abstract dropNamespace(namespacePath, options?): Promise<DropNamespaceResponse>
Drop a namespace.
Use behavior: "cascade" to also drop everything contained in the
namespace (sub-namespaces and tables). The default "restrict"
behavior refuses to drop a non-empty namespace.
Parameters
-
namespacePath:
string[] The namespace path to drop. -
options?:
Partial<DropNamespaceOptions>mode("skip" | "fail" for missing-namespace handling) andbehavior("restrict" | "cascade").
Returns
Promise<DropNamespaceResponse>
Any properties returned by the server and an optional transaction id.
dropTable()
abstract dropTable(name, namespacePath?): Promise<void>
Drop an existing table.
Parameters
-
name:
stringThe name of the table to drop. -
namespacePath?:
string[] The namespace path of the table (defaults to root namespace).
Returns
Promise<void>
dropTableAsync()
abstract dropTableAsync(name, namespacePath?): Promise<Job<void>>
Start dropping a table and return its cleanup job.
The table may become unavailable before its data files are removed. Wait on the returned job to know when cleanup has finished.
Parameters
-
name:
string -
namespacePath?:
string[]
Returns
Promise<Job<void>>
dropView()
abstract dropView(name, namespacePath?): Promise<void>
Drop the view named name and wait for catalog removal.
The tables it reads are untouched: a view holds no rows of its own. Use dropViewAsync to retain its SQL query job. Completion confirms catalog removal; physical cleanup continues in the background.
Parameters
-
name:
string -
namespacePath?:
string[]
Returns
Promise<void>
dropViewAsync()
abstract dropViewAsync(name, namespacePath?): Promise<Job<void>>
Drop a view and return its SQL query job.
The job has type query and its ID is the SQL query UUID. Waiting confirms
catalog removal; physical cleanup continues in the background.
Parameters
-
name:
string -
namespacePath?:
string[]
Returns
Promise<Job<void>>
isOpen()
abstract isOpen(): boolean
Return true if the connection has not been closed
Returns
boolean
listJobs()
abstract listJobs(options?): Listing<JobInfo>
Iterate lazily over server-side jobs across the database's tables.
Use for await...of. Options control page size and the starting token.
See Listing for pagination state and error behavior.
Parameters
- options?:
ListingOptions
Returns
listMaterializedViews()
abstract listMaterializedViews(options?): Listing<string>
The names of the materialized views in this database.
Iterate lazily with for await...of. Local listings inspect table schemas
one page at a time. Options control page size and the starting token.
See Listing for pagination state and error behavior.
Parameters
- options?:
ListingOptions
Returns
Listing<string>
listNamespaces()
abstract listNamespaces(namespacePath?, options?): Listing<string>
Lazily list immediate child namespaces, 100 per page by default.
Parameters
-
namespacePath?:
string[] -
options?:
ListingOptions
Returns
Listing<string>
listTables()
abstract listTables(namespacePath?, options?): Listing<string>
Lazily list tables in a namespace, requesting 100 per page by default.
Parameters
-
namespacePath?:
string[] -
options?:
ListingOptions
Returns
Listing<string>
Example
for await (const name of conn.listTables([], { pageLimit: 20 })) {
console.log(name);
}
listViews()
abstract listViews(namespacePath?, options?): Listing<string>
The names of the views in one namespace.
Names only; a definition comes from describeView.
Iterate lazily with for await...of. See Listing for pagination
state and error behavior; options control page size and the starting token.
Parameters
-
namespacePath?:
string[] -
options?:
ListingOptions
Returns
Listing<string>
openJob()
abstract openJob<T>(jobId): Promise<Job<T>>
Open a server-side job by id, returning a handle with its record already populated. Rejects when the server has no such job, the way Connection.openTable does for a missing table.
The returned Job answers for its own state, specification, result, failure and event history, so there is no separate connection-level call for any of them.
Type Parameters
• T = void
Parameters
- jobId:
string
Returns
Promise<Job<T>>
openMaterializedView()
abstract openMaterializedView(name): Promise<MaterializedView>
Open the materialized view named name.
Rejects a table that exists but is not a materialized view.
Parameters
- name:
string
Returns
Promise<MaterializedView>
openTable()
abstract openTable(
name,
namespacePath?,
options?): Promise<Table>
Parameters
-
name:
string -
namespacePath?:
string[] -
options?:
Partial<OpenTableOptions>
Returns
Promise<Table>
pauseJob()
abstract pauseJob(jobId): Promise<string>
Pause a server-side job by id.
The job's workers drain and it stays parked until resumed. Resolves to "pausing", "already_paused", or "committing" -- a job finalizing its results cannot be parked; retry shortly.
Parameters
- jobId:
string
Returns
Promise<string>
renameTable()
abstract renameTable(
currentName,
newName,
options?): Promise<void>
Rename a table.
Supported in LanceDB Enterprise and by namespace backends that implement renaming. Directory namespaces support renaming tables resolved through their manifest, including tables within or across child namespaces. LanceDB Embedded connections and directory-listing root tables reject with a "not supported" error.
Parameters
-
currentName:
stringThe current name of the table. -
newName:
stringThe new name for the table. -
options?:
RenameTableOptionsOptional namespace paths. WhennewNamespacePathis omitted the table stays innamespacePath.
Returns
Promise<void>
resumeJob()
abstract resumeJob(jobId): Promise<string>
Resume a paused server-side job by id.
Its workers pick their work back up from checkpoints. Resolves to "resumed", "still_pausing" -- the pause's worker drain is not confirmed yet; retry shortly -- or "not_paused".
Parameters
- jobId:
string
Returns
Promise<string>
tableNames()
tableNames(options)
abstract tableNames(options?): Promise<string[]>
List all the table names in this database.
Tables will be returned in lexicographical order.
Parameters
- options?:
Partial<TableNamesOptions> options to control the paging / start point (backwards compatibility)
Returns
Promise<string[]>
Deprecated
Use Connection.listTables instead.
tableNames(namespacePath, options)
abstract tableNames(namespacePath?, options?): Promise<string[]>
List all the table names in this database.
Tables will be returned in lexicographical order.
Parameters
-
namespacePath?:
string[] The namespace path to list tables from (defaults to root namespace) -
options?:
Partial<TableNamesOptions> options to control the paging / start point
Returns
Promise<string[]>
Deprecated
Use Connection.listTables instead.