@databricks/zerobus-ingest-sdk 1.1.0 → 1.3.0
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/Cargo.lock +82 -97
- package/Cargo.toml +6 -13
- package/README.md +150 -205
- package/index.d.ts +355 -41
- package/index.js +4 -1
- package/package.json +28 -13
- package/src/headers_provider.ts +24 -36
- package/src/lib.rs +119 -82
- package/utils/descriptor.d.ts +32 -0
- package/utils/descriptor.js +55 -0
- package/utils/descriptor.ts +2 -2
package/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export const enum RecordType {
|
|
|
22
22
|
export interface StreamConfigurationOptions {
|
|
23
23
|
/**
|
|
24
24
|
* Maximum number of unacknowledged requests that can be in flight.
|
|
25
|
-
* Default:
|
|
25
|
+
* Default: 1,000,000
|
|
26
26
|
*/
|
|
27
27
|
maxInflightRequests?: number
|
|
28
28
|
/**
|
|
@@ -83,7 +83,8 @@ export interface TableProperties {
|
|
|
83
83
|
tableName: string
|
|
84
84
|
/**
|
|
85
85
|
* Optional Protocol Buffer descriptor as a base64-encoded string.
|
|
86
|
-
*
|
|
86
|
+
* Omitting this does not select JSON. The stream defaults to Protocol Buffers
|
|
87
|
+
* unless `record_type` is set to JSON.
|
|
87
88
|
*/
|
|
88
89
|
descriptorProto?: string
|
|
89
90
|
}
|
|
@@ -91,12 +92,143 @@ export interface TableProperties {
|
|
|
91
92
|
* JavaScript headers provider callback wrapper.
|
|
92
93
|
*
|
|
93
94
|
* Allows TypeScript code to provide custom authentication headers
|
|
94
|
-
* by implementing a
|
|
95
|
+
* by implementing a getHeadersCallback() function.
|
|
95
96
|
*/
|
|
96
97
|
export interface JsHeadersProvider {
|
|
97
|
-
/** JavaScript function: () =>
|
|
98
|
+
/** JavaScript function: () => Array<[string, string]> */
|
|
98
99
|
getHeadersCallback: (...args: any[]) => any
|
|
99
100
|
}
|
|
101
|
+
export interface ZerobusSdkOptions {
|
|
102
|
+
/** Identifier appended to the `user-agent` header */
|
|
103
|
+
applicationName?: string
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* IPC compression type for Arrow Flight streams.
|
|
107
|
+
*
|
|
108
|
+
*/
|
|
109
|
+
export const enum IpcCompressionType {
|
|
110
|
+
/** LZ4 frame compression - fast compression with moderate ratio */
|
|
111
|
+
Lz4Frame = 0,
|
|
112
|
+
/** Zstandard compression - better compression ratio, slightly slower */
|
|
113
|
+
Zstd = 1
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Configuration options for Arrow Flight streams.
|
|
117
|
+
*
|
|
118
|
+
*/
|
|
119
|
+
export interface ArrowStreamConfigurationOptions {
|
|
120
|
+
/**
|
|
121
|
+
* Maximum number of batches that can be in-flight (sent but not acknowledged).
|
|
122
|
+
* Default: 1,000
|
|
123
|
+
*/
|
|
124
|
+
maxInflightBatches?: number
|
|
125
|
+
/**
|
|
126
|
+
* Whether to enable automatic stream recovery on failure.
|
|
127
|
+
* Default: true
|
|
128
|
+
*/
|
|
129
|
+
recovery?: boolean
|
|
130
|
+
/**
|
|
131
|
+
* Timeout for recovery operations in milliseconds.
|
|
132
|
+
* Default: 15,000 (15 seconds)
|
|
133
|
+
*/
|
|
134
|
+
recoveryTimeoutMs?: number
|
|
135
|
+
/**
|
|
136
|
+
* Delay between recovery retry attempts in milliseconds.
|
|
137
|
+
* Default: 2,000 (2 seconds)
|
|
138
|
+
*/
|
|
139
|
+
recoveryBackoffMs?: number
|
|
140
|
+
/**
|
|
141
|
+
* Maximum number of recovery attempts before giving up.
|
|
142
|
+
* Default: 4
|
|
143
|
+
*/
|
|
144
|
+
recoveryRetries?: number
|
|
145
|
+
/**
|
|
146
|
+
* Timeout waiting for server acknowledgments in milliseconds.
|
|
147
|
+
* Default: 60,000 (1 minute)
|
|
148
|
+
*/
|
|
149
|
+
serverLackOfAckTimeoutMs?: number
|
|
150
|
+
/**
|
|
151
|
+
* Timeout for flush operations in milliseconds.
|
|
152
|
+
* Default: 300,000 (5 minutes)
|
|
153
|
+
*/
|
|
154
|
+
flushTimeoutMs?: number
|
|
155
|
+
/**
|
|
156
|
+
* Timeout for connection establishment in milliseconds.
|
|
157
|
+
* Default: 30,000 (30 seconds)
|
|
158
|
+
*/
|
|
159
|
+
connectionTimeoutMs?: number
|
|
160
|
+
/** Optional IPC compression type (0 = LZ4Frame, 1 = Zstd, undefined = no compression) */
|
|
161
|
+
ipcCompression?: number
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Arrow data type enum for schema definition.
|
|
165
|
+
*
|
|
166
|
+
*/
|
|
167
|
+
export const enum ArrowDataType {
|
|
168
|
+
/** Boolean type */
|
|
169
|
+
Boolean = 0,
|
|
170
|
+
/** Signed 8-bit integer */
|
|
171
|
+
Int8 = 1,
|
|
172
|
+
/** Signed 16-bit integer */
|
|
173
|
+
Int16 = 2,
|
|
174
|
+
/** Signed 32-bit integer */
|
|
175
|
+
Int32 = 3,
|
|
176
|
+
/** Signed 64-bit integer */
|
|
177
|
+
Int64 = 4,
|
|
178
|
+
/** Unsigned 8-bit integer */
|
|
179
|
+
UInt8 = 5,
|
|
180
|
+
/** Unsigned 16-bit integer */
|
|
181
|
+
UInt16 = 6,
|
|
182
|
+
/** Unsigned 32-bit integer */
|
|
183
|
+
UInt32 = 7,
|
|
184
|
+
/** Unsigned 64-bit integer */
|
|
185
|
+
UInt64 = 8,
|
|
186
|
+
/** 32-bit floating point */
|
|
187
|
+
Float32 = 9,
|
|
188
|
+
/** 64-bit floating point */
|
|
189
|
+
Float64 = 10,
|
|
190
|
+
/** UTF-8 encoded string */
|
|
191
|
+
Utf8 = 11,
|
|
192
|
+
/** Large UTF-8 encoded string (64-bit offsets) */
|
|
193
|
+
LargeUtf8 = 12,
|
|
194
|
+
/** Binary data */
|
|
195
|
+
Binary = 13,
|
|
196
|
+
/** Large binary data (64-bit offsets) */
|
|
197
|
+
LargeBinary = 14,
|
|
198
|
+
/** Date (32-bit days since epoch) */
|
|
199
|
+
Date32 = 15,
|
|
200
|
+
/** Date (64-bit milliseconds since epoch) */
|
|
201
|
+
Date64 = 16,
|
|
202
|
+
/** Timestamp with microsecond precision (UTC) */
|
|
203
|
+
TimestampMicros = 17,
|
|
204
|
+
/** Timestamp with nanosecond precision (UTC) */
|
|
205
|
+
TimestampNanos = 18
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Arrow field definition for schema.
|
|
209
|
+
*
|
|
210
|
+
*/
|
|
211
|
+
export interface ArrowField {
|
|
212
|
+
/** Field name */
|
|
213
|
+
name: string
|
|
214
|
+
/** Field data type (ArrowDataType enum value) */
|
|
215
|
+
dataType: number
|
|
216
|
+
/** Whether the field is nullable */
|
|
217
|
+
nullable?: boolean
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Properties of the target Delta table for Arrow Flight ingestion.
|
|
221
|
+
*
|
|
222
|
+
* Unlike `TableProperties` which uses Protocol Buffers, Arrow Flight streams
|
|
223
|
+
* require an Arrow schema definition.
|
|
224
|
+
*
|
|
225
|
+
*/
|
|
226
|
+
export interface ArrowTableProperties {
|
|
227
|
+
/** Full table name in Unity Catalog (e.g., "catalog.schema.table") */
|
|
228
|
+
tableName: string
|
|
229
|
+
/** Arrow schema fields */
|
|
230
|
+
schemaFields: Array<ArrowField>
|
|
231
|
+
}
|
|
100
232
|
/**
|
|
101
233
|
* Custom error type for Zerobus operations.
|
|
102
234
|
*
|
|
@@ -112,15 +244,16 @@ export declare class ZerobusError {
|
|
|
112
244
|
/**
|
|
113
245
|
* A stream for ingesting data into a Databricks Delta table.
|
|
114
246
|
*
|
|
115
|
-
* The stream manages
|
|
116
|
-
* and provides automatic recovery
|
|
247
|
+
* The stream manages JSON or Protocol Buffer ingestion over a bidirectional
|
|
248
|
+
* gRPC connection, handles acknowledgments, and provides automatic recovery
|
|
249
|
+
* on transient failures.
|
|
117
250
|
*
|
|
118
251
|
* # Example
|
|
119
252
|
*
|
|
120
253
|
* ```typescript
|
|
121
254
|
* const stream = await sdk.createStream(tableProps, clientId, clientSecret, options);
|
|
122
|
-
* const
|
|
123
|
-
*
|
|
255
|
+
* const offset = await stream.ingestRecordOffset(Buffer.from([1, 2, 3]));
|
|
256
|
+
* await stream.flush();
|
|
124
257
|
* await stream.close();
|
|
125
258
|
* ```
|
|
126
259
|
*/
|
|
@@ -210,6 +343,13 @@ export declare class ZerobusStream {
|
|
|
210
343
|
* This is the recommended API for high-throughput scenarios where you want to
|
|
211
344
|
* decouple record ingestion from acknowledgment tracking.
|
|
212
345
|
*
|
|
346
|
+
* **Acknowledgments:** the idiomatic flow is to ingest in a loop and then `flush()`
|
|
347
|
+
* once to confirm everything queued so far. The returned offset, together with
|
|
348
|
+
* `waitForOffset()`, lets you confirm a specific record when you need it (acks are
|
|
349
|
+
* ordered, so the last offset confirms the whole run) — prefer `flush()` for bulk.
|
|
350
|
+
* Avoid calling `waitForOffset()` after every record in a tight loop, since that
|
|
351
|
+
* limits throughput to one record per round-trip.
|
|
352
|
+
*
|
|
213
353
|
* # Arguments
|
|
214
354
|
*
|
|
215
355
|
* * `payload` - The record data (Buffer, string, protobuf message, or plain object)
|
|
@@ -222,11 +362,14 @@ export declare class ZerobusStream {
|
|
|
222
362
|
* # Example
|
|
223
363
|
*
|
|
224
364
|
* ```typescript
|
|
225
|
-
* //
|
|
226
|
-
*
|
|
227
|
-
* const
|
|
228
|
-
* //
|
|
229
|
-
*
|
|
365
|
+
* // High-throughput pattern: ingest in a loop, wait once at the end.
|
|
366
|
+
* let lastOffset: bigint | null = null;
|
|
367
|
+
* for (const record of records) {
|
|
368
|
+
* lastOffset = await stream.ingestRecordOffset(record); // resolves on queue, no round-trip
|
|
369
|
+
* }
|
|
370
|
+
* // The ack watermark is monotonic: waiting on the last offset confirms all prior records.
|
|
371
|
+
* if (lastOffset !== null) await stream.waitForOffset(lastOffset);
|
|
372
|
+
* // Or simply: await stream.flush();
|
|
230
373
|
* ```
|
|
231
374
|
*/
|
|
232
375
|
ingestRecordOffset(payload: unknown): Promise<bigint>
|
|
@@ -237,6 +380,12 @@ export declare class ZerobusStream {
|
|
|
237
380
|
* the batch is queued, without waiting for server acknowledgment. Use
|
|
238
381
|
* `waitForOffset()` to wait for acknowledgment when needed.
|
|
239
382
|
*
|
|
383
|
+
* **Acknowledgments:** the idiomatic flow is to ingest your batches in a loop and
|
|
384
|
+
* then `flush()` once to confirm. The returned offset, together with `waitForOffset()`,
|
|
385
|
+
* confirms a specific batch when you need it (acks are ordered, so the last offset
|
|
386
|
+
* confirms the whole run) — prefer `flush()` for bulk. Avoid calling `waitForOffset()`
|
|
387
|
+
* after every batch in a tight loop, since that limits throughput to one round-trip per batch.
|
|
388
|
+
*
|
|
240
389
|
* # Arguments
|
|
241
390
|
*
|
|
242
391
|
* * `records` - Array of record data
|
|
@@ -249,20 +398,26 @@ export declare class ZerobusStream {
|
|
|
249
398
|
* # Example
|
|
250
399
|
*
|
|
251
400
|
* ```typescript
|
|
252
|
-
* //
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
* await stream.
|
|
401
|
+
* // Ingest many batches without waiting, then flush once.
|
|
402
|
+
* let lastOffset = null;
|
|
403
|
+
* for (const batch of batches) {
|
|
404
|
+
* const offset = await stream.ingestRecordsOffset(batch); // resolves on queue
|
|
405
|
+
* if (offset !== null) lastOffset = offset;
|
|
256
406
|
* }
|
|
407
|
+
* if (lastOffset !== null) await stream.waitForOffset(lastOffset);
|
|
408
|
+
* // Or simply: await stream.flush();
|
|
257
409
|
* ```
|
|
258
410
|
*/
|
|
259
411
|
ingestRecordsOffset(records: Array<unknown>): Promise<bigint | null>
|
|
260
412
|
/**
|
|
261
413
|
* Waits for a specific offset to be acknowledged by the server.
|
|
262
414
|
*
|
|
263
|
-
* Use this method with `ingestRecordOffset()` and `ingestRecordsOffset()` to
|
|
264
|
-
*
|
|
265
|
-
*
|
|
415
|
+
* Use this method with `ingestRecordOffset()` and `ingestRecordsOffset()` to confirm
|
|
416
|
+
* a specific record before continuing. Acks are ordered, so waiting on the LAST offset
|
|
417
|
+
* confirms every prior record too — you never need to wait on intermediate offsets.
|
|
418
|
+
* For confirming a bulk run, `flush()` is usually simpler; reach for `waitForOffset()`
|
|
419
|
+
* when one particular record must be confirmed. Avoid calling it after every record in
|
|
420
|
+
* a tight loop, since that limits throughput to one record per round-trip.
|
|
266
421
|
*
|
|
267
422
|
* # Arguments
|
|
268
423
|
*
|
|
@@ -276,12 +431,12 @@ export declare class ZerobusStream {
|
|
|
276
431
|
* # Example
|
|
277
432
|
*
|
|
278
433
|
* ```typescript
|
|
279
|
-
*
|
|
434
|
+
* let lastOffset: bigint | null = null;
|
|
280
435
|
* for (const record of records) {
|
|
281
|
-
*
|
|
436
|
+
* lastOffset = await stream.ingestRecordOffset(record); // no per-record wait
|
|
282
437
|
* }
|
|
283
|
-
* // Wait for the last offset (implies all previous are also acknowledged)
|
|
284
|
-
* await stream.waitForOffset(
|
|
438
|
+
* // Wait for the last offset only (implies all previous are also acknowledged).
|
|
439
|
+
* if (lastOffset !== null) await stream.waitForOffset(lastOffset);
|
|
285
440
|
* ```
|
|
286
441
|
*/
|
|
287
442
|
waitForOffset(offsetId: bigint): Promise<void>
|
|
@@ -291,6 +446,11 @@ export declare class ZerobusStream {
|
|
|
291
446
|
* This method ensures all previously ingested records have been sent to the server
|
|
292
447
|
* and acknowledged. It's useful for checkpointing or ensuring data durability.
|
|
293
448
|
*
|
|
449
|
+
* This is the idiomatic way to confirm records ingested via `ingestRecordOffset()` /
|
|
450
|
+
* `ingestRecordsOffset()`: ingest in a loop, then `flush()` once (for a bounded batch,
|
|
451
|
+
* or periodically for a long-running stream). It resolves once everything queued so
|
|
452
|
+
* far is acknowledged.
|
|
453
|
+
*
|
|
294
454
|
* # Errors
|
|
295
455
|
*
|
|
296
456
|
* - Timeout errors if flush takes longer than configured timeout
|
|
@@ -340,15 +500,12 @@ export declare class ZerobusStream {
|
|
|
340
500
|
*
|
|
341
501
|
* ```typescript
|
|
342
502
|
* try {
|
|
343
|
-
* await stream.
|
|
344
|
-
* await stream.
|
|
503
|
+
* await stream.ingestRecordsOffset(batch1);
|
|
504
|
+
* await stream.ingestRecordsOffset(batch2);
|
|
505
|
+
* await stream.flush();
|
|
345
506
|
* } catch (error) {
|
|
346
507
|
* const unackedBatches = await stream.getUnackedBatches();
|
|
347
|
-
*
|
|
348
|
-
* // Re-ingest with new stream
|
|
349
|
-
* for (const batch of unackedBatches) {
|
|
350
|
-
* await newStream.ingestRecords(batch);
|
|
351
|
-
* }
|
|
508
|
+
* console.log(`Batches available for recovery: ${unackedBatches.length}`);
|
|
352
509
|
* }
|
|
353
510
|
* ```
|
|
354
511
|
*/
|
|
@@ -364,7 +521,8 @@ export declare class ZerobusStream {
|
|
|
364
521
|
* ```typescript
|
|
365
522
|
* const sdk = new ZerobusSdk(
|
|
366
523
|
* "https://workspace-id.zerobus.region.cloud.databricks.com",
|
|
367
|
-
* "https://workspace.cloud.databricks.com"
|
|
524
|
+
* "https://workspace.cloud.databricks.com",
|
|
525
|
+
* { applicationName: "my-app/1.0" }
|
|
368
526
|
* );
|
|
369
527
|
*
|
|
370
528
|
* const stream = await sdk.createStream(
|
|
@@ -384,17 +542,19 @@ export declare class ZerobusSdk {
|
|
|
384
542
|
* (e.g., "https://workspace-id.zerobus.region.cloud.databricks.com")
|
|
385
543
|
* * `unity_catalog_url` - The Unity Catalog endpoint URL
|
|
386
544
|
* (e.g., "https://workspace.cloud.databricks.com")
|
|
545
|
+
* * `options` - Optional SDK configuration (see `ZerobusSdkOptions`),
|
|
546
|
+
* including `applicationName` for server-side attribution.
|
|
387
547
|
*
|
|
388
548
|
* # Errors
|
|
389
549
|
*
|
|
390
550
|
* - Invalid endpoint URLs
|
|
391
551
|
* - Failed to extract workspace ID from the endpoint
|
|
392
552
|
*/
|
|
393
|
-
constructor(zerobusEndpoint: string, unityCatalogUrl: string)
|
|
553
|
+
constructor(zerobusEndpoint: string, unityCatalogUrl: string, options?: ZerobusSdkOptions | undefined | null)
|
|
394
554
|
/**
|
|
395
555
|
* Creates a new ingestion stream to a Delta table.
|
|
396
556
|
*
|
|
397
|
-
* This method
|
|
557
|
+
* This method opens a JSON or Protocol Buffer stream to the Zerobus service
|
|
398
558
|
* and prepares it for data ingestion. By default, it uses OAuth 2.0 Client Credentials
|
|
399
559
|
* authentication. For custom authentication (e.g., Personal Access Tokens), provide
|
|
400
560
|
* a custom headers_provider.
|
|
@@ -436,7 +596,7 @@ export declare class ZerobusSdk {
|
|
|
436
596
|
* "", // ignored
|
|
437
597
|
* undefined,
|
|
438
598
|
* {
|
|
439
|
-
* getHeadersCallback:
|
|
599
|
+
* getHeadersCallback: () => [
|
|
440
600
|
* ["authorization", `Bearer ${myToken}`],
|
|
441
601
|
* ["x-databricks-zerobus-table-name", tableName]
|
|
442
602
|
* ]
|
|
@@ -456,7 +616,8 @@ export declare class ZerobusSdk {
|
|
|
456
616
|
*
|
|
457
617
|
* # Arguments
|
|
458
618
|
*
|
|
459
|
-
* * `stream` - The failed
|
|
619
|
+
* * `stream` - The terminally failed stream to recreate. The TypeScript wrapper
|
|
620
|
+
* must not have been closed because `close()` releases its native handle.
|
|
460
621
|
*
|
|
461
622
|
* # Returns
|
|
462
623
|
*
|
|
@@ -472,14 +633,167 @@ export declare class ZerobusSdk {
|
|
|
472
633
|
*
|
|
473
634
|
* ```typescript
|
|
474
635
|
* try {
|
|
475
|
-
* await stream.
|
|
636
|
+
* await stream.ingestRecordsOffset(batch);
|
|
637
|
+
* await stream.flush();
|
|
476
638
|
* } catch (error) {
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
*
|
|
639
|
+
* try {
|
|
640
|
+
* const newStream = await sdk.recreateStream(stream);
|
|
641
|
+
* try {
|
|
642
|
+
* await newStream.flush();
|
|
643
|
+
* } finally {
|
|
644
|
+
* await newStream.close();
|
|
645
|
+
* }
|
|
646
|
+
* } finally {
|
|
647
|
+
* try {
|
|
648
|
+
* await stream.close();
|
|
649
|
+
* } catch (closeError) {
|
|
650
|
+
* console.error("Failed stream released:", closeError);
|
|
651
|
+
* }
|
|
652
|
+
* }
|
|
481
653
|
* }
|
|
482
654
|
* ```
|
|
483
655
|
*/
|
|
484
656
|
recreateStream(stream: ZerobusStream): Promise<ZerobusStream>
|
|
657
|
+
/**
|
|
658
|
+
* Creates a new Arrow Flight stream to a Delta table.
|
|
659
|
+
*
|
|
660
|
+
* This method establishes an Arrow Flight connection to the Zerobus service
|
|
661
|
+
* for high-performance columnar data ingestion.
|
|
662
|
+
*
|
|
663
|
+
* # Arguments
|
|
664
|
+
*
|
|
665
|
+
* * `table_properties` - Properties of the target table including name and Arrow schema
|
|
666
|
+
* * `client_id` - OAuth 2.0 client ID
|
|
667
|
+
* * `client_secret` - OAuth 2.0 client secret
|
|
668
|
+
* * `options` - Optional stream configuration
|
|
669
|
+
*
|
|
670
|
+
* # Returns
|
|
671
|
+
*
|
|
672
|
+
* A Promise that resolves to a ZerobusArrowStream ready for data ingestion.
|
|
673
|
+
*
|
|
674
|
+
* # Example
|
|
675
|
+
*
|
|
676
|
+
* ```typescript
|
|
677
|
+
* const tableProps = {
|
|
678
|
+
* tableName: 'catalog.schema.table',
|
|
679
|
+
* schemaFields: [
|
|
680
|
+
* { name: 'device_name', dataType: ArrowDataType.Utf8 },
|
|
681
|
+
* { name: 'temp', dataType: ArrowDataType.Int32 },
|
|
682
|
+
* { name: 'humidity', dataType: ArrowDataType.Int64 }
|
|
683
|
+
* ]
|
|
684
|
+
* };
|
|
685
|
+
*
|
|
686
|
+
* const arrowStream = await sdk.createArrowStream(
|
|
687
|
+
* tableProps,
|
|
688
|
+
* clientId,
|
|
689
|
+
* clientSecret,
|
|
690
|
+
* { maxInflightBatches: 100 }
|
|
691
|
+
* );
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
694
|
+
createArrowStream(tableProperties: ArrowTableProperties, clientId: string, clientSecret: string, options?: ArrowStreamConfigurationOptions | undefined | null): Promise<ZerobusArrowStream>
|
|
695
|
+
/**
|
|
696
|
+
* Recreates an Arrow stream with the same configuration and re-ingests unacknowledged batches.
|
|
697
|
+
*
|
|
698
|
+
* # Arguments
|
|
699
|
+
*
|
|
700
|
+
* * `stream` - The terminally failed Arrow stream to recreate. The TypeScript wrapper
|
|
701
|
+
* must not have been closed because `close()` releases its native handle.
|
|
702
|
+
*
|
|
703
|
+
* # Returns
|
|
704
|
+
*
|
|
705
|
+
* A Promise that resolves to a new ZerobusArrowStream with all unacknowledged batches re-ingested.
|
|
706
|
+
*/
|
|
707
|
+
recreateArrowStream(stream: ZerobusArrowStream): Promise<ZerobusArrowStream>
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* An Arrow Flight stream for ingesting Arrow RecordBatches into a Delta table.
|
|
711
|
+
*
|
|
712
|
+
* This stream provides a high-performance interface for streaming Arrow data
|
|
713
|
+
* to Databricks Delta tables using the Arrow Flight protocol.
|
|
714
|
+
*
|
|
715
|
+
* # Lifecycle
|
|
716
|
+
*
|
|
717
|
+
* 1. Create a stream via `sdk.createArrowStream()`
|
|
718
|
+
* 2. Ingest Arrow IPC buffers with `ingestBatch()`
|
|
719
|
+
* 3. Use `waitForOffset()` to wait for acknowledgments
|
|
720
|
+
* 4. Call `flush()` to ensure all batches are persisted
|
|
721
|
+
* 5. Close the stream with `close()`
|
|
722
|
+
*
|
|
723
|
+
* # Example
|
|
724
|
+
*
|
|
725
|
+
* ```typescript
|
|
726
|
+
* import { tableToIPC } from 'apache-arrow';
|
|
727
|
+
*
|
|
728
|
+
* const arrowStream = await sdk.createArrowStream(
|
|
729
|
+
* arrowTableProps,
|
|
730
|
+
* clientId,
|
|
731
|
+
* clientSecret,
|
|
732
|
+
* options
|
|
733
|
+
* );
|
|
734
|
+
*
|
|
735
|
+
* const ipcBuffer = tableToIPC(arrowTable, 'stream');
|
|
736
|
+
* const offset = await arrowStream.ingestBatch(Buffer.from(ipcBuffer));
|
|
737
|
+
* await arrowStream.waitForOffset(offset);
|
|
738
|
+
* await arrowStream.close();
|
|
739
|
+
* ```
|
|
740
|
+
*/
|
|
741
|
+
export declare class ZerobusArrowStream {
|
|
742
|
+
/**
|
|
743
|
+
* Ingests a single Arrow IPC buffer into the stream.
|
|
744
|
+
*
|
|
745
|
+
* The buffer should be an Arrow IPC stream format containing one or more RecordBatches.
|
|
746
|
+
* You can create this using `tableToIPC(table, 'stream')` from the apache-arrow package.
|
|
747
|
+
*
|
|
748
|
+
* # Arguments
|
|
749
|
+
*
|
|
750
|
+
* * `ipc_buffer` - Arrow IPC stream format buffer
|
|
751
|
+
*
|
|
752
|
+
* # Returns
|
|
753
|
+
*
|
|
754
|
+
* The offset ID (bigint) assigned to this batch.
|
|
755
|
+
*
|
|
756
|
+
* # Example
|
|
757
|
+
*
|
|
758
|
+
* ```typescript
|
|
759
|
+
* const table = tableFromArrays({
|
|
760
|
+
* device_name: ['sensor-1'],
|
|
761
|
+
* temp: [25],
|
|
762
|
+
* humidity: [60]
|
|
763
|
+
* });
|
|
764
|
+
* const ipcBuffer = tableToIPC(table, 'stream');
|
|
765
|
+
* const offset = await stream.ingestBatch(Buffer.from(ipcBuffer));
|
|
766
|
+
* await stream.waitForOffset(offset);
|
|
767
|
+
* ```
|
|
768
|
+
*/
|
|
769
|
+
ingestBatch(ipcBuffer: Buffer): Promise<bigint>
|
|
770
|
+
/**
|
|
771
|
+
* Waits for a specific offset to be acknowledged by the server.
|
|
772
|
+
*
|
|
773
|
+
* Use this method with `ingestBatch()` to selectively wait for acknowledgments.
|
|
774
|
+
*
|
|
775
|
+
* # Arguments
|
|
776
|
+
*
|
|
777
|
+
* * `offset_id` - The offset ID to wait for (returned by ingestBatch)
|
|
778
|
+
*/
|
|
779
|
+
waitForOffset(offsetId: bigint): Promise<void>
|
|
780
|
+
/** Flushes all pending batches and waits for acknowledgments. */
|
|
781
|
+
flush(): Promise<void>
|
|
782
|
+
/** Closes the stream gracefully. */
|
|
783
|
+
close(): Promise<void>
|
|
784
|
+
/** Returns whether the stream has been closed. */
|
|
785
|
+
get isClosed(): boolean
|
|
786
|
+
/** Returns the table name for this stream. */
|
|
787
|
+
get tableName(): string
|
|
788
|
+
/**
|
|
789
|
+
* Gets unacknowledged batches as Arrow IPC buffers.
|
|
790
|
+
*
|
|
791
|
+
* This method should only be called after a stream failure to retrieve batches
|
|
792
|
+
* that were sent but not acknowledged. These can be re-ingested into a new stream.
|
|
793
|
+
*
|
|
794
|
+
* # Returns
|
|
795
|
+
*
|
|
796
|
+
* An array of Buffers containing the unacknowledged batches in Arrow IPC format.
|
|
797
|
+
*/
|
|
798
|
+
getUnackedBatches(): Promise<Array<Buffer>>
|
|
485
799
|
}
|
package/index.js
CHANGED
|
@@ -310,9 +310,12 @@ if (!nativeBinding) {
|
|
|
310
310
|
throw new Error(`Failed to load native binding`)
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
-
const { RecordType, ZerobusError, ZerobusStream, ZerobusSdk } = nativeBinding
|
|
313
|
+
const { RecordType, ZerobusError, ZerobusStream, ZerobusSdk, IpcCompressionType, ArrowDataType, ZerobusArrowStream } = nativeBinding
|
|
314
314
|
|
|
315
315
|
module.exports.RecordType = RecordType
|
|
316
316
|
module.exports.ZerobusError = ZerobusError
|
|
317
317
|
module.exports.ZerobusStream = ZerobusStream
|
|
318
318
|
module.exports.ZerobusSdk = ZerobusSdk
|
|
319
|
+
module.exports.IpcCompressionType = IpcCompressionType
|
|
320
|
+
module.exports.ArrowDataType = ArrowDataType
|
|
321
|
+
module.exports.ZerobusArrowStream = ZerobusArrowStream
|
package/package.json
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@databricks/zerobus-ingest-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "TypeScript/Node.js SDK for streaming data ingestion into Databricks Delta tables using Zerobus",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
|
+
"typesVersions": {
|
|
8
|
+
"*": {
|
|
9
|
+
"utils/descriptor": [
|
|
10
|
+
"utils/descriptor.d.ts"
|
|
11
|
+
],
|
|
12
|
+
"utils/descriptor.js": [
|
|
13
|
+
"utils/descriptor.d.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
},
|
|
7
17
|
"keywords": [
|
|
8
18
|
"databricks",
|
|
9
19
|
"delta",
|
|
@@ -66,20 +76,19 @@
|
|
|
66
76
|
"example:arrow": "tsx examples/arrow/batch.ts"
|
|
67
77
|
},
|
|
68
78
|
"optionalDependencies": {
|
|
69
|
-
"@databricks/zerobus-ingest-sdk-linux-x64-gnu": "1.
|
|
70
|
-
"@databricks/zerobus-ingest-sdk-linux-arm64-gnu": "1.
|
|
71
|
-
"@databricks/zerobus-ingest-sdk-win32-x64-msvc": "1.
|
|
72
|
-
"@databricks/zerobus-ingest-sdk-darwin-x64": "1.
|
|
73
|
-
"@databricks/zerobus-ingest-sdk-darwin-arm64": "1.
|
|
79
|
+
"@databricks/zerobus-ingest-sdk-linux-x64-gnu": "1.3.0",
|
|
80
|
+
"@databricks/zerobus-ingest-sdk-linux-arm64-gnu": "1.3.0",
|
|
81
|
+
"@databricks/zerobus-ingest-sdk-win32-x64-msvc": "1.3.0",
|
|
82
|
+
"@databricks/zerobus-ingest-sdk-darwin-x64": "1.3.0",
|
|
83
|
+
"@databricks/zerobus-ingest-sdk-darwin-arm64": "1.3.0"
|
|
84
|
+
},
|
|
85
|
+
"dependencies": {
|
|
86
|
+
"protobufjs": "^8.7.1"
|
|
74
87
|
},
|
|
75
88
|
"peerDependencies": {
|
|
76
|
-
"protobufjs": "^7.0.0",
|
|
77
89
|
"apache-arrow": "^18.0.0"
|
|
78
90
|
},
|
|
79
91
|
"peerDependenciesMeta": {
|
|
80
|
-
"protobufjs": {
|
|
81
|
-
"optional": true
|
|
82
|
-
},
|
|
83
92
|
"apache-arrow": {
|
|
84
93
|
"optional": true
|
|
85
94
|
}
|
|
@@ -89,12 +98,18 @@
|
|
|
89
98
|
"@types/node": "^20.0.0",
|
|
90
99
|
"apache-arrow": "^18.1.0",
|
|
91
100
|
"dotenv": "^17.2.3",
|
|
92
|
-
"protobufjs": "^
|
|
93
|
-
"protobufjs-cli": "^2.0.0",
|
|
101
|
+
"protobufjs-cli": "^2.6.1",
|
|
94
102
|
"tsx": "^4.21.0",
|
|
95
103
|
"typescript": "^5.3.0"
|
|
96
104
|
},
|
|
97
105
|
"overrides": {
|
|
98
|
-
"
|
|
106
|
+
"@protobufjs/utf8": "^1.1.1",
|
|
107
|
+
"brace-expansion": "^2.1.2",
|
|
108
|
+
"glob": "^10.0.0",
|
|
109
|
+
"lodash": "^4.18.0",
|
|
110
|
+
"markdown-it": "^14.2.0",
|
|
111
|
+
"minimatch": "^9.0.7",
|
|
112
|
+
"tmp": "^0.2.6",
|
|
113
|
+
"underscore": "^1.13.8"
|
|
99
114
|
}
|
|
100
115
|
}
|