feat(nodejs): add table delta streams (#5149)

Adds the Embedded `Table.delta` API to the Node.js bindings, matching
the Rust/Python contract from #5135. `Table.delta(fromVersion,
toVersion?)` accepts a positive safe-integer number, a positive lossless
u64 `bigint`, or a same-branch tag string. `TableDelta` exposes
`beginVersion`/`endVersion` as `bigint`, streaming `insertedRows()`,
`updatedRows()`, `upsertedRows()`, `deletedRowIds()`, and
`listTransactions()` with `readVersion` as `bigint`.

Readers reuse the existing native Arrow IPC iterator adapter. They are
lazy, single-use, serialize pulls, capture/cache the schema before
polling, and release the native stream on completion, break, or error.
Row readers retain the Rust contract: equal endpoints return empty
streams with schemas, invalid/reversed/missing endpoints and
cross-branch tags are rejected, and Restore or incomplete transaction
history fail closed with full-rescan and range-end checkpoint guidance.
Enterprise tables remain unsupported through the native Rust default.

The abstract `Table` keeps a concrete unsupported `delta` default for
custom subclasses; `LocalTable` overrides it. TypeDoc API docs and
focused Node tests cover pinned targets, typed bigint values,
transaction listing, lazy rejected readers, schema/decode failures,
aliasing, and early drop.

Refs OSS-2860
This commit is contained in:
Xuanwo
2026-11-21 15:43:16 +08:00
committed by GitHub
parent b44807e4db
commit 6a7a2c4ec0
14 changed files with 1160 additions and 6 deletions
+47
View File
@@ -552,6 +552,53 @@ containing the new version number of the table
***
### delta()
```ts
delta(fromVersion, toVersion?): Promise<TableDelta>
```
Compare two persisted versions or same-branch tags on an Embedded table.
`fromVersion` is exclusive and `toVersion` is inclusive. Omitting
`toVersion` uses the version currently visible through this handle,
including a checked-out version. The endpoints are fixed when the delta is
created.
Row readers require stable row IDs at both endpoints. Create the table with
`storageOptions: { new_table_enable_stable_row_ids: "true" }` to enable
them. `listTransactions()` works without stable row IDs.
Row readers reject ranges containing a Restore, or ranges whose transaction
history cannot prove they are restore-free. Recompute the checkpoint with a
full rescan and reinitialize it at the range end version.
LanceDB Enterprise tables reject this operation.
#### Parameters
* **fromVersion**: [`DeltaVersion`](../type-aliases/DeltaVersion.md)
* **toVersion?**: [`DeltaVersion`](../type-aliases/DeltaVersion.md)
#### Returns
`Promise`&lt;[`TableDelta`](TableDelta.md)&gt;
#### Example
```ts
const delta = await table.delta("baseline");
const reader = delta.insertedRows();
console.log((await reader.schema()).fields.map((field) => field.name));
for await (const batch of reader) {
console.log(batch.getChild("id")?.toJSON());
}
console.log(await delta.listTransactions());
```
***
### disableRTE()
```ts
+110
View File
@@ -0,0 +1,110 @@
[**@lancedb/lancedb**](../README.md) • **Docs**
***
[@lancedb/lancedb](../globals.md) / TableDelta
# Class: TableDelta
A handle for reading changes between two pinned table versions.
Created by [Table.delta](Table.md#delta). Endpoints are fixed at creation; later writes
or tag moves do not change this delta.
## Accessors
### beginVersion
```ts
get beginVersion(): bigint
```
The exclusive start version, as an exact u64 bigint.
#### Returns
`bigint`
***
### endVersion
```ts
get endVersion(): bigint
```
The inclusive end version, as an exact u64 bigint.
#### Returns
`bigint`
## Methods
### deletedRowIds()
```ts
deletedRowIds(): TableDeltaReader
```
Stream deleted row IDs. Each batch has one `_rowid: uint64` column.
#### Returns
[`TableDeltaReader`](../interfaces/TableDeltaReader.md)
***
### insertedRows()
```ts
insertedRows(): TableDeltaReader
```
Stream rows inserted in `(beginVersion, endVersion]`.
#### Returns
[`TableDeltaReader`](../interfaces/TableDeltaReader.md)
***
### listTransactions()
```ts
listTransactions(): Promise<TableDeltaTransaction[]>
```
List readable transactions committed in `(beginVersion, endVersion]`.
#### Returns
`Promise`&lt;[`TableDeltaTransaction`](../interfaces/TableDeltaTransaction.md)[]&gt;
***
### updatedRows()
```ts
updatedRows(): TableDeltaReader
```
Stream rows updated in `(beginVersion, endVersion]`.
#### Returns
[`TableDeltaReader`](../interfaces/TableDeltaReader.md)
***
### upsertedRows()
```ts
upsertedRows(): TableDeltaReader
```
Stream inserted and updated rows in `(beginVersion, endVersion]`.
#### Returns
[`TableDeltaReader`](../interfaces/TableDeltaReader.md)
+4
View File
@@ -49,6 +49,7 @@
- [Session](classes/Session.md)
- [StaticHeaderProvider](classes/StaticHeaderProvider.md)
- [Table](classes/Table.md)
- [TableDelta](classes/TableDelta.md)
- [TagContents](classes/TagContents.md)
- [Tags](classes/Tags.md)
- [TakeQuery](classes/TakeQuery.md)
@@ -158,6 +159,8 @@
- [SplitRandomOptions](interfaces/SplitRandomOptions.md)
- [SplitSequentialOptions](interfaces/SplitSequentialOptions.md)
- [SsTableStats](interfaces/SsTableStats.md)
- [TableDeltaReader](interfaces/TableDeltaReader.md)
- [TableDeltaTransaction](interfaces/TableDeltaTransaction.md)
- [TableNamesOptions](interfaces/TableNamesOptions.md)
- [TableShardStats](interfaces/TableShardStats.md)
- [TableStatistics](interfaces/TableStatistics.md)
@@ -189,6 +192,7 @@
- [Data](type-aliases/Data.md)
- [DataLike](type-aliases/DataLike.md)
- [DataTypeLike](type-aliases/DataTypeLike.md)
- [DeltaVersion](type-aliases/DeltaVersion.md)
- [ExprLike](type-aliases/ExprLike.md)
- [FieldLike](type-aliases/FieldLike.md)
- [IntoSql](type-aliases/IntoSql.md)
+109
View File
@@ -0,0 +1,109 @@
[**@lancedb/lancedb**](../README.md) • **Docs**
***
[@lancedb/lancedb](../globals.md) / TableDeltaReader
# Interface: TableDeltaReader
A streaming table-delta reader.
`schema()` is available before consuming the stream, including when the
range is empty. The stream yields Arrow record batches without
materializing the full result.
A reader owns one native cursor. It is single-use:
`[Symbol.asyncIterator]()` returns the same iterator, concurrent pulls are
serialized, and `return()` releases the native stream on early drop.
## Extends
- `AsyncIterable`&lt;`RecordBatch`&gt;.`AsyncIterator`&lt;`RecordBatch`&gt;
## Methods
### \[asyncIterator\]()
```ts
asyncIterator: AsyncIterator<RecordBatch<any>, any, undefined>
```
#### Returns
`AsyncIterator`&lt;`RecordBatch`&lt;`any`&gt;, `any`, `undefined`&gt;
#### Inherited from
`AsyncIterable.[asyncIterator]`
***
### next()
```ts
next(...args): Promise<IteratorResult<RecordBatch<any>, any>>
```
#### Parameters
* ...**args**: [] \| [`undefined`]
#### Returns
`Promise`&lt;`IteratorResult`&lt;`RecordBatch`&lt;`any`&gt;, `any`&gt;&gt;
#### Inherited from
`AsyncIterator.next`
***
### return()?
```ts
optional return(value?): Promise<IteratorResult<RecordBatch<any>, any>>
```
#### Parameters
* **value?**: `any`
#### Returns
`Promise`&lt;`IteratorResult`&lt;`RecordBatch`&lt;`any`&gt;, `any`&gt;&gt;
#### Inherited from
`AsyncIterator.return`
***
### schema()
```ts
schema(): Promise<Schema<any>>
```
#### Returns
`Promise`&lt;`Schema`&lt;`any`&gt;&gt;
***
### throw()?
```ts
optional throw(e?): Promise<IteratorResult<RecordBatch<any>, any>>
```
#### Parameters
* **e?**: `any`
#### Returns
`Promise`&lt;`IteratorResult`&lt;`RecordBatch`&lt;`any`&gt;, `any`&gt;&gt;
#### Inherited from
`AsyncIterator.throw`
@@ -0,0 +1,51 @@
[**@lancedb/lancedb**](../README.md) • **Docs**
***
[@lancedb/lancedb](../globals.md) / TableDeltaTransaction
# Interface: TableDeltaTransaction
A committed transaction in a table delta range.
## Properties
### operation
```ts
operation: string;
```
***
### readVersion
```ts
readVersion: bigint;
```
The version the transaction was based on. Exact u64 value.
***
### tag?
```ts
optional tag: string;
```
***
### transactionProperties?
```ts
optional transactionProperties: Record<string, string>;
```
***
### uuid
```ts
uuid: string;
```
+17
View File
@@ -0,0 +1,17 @@
[**@lancedb/lancedb**](../README.md) • **Docs**
***
[@lancedb/lancedb](../globals.md) / DeltaVersion
# Type Alias: DeltaVersion
```ts
type DeltaVersion: number | bigint | string;
```
One endpoint of a table delta: a positive version number/bigint or a tag on
the table handle's current branch.
Use a `bigint` when the version may exceed `Number.MAX_SAFE_INTEGER`.
Strings are always tags.
+64
View File
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
import type { Connection } from "@lancedb/lancedb";
/**
* Draft checkpoint-delta example for the Versioning guide.
*
* This file is snippet source only. The published documentation test package is
* pinned to an older npm release, so it is not part of the Jest test glob.
*/
export async function versioningCheckpointDeltaExample(
db: Connection,
): Promise<void> {
// --8<-- [start:versioning_checkpoint_delta]
const table = await db.createTable(
"checkpoint_delta_example",
[
{ id: 1, author: "Richard", quote: "Wubba Lubba Dub Dub!" },
{ id: 2, author: "Morty", quote: "Rick, what's going on?" },
],
{
mode: "overwrite",
storageOptions: { new_table_enable_stable_row_ids: "true" },
},
);
const tags = await table.tags();
await tags.create("baseline", await table.version());
await table.add([
{ id: 3, author: "Summer", quote: "Whatever, Grandpa" },
]);
await table.update({
where: "id = 2",
values: { quote: "Aww geez, Rick!" },
});
await table.delete("id = 1");
const delta = await table.delta("baseline");
console.log(delta.beginVersion, delta.endVersion);
const inserted = delta.insertedRows();
console.log((await inserted.schema()).fields.map((field) => field.name));
for await (const batch of inserted) {
console.log("inserted:", batch.getChild("id")?.toJSON());
}
const updated = delta.updatedRows();
for await (const batch of updated) {
console.log("updated:", batch.getChild("id")?.toJSON());
}
const deleted = delta.deletedRowIds();
for await (const batch of deleted) {
console.log("deleted row ids:", batch.getChild("_rowid")?.toJSON());
}
console.log(
"transactions:",
(await delta.listTransactions()).map(
(transaction) => transaction.operation,
),
);
// --8<-- [end:versioning_checkpoint_delta]
}
+10 -4
View File
@@ -89,6 +89,7 @@ import {
} from '/snippets/tables.mdx';
import {
PyVersioningCheckpointDelta as VersioningCheckpointDelta,
TsVersioningCheckpointDelta as TsVersioningCheckpointDelta,
RsVersioningCheckpointDelta as RsVersioningCheckpointDelta,
} from '/snippets/table_delta_docs.mdx';
import {
@@ -1786,10 +1787,11 @@ with stable row IDs enabled, as shown below. If a table does not have them, the
row-level readers explain how to recreate it with the option. `list_transactions()`
reports the transactions in the range and works without stable row IDs.
This preview supports Python and Rust for LanceDB Embedded. TypeScript support
is a follow-up. The API accepts versions and tags on the current branch only,
and rejects tags that belong to another branch. LanceDB Enterprise tables do
not support row-level deltas.
This preview supports Python, TypeScript, and Rust for LanceDB Embedded. The
API accepts versions and tags on the current branch only, and rejects tags that
belong to another branch. TypeScript exposes endpoint and transaction
`readVersion` values as `bigint`, and reader schemas are available before
streaming. LanceDB Enterprise tables do not support row-level deltas.
A `Restore` can reintroduce rows with older row-version metadata that the delta
readers do not report as changed. For that reason, the row-level readers reject
@@ -1804,6 +1806,10 @@ range. Branch-vs-main summaries remain a separate `branches.diff()` API.
{VersioningCheckpointDelta}
</CodeBlock>
<CodeBlock filename="TypeScript" language="TypeScript" icon="square-js">
{TsVersioningCheckpointDelta}
</CodeBlock>
<CodeBlock filename="Rust" language="Rust" icon="rust">
{RsVersioningCheckpointDelta}
</CodeBlock>
+2
View File
@@ -2,4 +2,6 @@
export const PyVersioningCheckpointDelta = "table = db.create_table(\n \"checkpoint_delta_example\",\n [\n {\"id\": 1, \"author\": \"Richard\", \"quote\": \"Wubba Lubba Dub Dub!\"},\n {\"id\": 2, \"author\": \"Morty\", \"quote\": \"Rick, what's going on?\"},\n ],\n storage_options={\"new_table_enable_stable_row_ids\": \"true\"},\n mode=\"overwrite\",\n)\ntable.tags.create(\"baseline\", table.version)\ntable.add([{\"id\": 3, \"author\": \"Summer\", \"quote\": \"Whatever, Grandpa\"}])\ntable.update(where=\"id = 2\", values={\"quote\": \"Aww geez, Rick!\"})\ntable.delete(\"id = 1\")\n\ndelta = table.delta(\"baseline\")\nprint(\"inserted:\", delta.inserted_rows().read_all()[\"id\"].to_pylist())\nprint(\"updated:\", delta.updated_rows().read_all()[\"id\"].to_pylist())\nprint(\"deleted:\", delta.deleted_row_ids().read_all()[\"_rowid\"].to_pylist())\nprint(\n \"transactions:\",\n [transaction[\"operation\"] for transaction in delta.list_transactions()],\n)\n";
export const TsVersioningCheckpointDelta = "const table = await db.createTable(\n \"checkpoint_delta_example\",\n [\n { id: 1, author: \"Richard\", quote: \"Wubba Lubba Dub Dub!\" },\n { id: 2, author: \"Morty\", quote: \"Rick, what's going on?\" },\n ],\n {\n mode: \"overwrite\",\n storageOptions: { new_table_enable_stable_row_ids: \"true\" },\n },\n);\nconst tags = await table.tags();\nawait tags.create(\"baseline\", await table.version());\nawait table.add([\n { id: 3, author: \"Summer\", quote: \"Whatever, Grandpa\" },\n]);\nawait table.update({\n where: \"id = 2\",\n values: { quote: \"Aww geez, Rick!\" },\n});\nawait table.delete(\"id = 1\");\n\nconst delta = await table.delta(\"baseline\");\nconsole.log(delta.beginVersion, delta.endVersion);\n\nconst inserted = delta.insertedRows();\nconsole.log((await inserted.schema()).fields.map((field) => field.name));\nfor await (const batch of inserted) {\n console.log(\"inserted:\", batch.getChild(\"id\")?.toJSON());\n}\n\nconst updated = delta.updatedRows();\nfor await (const batch of updated) {\n console.log(\"updated:\", batch.getChild(\"id\")?.toJSON());\n}\n\nconst deleted = delta.deletedRowIds();\nfor await (const batch of deleted) {\n console.log(\"deleted row ids:\", batch.getChild(\"_rowid\")?.toJSON());\n}\n\nconsole.log(\n \"transactions:\",\n (await delta.listTransactions()).map(\n (transaction) => transaction.operation,\n ),\n);\n";
export const RsVersioningCheckpointDelta = "use futures::TryStreamExt;\n\nlet table = db\n .create_table(\n \"checkpoint_delta_example\",\n make_quotes_reader(vec![\n (1, \"Richard\", \"Wubba Lubba Dub Dub!\"),\n (2, \"Morty\", \"Rick, what's going on?\"),\n ]),\n )\n .storage_option(\"new_table_enable_stable_row_ids\", \"true\")\n .execute()\n .await?;\n\nlet mut tags = table.tags().await?;\ntags.create(\"baseline\", table.version().await?).await?;\ntable\n .add(make_quotes_reader(vec![(3, \"Summer\", \"Whatever, Grandpa\")]))\n .execute()\n .await?;\ntable\n .update()\n .only_if(\"id = 2\")\n .column(\"quote\", \"'Aww geez, Rick!'\")\n .execute()\n .await?;\ntable.delete(\"id = 1\").await?;\n\nlet delta = table.delta(\"baseline\", None).await?;\nlet mut inserted = delta.inserted_rows().await?;\nwhile let Some(batch) = inserted.try_next().await? {\n println!(\"inserted: {:?}\", batch.column_by_name(\"id\"));\n}\nlet mut deleted = delta.deleted_row_ids().await?;\nwhile let Some(batch) = deleted.try_next().await? {\n println!(\"deleted row ids: {batch:?}\");\n}\nfor transaction in delta.list_transactions().await? {\n println!(\"{}\", transaction.operation.name());\n}\n";