fix(nodejs): harden table delta reader lifecycle

Make delta readers lazy, single-use, and serialized. Capture schema before polling, cache it for empty and completed streams, and release the native iterator on completion, break, and error. Cover unused rejected readers and early-drop/alias behavior.
This commit is contained in:
Xuanwo
2026-11-21 07:03:26 +00:00
parent 16ba9b5c2b
commit 156bc8ea1b
3 changed files with 272 additions and 13 deletions
+65 -1
View File
@@ -12,9 +12,13 @@ A streaming table-delta reader.
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`<`RecordBatch`>
- `AsyncIterable`<`RecordBatch`>.`AsyncIterator`<`RecordBatch`>
## Methods
@@ -34,6 +38,46 @@ asyncIterator: AsyncIterator<RecordBatch<any>, any, undefined>
***
### 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
@@ -43,3 +87,23 @@ 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`