@lancedb/lancedb 0.42.0-beta.20 → 0.42.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sql.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { type RecordBatchLike, type TableLike } from "./arrow";
2
+ /** Scalar SQL values. Use a one-row Arrow table for explicit Arrow types. */
3
+ export type QueryParameterValue = string | number | bigint | boolean | Date | Uint8Array | null;
4
+ /** Values for `$1`/`$name` placeholders, sent separately from SQL text.
5
+ * Arrays bind by position; objects bind by name. Arrow columns bind both ways.
6
+ * Safe integers and bigint use Int64; fractional numbers use Float64.
7
+ * Arrow input preserves explicit types.
8
+ */
9
+ export type QueryParameters = readonly QueryParameterValue[] | Readonly<Record<string, QueryParameterValue>> | TableLike | RecordBatchLike;
10
+ /** @internal */
11
+ export declare function toParameterBuffer(parameters: QueryParameters): Promise<Buffer>;
package/dist/sql.js ADDED
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: Copyright The LanceDB Authors
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.toParameterBuffer = toParameterBuffer;
6
+ const arrow_1 = require("./arrow");
7
+ const sanitize_1 = require("./sanitize");
8
+ /** @internal */
9
+ async function toParameterBuffer(parameters) {
10
+ let table;
11
+ if ("schema" in parameters &&
12
+ parameters.schema !== null &&
13
+ typeof parameters.schema === "object" &&
14
+ "fields" in parameters.schema) {
15
+ const arrow = parameters;
16
+ table = (0, sanitize_1.sanitizeTable)("batches" in arrow ? arrow : { schema: arrow.schema, batches: [arrow] });
17
+ }
18
+ else {
19
+ const entries = Array.isArray(parameters)
20
+ ? parameters.map((value, index) => [String(index + 1), value])
21
+ : Object.entries(parameters);
22
+ const columns = Object.fromEntries(entries.map(([name, input]) => {
23
+ let value = input;
24
+ let type;
25
+ if (value === null)
26
+ type = new arrow_1.Null();
27
+ else if (typeof value === "string")
28
+ type = new arrow_1.Utf8();
29
+ else if (typeof value === "boolean")
30
+ type = new arrow_1.Bool();
31
+ else if (typeof value === "number") {
32
+ if (!Number.isFinite(value) ||
33
+ (Number.isInteger(value) && !Number.isSafeInteger(value))) {
34
+ throw new Error("Numeric parameters must be finite and integers must be safe; use bigint for Int64");
35
+ }
36
+ type = Number.isInteger(value) ? new arrow_1.Int64() : new arrow_1.Float64();
37
+ if (Number.isInteger(value))
38
+ value = BigInt(value);
39
+ }
40
+ else if (typeof value === "bigint") {
41
+ if (value < -(1n << 63n) || value >= 1n << 63n) {
42
+ throw new Error("bigint parameters must fit Int64");
43
+ }
44
+ type = new arrow_1.Int64();
45
+ }
46
+ else if (value instanceof Date && Number.isFinite(value.getTime())) {
47
+ type = new arrow_1.TimestampMillisecond();
48
+ }
49
+ else if (value instanceof Uint8Array)
50
+ type = new arrow_1.Binary();
51
+ else
52
+ throw new Error("Query parameters must be scalar values or a one-row Arrow table");
53
+ return [name, (0, arrow_1.vectorFromArray)([value], type)];
54
+ }));
55
+ table = new arrow_1.Table(columns);
56
+ }
57
+ if (table.numRows !== 1) {
58
+ throw new Error(`Query parameters must contain exactly one row, got ${table.numRows}`);
59
+ }
60
+ return Buffer.from(await arrow_1.RecordBatchFileWriter.writeAll(table).toUint8Array());
61
+ }
package/dist/table.d.ts CHANGED
@@ -1,12 +1,14 @@
1
+ import { CleanupOptions, CleanupPlan, CleanupResult } from "./cleanup";
1
2
  import { CompactionResult } from "./compaction";
2
- import { PrewarmDataResult } from "./prewarm";
3
- import { Table as ArrowTable, Data, DataType, Field, IntoVector, MultiVector, Schema } from "./arrow";
3
+ import { PrewarmDataPlan, PrewarmDataResult } from "./prewarm";
4
+ import { Table as ArrowTable, Data, DataType, Field, IntoVector, MultiVector, RecordBatch, Schema } from "./arrow";
4
5
  import { BlobFile, BlobRangeRequest, BlobReadOptions } from "./blob";
5
6
  import { IndexOptions } from "./indices";
6
7
  import { Job } from "./job";
7
8
  import { MergeInsertBuilder } from "./merge";
8
- import { AddColumnsResult, AddColumnsSql, AddResult, AlterColumnsResult, BranchContents, DeleteResult, DropColumnsResult, FunctionErrors, FunctionErrorsOptions, IndexConfig, IndexStatistics, JobFailureInfo, Branches as NativeBranches, OptimizeStats, RTEStats, RefreshColumnOptions, RefreshColumnResult, RefreshMaterializedViewResult, TableStatistics, Tags, UpdateFieldMetadataResult, UpdateResult, Table as _NativeTable } from "./native";
9
+ import { AddColumnsResult, AddColumnsSql, AddResult, AlterColumnsResult, BranchContents, DeleteResult, DropColumnsResult, FunctionErrors, FunctionErrorsOptions, IndexConfig, IndexStatistics, JobFailureInfo, Branches as NativeBranches, TableDelta as NativeTableDelta, OptimizeStats, RTEStats, RefreshColumnOptions, RefreshColumnResult, RefreshMaterializedViewResult, TableStatistics, Tags, UpdateFieldMetadataResult, UpdateResult, Table as _NativeTable } from "./native";
9
10
  import { AutoQuery, FullTextQuery, Query, TakeQuery, VectorQuery } from "./query";
11
+ import { QueryParameters } from "./sql";
10
12
  import { IntoSql } from "./util";
11
13
  export { IndexConfig } from "./native";
12
14
  export { TableShardStats, SsTableStats, RTEStats, MemtableStats, } from "./native";
@@ -97,12 +99,14 @@ export interface UpdateOptions {
97
99
  */
98
100
  where: string;
99
101
  }
100
- /** Settings for submitting a durable remote data-cache prewarm job. */
102
+ /** Settings for data-cache prewarm submissions and metadata previews. */
101
103
  export interface PrewarmDataOptions {
102
104
  /** Lance field paths to warm; omitted or empty means every column. */
103
105
  columns?: string[];
104
106
  /** A single SQL predicate for conservative metadata pruning. */
105
107
  filter?: string;
108
+ /** Typed positional or named filter values, sent separately from SQL. */
109
+ parameters?: QueryParameters;
106
110
  /** Positive per-executor concurrency, at most 4294967295. */
107
111
  concurrency?: number;
108
112
  }
@@ -162,6 +166,37 @@ export interface Version {
162
166
  timestamp: Date;
163
167
  metadata: Record<string, string>;
164
168
  }
169
+ /**
170
+ * One endpoint of a table delta: a positive version number/bigint or a tag on
171
+ * the table handle's current branch.
172
+ *
173
+ * Use a `bigint` when the version may exceed `Number.MAX_SAFE_INTEGER`.
174
+ * Strings are always tags.
175
+ */
176
+ export type DeltaVersion = number | bigint | string;
177
+ /** A committed transaction in a table delta range. */
178
+ export interface TableDeltaTransaction {
179
+ /** The version the transaction was based on. Exact u64 value. */
180
+ readVersion: bigint;
181
+ uuid: string;
182
+ operation: string;
183
+ tag?: string;
184
+ transactionProperties?: Record<string, string>;
185
+ }
186
+ /**
187
+ * A streaming table-delta reader.
188
+ *
189
+ * `schema()` is available before consuming the stream, including when the
190
+ * range is empty. The stream yields Arrow record batches without
191
+ * materializing the full result.
192
+ *
193
+ * A reader owns one native cursor. It is single-use:
194
+ * `[Symbol.asyncIterator]()` returns the same iterator, concurrent pulls are
195
+ * serialized, and `return()` releases the native stream on early drop.
196
+ */
197
+ export interface TableDeltaReader extends AsyncIterable<RecordBatch>, AsyncIterator<RecordBatch> {
198
+ schema(): Promise<Schema>;
199
+ }
165
200
  /** Token produced by the tokenizer configured on a full-text search index. */
166
201
  export interface FtsToken {
167
202
  /** Token text after tokenizer filters have been applied. */
@@ -491,11 +526,29 @@ export declare abstract class Table {
491
526
  *
492
527
  * @example
493
528
  * const job = await table.prewarmDataAsync({
494
- * columns: ["video"], filter: "quality > 0.7", concurrency: 4,
529
+ * columns: ["video"], filter: "quality > $minimum",
530
+ * parameters: { minimum: 0.7 }, concurrency: 4,
495
531
  * });
496
532
  * await job.wait();
497
533
  */
498
534
  abstract prewarmDataAsync(options?: PrewarmDataOptions): Promise<Job<PrewarmDataResult>>;
535
+ /**
536
+ * Preview prewarm with the same options as {@link prewarmDataAsync}, without
537
+ * submitting a warming job. Requires LanceDB Enterprise with structured SQL
538
+ * previews, table Select and database/namespace Usage. Reads metadata and
539
+ * returns the source version, readable plan, and conservative pruning summary.
540
+ * A later submission plans its own snapshot. Historical and Embedded handles
541
+ * are unsupported. Unknown measurements remain null.
542
+ * Custom table implementations can override this method; its default rejects
543
+ * with an unsupported-operation error.
544
+ *
545
+ * @example
546
+ * const plan = await table.explainPrewarmData({
547
+ * columns: ["video"], filter: "quality > $minimum", parameters: {minimum: 0.7},
548
+ * });
549
+ * console.log(plan.pruning.selectedFragments);
550
+ */
551
+ explainPrewarmData(_options?: PrewarmDataOptions): Promise<PrewarmDataPlan>;
499
552
  /**
500
553
  * Waits for asynchronous indexing to complete on the table.
501
554
  *
@@ -912,6 +965,45 @@ export declare abstract class Table {
912
965
  * @returns {Promise<RTEWriteSpec | undefined>}
913
966
  */
914
967
  abstract getRTESpec(): Promise<RTEWriteSpec | undefined>;
968
+ /**
969
+ * Read the stored overrides for a remote Enterprise table.
970
+ *
971
+ * Overrides configure background behavior such as automatic compaction,
972
+ * cleanup, and reindex execution. Keys use the server's snake_case names.
973
+ * Returns an empty object when no overrides are set. Local tables are unsupported.
974
+ * Custom table implementations inherit a default rejection unless they override
975
+ * this method.
976
+ */
977
+ getTableOverrides(): Promise<Record<string, unknown>>;
978
+ /**
979
+ * Recursively merge overrides into a remote Enterprise table's stored overrides.
980
+ *
981
+ * Fetches the current overrides, merges nested objects locally, then sends the
982
+ * complete replacement using REST PUT. Other values replace existing values;
983
+ * unrelated fields from the read snapshot are preserved. This read-modify-write
984
+ * is not atomic: concurrent edits can be overwritten, even to unrelated fields.
985
+ * Coordinate writers when concurrent edits must be preserved. An empty update
986
+ * only reads and returns the current overrides.
987
+ *
988
+ * Unlike this SDK method, CLI `set` and REST PUT replace the overrides object
989
+ * without merging. Use {@link Table.resetTableOverrides} to clear all overrides.
990
+ * Local tables and custom table implementations without override support reject
991
+ * this operation.
992
+ *
993
+ * @example
994
+ * ```ts
995
+ * await table.updateTableOverrides({
996
+ * job_types: { compaction: { enabled: false } },
997
+ * });
998
+ * ```
999
+ */
1000
+ updateTableOverrides(overrides: Record<string, unknown>): Promise<Record<string, unknown>>;
1001
+ /**
1002
+ * Clear a remote Enterprise table's overrides and return an empty object.
1003
+ * Local tables and custom table implementations without override support reject
1004
+ * this operation.
1005
+ */
1006
+ resetTableOverrides(): Promise<Record<string, unknown>>;
915
1007
  /**
916
1008
  * Drain and close any cached RTE shard writers held for this table.
917
1009
  *
@@ -1055,6 +1147,50 @@ export declare abstract class Table {
1055
1147
  * out state and the read_consistency_interval, if any, will apply.
1056
1148
  */
1057
1149
  abstract restore(): Promise<void>;
1150
+ /**
1151
+ * Compare two persisted versions or same-branch tags on an Embedded table.
1152
+ *
1153
+ * `fromVersion` is exclusive and `toVersion` is inclusive. Omitting
1154
+ * `toVersion` uses the version currently visible through this handle,
1155
+ * including a checked-out version. The endpoints are fixed when the delta is
1156
+ * created.
1157
+ *
1158
+ * Row readers require stable row IDs at both endpoints. Create the table with
1159
+ * `storageOptions: { new_table_enable_stable_row_ids: "true" }` to enable
1160
+ * them. `listTransactions()` works without stable row IDs.
1161
+ *
1162
+ * Row readers reject ranges containing a Restore, or ranges whose transaction
1163
+ * history cannot prove they are restore-free. Recompute the checkpoint with a
1164
+ * full rescan and reinitialize it at the range end version.
1165
+ *
1166
+ * LanceDB Enterprise tables reject this operation.
1167
+ *
1168
+ * @example
1169
+ * const delta = await table.delta("baseline");
1170
+ * const reader = delta.insertedRows();
1171
+ * console.log((await reader.schema()).fields.map((field) => field.name));
1172
+ * for await (const batch of reader) {
1173
+ * console.log(batch.getChild("id")?.toJSON());
1174
+ * }
1175
+ * console.log(await delta.listTransactions());
1176
+ */
1177
+ delta(fromVersion: DeltaVersion, toVersion?: DeltaVersion): Promise<TableDelta>;
1178
+ /**
1179
+ * Submit durable remote cleanup through SQL VACUUM and return after acceptance.
1180
+ * Requires table Ownership and parent Usage. Retention inherits from the table
1181
+ * then deployment when omitted. Local/historical handles are unsupported.
1182
+ * Before submission, disable/drain automatic cleanup and prevent other cleanup,
1183
+ * tag/branch publication and restore until completion, including direct clients.
1184
+ * Coordination is not enforced by the server. Cancellation cannot undo deletion
1185
+ * or prove storage I/O stopped. Preview is available without deletion.
1186
+ * Wait timeout leaves work running; save the ID and reopen with db.openJob().
1187
+ * @example
1188
+ * const job = await table.cleanupAsync({ minAgeSeconds: 604800 });
1189
+ * const result = await job.wait({ timeoutMs: 600000 });
1190
+ */
1191
+ cleanupAsync(_options?: CleanupOptions): Promise<Job<CleanupResult>>;
1192
+ /** Preview version deletion without creating a job. Execution re-evaluates current state. */
1193
+ explainCleanup(_options?: CleanupOptions): Promise<CleanupPlan>;
1058
1194
  /**
1059
1195
  * Submit remote compaction and return its durable job after acceptance.
1060
1196
  *
@@ -1199,6 +1335,7 @@ export declare class LocalTable extends Table {
1199
1335
  prewarmData(options?: PrewarmDataOptions): Promise<void>;
1200
1336
  prewarmData(columns?: string[]): Promise<void>;
1201
1337
  prewarmDataAsync(options?: PrewarmDataOptions): Promise<Job<PrewarmDataResult>>;
1338
+ explainPrewarmData(options?: PrewarmDataOptions): Promise<PrewarmDataPlan>;
1202
1339
  waitForIndex(indexNames: string[], timeoutSeconds: number): Promise<void>;
1203
1340
  takeOffsets(offsets: number[]): TakeQuery;
1204
1341
  takeRowIds(rowIds: readonly (bigint | number)[]): TakeQuery;
@@ -1227,6 +1364,9 @@ export declare class LocalTable extends Table {
1227
1364
  enableRTE(spec: RTEWriteSpec): Promise<void>;
1228
1365
  disableRTE(): Promise<void>;
1229
1366
  getRTESpec(): Promise<RTEWriteSpec | undefined>;
1367
+ getTableOverrides(): Promise<Record<string, unknown>>;
1368
+ updateTableOverrides(overrides: Record<string, unknown>): Promise<Record<string, unknown>>;
1369
+ resetTableOverrides(): Promise<Record<string, unknown>>;
1230
1370
  closeRTEWriters(): Promise<void>;
1231
1371
  flushRTE(): Promise<void>;
1232
1372
  compactRTE(): Promise<void>;
@@ -1235,12 +1375,15 @@ export declare class LocalTable extends Table {
1235
1375
  version(): Promise<number>;
1236
1376
  checkout(version: number | string): Promise<void>;
1237
1377
  checkoutLatest(): Promise<void>;
1378
+ delta(fromVersion: DeltaVersion, toVersion?: DeltaVersion): Promise<TableDelta>;
1238
1379
  listVersions(): Promise<Version[]>;
1239
1380
  restore(): Promise<void>;
1240
1381
  tags(): Promise<Tags>;
1241
1382
  branches(): Promise<Branches>;
1242
1383
  currentBranch(): string | null;
1243
1384
  compactAsync(options?: CompactionOptions): Promise<Job<CompactionResult>>;
1385
+ cleanupAsync(options?: CleanupOptions): Promise<Job<CleanupResult>>;
1386
+ explainCleanup(options?: CleanupOptions): Promise<CleanupPlan>;
1244
1387
  optimize(options?: Partial<OptimizeOptions>): Promise<OptimizeStats>;
1245
1388
  listIndices(): Promise<IndexConfig[]>;
1246
1389
  tokenize(query: string, options: TokenizeTableOptions): Promise<FtsToken[]>;
@@ -1383,6 +1526,44 @@ export interface CherryPickResult {
1383
1526
  preview: CherryPickPreview;
1384
1527
  mainVersionAfter?: number;
1385
1528
  }
1529
+ /**
1530
+ * Options for creating a branch from a named source.
1531
+ */
1532
+ export interface CreateBranchOptions {
1533
+ /**
1534
+ * Tag to fork from. The tag keeps the branch and version it points to.
1535
+ * Cannot be combined with `fromRef` or `fromVersion`.
1536
+ */
1537
+ fromTag: string;
1538
+ }
1539
+ /**
1540
+ * A handle for reading changes between two pinned table versions.
1541
+ *
1542
+ * Created by {@link Table.delta}. Endpoints are fixed at creation; later writes
1543
+ * or tag moves do not change this delta.
1544
+ */
1545
+ export declare class TableDelta {
1546
+ #private;
1547
+ /**
1548
+ * Construct a table-delta handle. Internal use only.
1549
+ * @hidden
1550
+ */
1551
+ constructor(inner: NativeTableDelta);
1552
+ /** The exclusive start version, as an exact u64 bigint. */
1553
+ get beginVersion(): bigint;
1554
+ /** The inclusive end version, as an exact u64 bigint. */
1555
+ get endVersion(): bigint;
1556
+ /** Stream rows inserted in `(beginVersion, endVersion]`. */
1557
+ insertedRows(): TableDeltaReader;
1558
+ /** Stream rows updated in `(beginVersion, endVersion]`. */
1559
+ updatedRows(): TableDeltaReader;
1560
+ /** Stream inserted and updated rows in `(beginVersion, endVersion]`. */
1561
+ upsertedRows(): TableDeltaReader;
1562
+ /** Stream deleted row IDs. Each batch has one `_rowid: uint64` column. */
1563
+ deletedRowIds(): TableDeltaReader;
1564
+ /** List readable transactions committed in `(beginVersion, endVersion]`. */
1565
+ listTransactions(): Promise<TableDeltaTransaction[]>;
1566
+ }
1386
1567
  /**
1387
1568
  * Branch manager for a {@link Table}.
1388
1569
  *
@@ -1398,6 +1579,18 @@ export declare class Branches {
1398
1579
  constructor(inner: NativeBranches);
1399
1580
  /** List all branches, mapping name to branch metadata. */
1400
1581
  list(): Promise<Record<string, BranchContents>>;
1582
+ /**
1583
+ * Create a branch from a tag and return a handle scoped to it.
1584
+ *
1585
+ * @param name Name of the new branch.
1586
+ * @param options Named source. `fromTag` keeps the tag's branch and version.
1587
+ * @example
1588
+ * ```typescript
1589
+ * const branches = await table.branches();
1590
+ * const branch = await branches.create("exp", { fromTag: "baseline" });
1591
+ * ```
1592
+ */
1593
+ create(name: string, options: CreateBranchOptions): Promise<Table>;
1401
1594
  /**
1402
1595
  * Create a branch and return a handle scoped to it.
1403
1596
  *