@qualithm/arrow-flight-sql-js 0.0.1
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/LICENSE +18 -0
- package/README.md +433 -0
- package/dist/arrow.d.ts +65 -0
- package/dist/arrow.d.ts.map +1 -0
- package/dist/arrow.js +250 -0
- package/dist/arrow.js.map +1 -0
- package/dist/client.d.ts +416 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1087 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +128 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +181 -0
- package/dist/errors.js.map +1 -0
- package/dist/generated/index.d.ts +4 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +33 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics.d.ts +217 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +304 -0
- package/dist/metrics.js.map +1 -0
- package/dist/pool.d.ts +161 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/pool.js +434 -0
- package/dist/pool.js.map +1 -0
- package/dist/proto.d.ts +168 -0
- package/dist/proto.d.ts.map +1 -0
- package/dist/proto.js +417 -0
- package/dist/proto.js.map +1 -0
- package/dist/query-builder.d.ts +1 -0
- package/dist/query-builder.d.ts.map +1 -0
- package/dist/query-builder.js +3 -0
- package/dist/query-builder.js.map +1 -0
- package/dist/retry.d.ts +92 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +212 -0
- package/dist/retry.js.map +1 -0
- package/dist/types.d.ts +325 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +18 -0
- package/dist/types.js.map +1 -0
- package/package.json +82 -0
- package/proto/Flight.proto +645 -0
- package/proto/FlightSql.proto +1925 -0
package/dist/arrow.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arrow IPC utilities for parsing Flight data
|
|
3
|
+
*
|
|
4
|
+
* Flight SQL transmits data in Arrow IPC format. This module provides
|
|
5
|
+
* utilities for parsing schemas and record batches from raw IPC bytes.
|
|
6
|
+
*/
|
|
7
|
+
import { MessageHeader, MessageReader, RecordBatchReader, RecordBatchStreamWriter, Table, tableFromIPC } from "apache-arrow";
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Schema Parsing
|
|
10
|
+
// ============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* Parse an Arrow schema from IPC format bytes
|
|
13
|
+
*
|
|
14
|
+
* The schema bytes format from Flight:
|
|
15
|
+
* - 4 bytes: IPC_CONTINUATION_TOKEN (0xFFFFFFFF)
|
|
16
|
+
* - 4 bytes: message length
|
|
17
|
+
* - flatbuffer Message with Schema header
|
|
18
|
+
*
|
|
19
|
+
* Uses MessageReader to parse schema-only IPC messages, which is the correct
|
|
20
|
+
* approach for FlightInfo.schema bytes (as opposed to RecordBatchReader which
|
|
21
|
+
* expects a full IPC stream with record batches).
|
|
22
|
+
*/
|
|
23
|
+
export function parseSchema(schemaBytes) {
|
|
24
|
+
if (schemaBytes.length === 0) {
|
|
25
|
+
throw new Error("Cannot parse empty schema bytes");
|
|
26
|
+
}
|
|
27
|
+
// Use MessageReader which can parse schema-only IPC messages
|
|
28
|
+
const reader = new MessageReader(schemaBytes);
|
|
29
|
+
const schema = reader.readSchema();
|
|
30
|
+
if (!schema) {
|
|
31
|
+
throw new Error("Failed to parse schema from IPC message");
|
|
32
|
+
}
|
|
33
|
+
return schema;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Parse schema from FlightInfo response
|
|
37
|
+
* Returns null if schema is empty or cannot be parsed
|
|
38
|
+
*/
|
|
39
|
+
export function tryParseSchema(schemaBytes) {
|
|
40
|
+
if (schemaBytes.length === 0) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
return parseSchema(schemaBytes);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// ============================================================================
|
|
51
|
+
// Record Batch Streaming
|
|
52
|
+
// ============================================================================
|
|
53
|
+
/**
|
|
54
|
+
* Parse a single FlightData message into a RecordBatch
|
|
55
|
+
*
|
|
56
|
+
* Flight sends data in a streaming format where:
|
|
57
|
+
* - First message: Schema (dataHeader only, no dataBody)
|
|
58
|
+
* - Subsequent messages: RecordBatch (dataHeader + dataBody)
|
|
59
|
+
*
|
|
60
|
+
* The dataHeader is a raw flatbuffer Message (without IPC framing).
|
|
61
|
+
* We need to frame it before passing to apache-arrow.
|
|
62
|
+
*
|
|
63
|
+
* @param dataHeader - IPC Message flatbuffer (without continuation/length prefix)
|
|
64
|
+
* @param dataBody - IPC Message body (raw data buffers)
|
|
65
|
+
* @param schema - Schema to use for parsing (from FlightInfo or first message)
|
|
66
|
+
*/
|
|
67
|
+
export function parseFlightData(dataHeader, dataBody, schema) {
|
|
68
|
+
if (dataHeader.length === 0) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
// Frame the header with IPC continuation marker + length prefix
|
|
72
|
+
const framedData = frameAsIPC(dataHeader, dataBody);
|
|
73
|
+
// Check if this is a schema message (skip it, we already have schema)
|
|
74
|
+
const msgReader = new MessageReader(framedData);
|
|
75
|
+
const msg = msgReader.readMessage();
|
|
76
|
+
if (!msg || msg.headerType === MessageHeader.Schema) {
|
|
77
|
+
return null; // Schema message, no batch to return
|
|
78
|
+
}
|
|
79
|
+
// For RecordBatch messages, we need a complete IPC stream with schema + batch
|
|
80
|
+
// Create a minimal stream with schema first, then this batch
|
|
81
|
+
const schemaBytes = serializeSchemaMessage(schema);
|
|
82
|
+
const fullStream = concatArrays([schemaBytes, framedData]);
|
|
83
|
+
try {
|
|
84
|
+
const reader = RecordBatchReader.from(fullStream);
|
|
85
|
+
const batch = reader.next();
|
|
86
|
+
if (batch.value !== null && batch.value !== undefined) {
|
|
87
|
+
return batch.value;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// If parsing fails, return null
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Frame raw flatbuffer bytes with IPC continuation marker and length prefix
|
|
97
|
+
*/
|
|
98
|
+
function frameAsIPC(header, body) {
|
|
99
|
+
const continuationToken = new Uint8Array([0xff, 0xff, 0xff, 0xff]);
|
|
100
|
+
const metadataLength = new Uint8Array(4);
|
|
101
|
+
new DataView(metadataLength.buffer).setInt32(0, header.length, true);
|
|
102
|
+
// Calculate padding for 8-byte alignment
|
|
103
|
+
const headerPadding = (8 - ((header.length + 4 + 4) % 8)) % 8;
|
|
104
|
+
const padding = new Uint8Array(headerPadding);
|
|
105
|
+
return concatArrays([continuationToken, metadataLength, header, padding, body]);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Serialize a schema to IPC message format
|
|
109
|
+
*/
|
|
110
|
+
function serializeSchemaMessage(schema) {
|
|
111
|
+
// The schema from FlightInfo is already in IPC format with framing
|
|
112
|
+
// We need to extract just the schema portion
|
|
113
|
+
// For now, use a workaround: create an empty table with the schema
|
|
114
|
+
// and extract the schema message from the IPC representation
|
|
115
|
+
const emptyTable = new Table(schema);
|
|
116
|
+
const ipcBytes = tableToIPCBytes(emptyTable);
|
|
117
|
+
// The IPC stream starts with schema message - extract just that part
|
|
118
|
+
// Read the first message (schema)
|
|
119
|
+
const reader = new MessageReader(ipcBytes);
|
|
120
|
+
const msg = reader.readMessage();
|
|
121
|
+
if (msg && msg.headerType === MessageHeader.Schema) {
|
|
122
|
+
// Return the schema portion
|
|
123
|
+
// The reader consumes: continuation(4) + length(4) + header + padding
|
|
124
|
+
const metadataLength = new DataView(ipcBytes.buffer, 4, 4).getInt32(0, true);
|
|
125
|
+
const headerPadding = (8 - ((metadataLength + 4 + 4) % 8)) % 8;
|
|
126
|
+
const schemaEnd = 4 + 4 + metadataLength + headerPadding;
|
|
127
|
+
return ipcBytes.slice(0, schemaEnd);
|
|
128
|
+
}
|
|
129
|
+
// Fallback: shouldn't happen
|
|
130
|
+
return new Uint8Array(0);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Helper to serialize a Table to IPC stream bytes
|
|
134
|
+
*/
|
|
135
|
+
function tableToIPCBytes(table) {
|
|
136
|
+
const writer = RecordBatchStreamWriter.throughNode();
|
|
137
|
+
const chunks = [];
|
|
138
|
+
// Collect chunks synchronously
|
|
139
|
+
writer.on("data", (chunk) => {
|
|
140
|
+
chunks.push(chunk);
|
|
141
|
+
});
|
|
142
|
+
// Write all batches
|
|
143
|
+
for (const batch of table.batches) {
|
|
144
|
+
writer.write(batch);
|
|
145
|
+
}
|
|
146
|
+
writer.end();
|
|
147
|
+
return concatArrays(chunks);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Concatenate multiple Uint8Arrays
|
|
151
|
+
*/
|
|
152
|
+
function concatArrays(arrays) {
|
|
153
|
+
const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
|
|
154
|
+
const result = new Uint8Array(totalLength);
|
|
155
|
+
let offset = 0;
|
|
156
|
+
for (const arr of arrays) {
|
|
157
|
+
result.set(arr, offset);
|
|
158
|
+
offset += arr.length;
|
|
159
|
+
}
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
// ============================================================================
|
|
163
|
+
// Stream Processing
|
|
164
|
+
// ============================================================================
|
|
165
|
+
/**
|
|
166
|
+
* Async iterable that parses FlightData messages into RecordBatches
|
|
167
|
+
*/
|
|
168
|
+
export async function* parseFlightDataStream(flightDataStream, schema) {
|
|
169
|
+
for await (const flightData of flightDataStream) {
|
|
170
|
+
if (!flightData.dataHeader || flightData.dataHeader.length === 0) {
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const batch = parseFlightData(flightData.dataHeader, flightData.dataBody ?? new Uint8Array(), schema);
|
|
174
|
+
if (batch !== null) {
|
|
175
|
+
yield batch;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Collect all record batches into a Table
|
|
181
|
+
*/
|
|
182
|
+
export async function collectToTable(batches, schema) {
|
|
183
|
+
const batchArray = [];
|
|
184
|
+
// Handle both async and sync iterables
|
|
185
|
+
if (Symbol.asyncIterator in batches) {
|
|
186
|
+
for await (const batch of batches) {
|
|
187
|
+
batchArray.push(batch);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
for (const batch of batches) {
|
|
192
|
+
batchArray.push(batch);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// Use tableFromIPC to combine batches
|
|
196
|
+
// First, we need to serialize the batches to IPC format
|
|
197
|
+
if (batchArray.length === 0) {
|
|
198
|
+
// Return empty table with schema
|
|
199
|
+
return tableFromIPC(serializeEmptyTable(schema));
|
|
200
|
+
}
|
|
201
|
+
// For now, return a table from the collected batches
|
|
202
|
+
// The Table constructor can accept an array of RecordBatches
|
|
203
|
+
return new Table(batchArray);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Serialize an empty table with the given schema to IPC format
|
|
207
|
+
*/
|
|
208
|
+
function serializeEmptyTable(schema) {
|
|
209
|
+
// Create minimal IPC stream with just schema and EOS marker
|
|
210
|
+
// This is a simplified implementation
|
|
211
|
+
const schemaMessage = serializeSchemaMessage(schema);
|
|
212
|
+
const eosMarker = new Uint8Array([0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00]);
|
|
213
|
+
const result = new Uint8Array(schemaMessage.length + eosMarker.length);
|
|
214
|
+
result.set(schemaMessage, 0);
|
|
215
|
+
result.set(eosMarker, schemaMessage.length);
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
// serializeSchemaMessage is defined above
|
|
219
|
+
// ============================================================================
|
|
220
|
+
// Table Utilities
|
|
221
|
+
// ============================================================================
|
|
222
|
+
/**
|
|
223
|
+
* Get column names from a schema
|
|
224
|
+
*/
|
|
225
|
+
export function getColumnNames(schema) {
|
|
226
|
+
return schema.fields.map((field) => field.name);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Get the number of rows in a table
|
|
230
|
+
*/
|
|
231
|
+
export function getRowCount(table) {
|
|
232
|
+
return table.numRows;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Convert a Table to an array of plain objects
|
|
236
|
+
*/
|
|
237
|
+
export function tableToObjects(table) {
|
|
238
|
+
const result = [];
|
|
239
|
+
const columns = table.schema.fields.map((f) => f.name);
|
|
240
|
+
for (let i = 0; i < table.numRows; i++) {
|
|
241
|
+
const row = {};
|
|
242
|
+
for (const col of columns) {
|
|
243
|
+
const column = table.getChild(col);
|
|
244
|
+
row[col] = column?.get(i);
|
|
245
|
+
}
|
|
246
|
+
result.push(row);
|
|
247
|
+
}
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=arrow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrow.js","sourceRoot":"","sources":["../src/arrow.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,aAAa,EACb,aAAa,EAEb,iBAAiB,EACjB,uBAAuB,EAEvB,KAAK,EACL,YAAY,EACb,MAAM,cAAc,CAAA;AAErB,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAAC,WAAuB;IACjD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;IACpD,CAAC;IAED,6DAA6D;IAC7D,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,WAAW,CAAC,CAAA;IAC7C,MAAM,MAAM,GAAG,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AC,KAAY,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AACxD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAY;IACtC,OAAO,KAAK,CAAC,OAAO,CAAA;AACtB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAY;IACzC,MAAM,MAAM,GAA8B,EAAE,CAAA;IAC5C,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IAE7D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,MAAM,GAAG,GAA4B,EAAE,CAAA;QACvC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YAC1B,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;YAClC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;QAC3B,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAClB,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arrow Flight SQL Client
|
|
3
|
+
*
|
|
4
|
+
* A TypeScript client for communicating with Arrow Flight SQL servers.
|
|
5
|
+
* Modeled after the official Arrow Flight SQL clients (Java, C++, Go).
|
|
6
|
+
*/
|
|
7
|
+
import { type RecordBatch, type Schema, type Table } from "apache-arrow";
|
|
8
|
+
import type { Action, ActionResult, ActionType, CatalogInfo, ExecuteOptions, FlightDescriptor, FlightInfo, FlightSqlClientOptions, ForeignKeyInfo, PrimaryKeyInfo, SchemaInfo, SchemaResult, TableInfo, TableType, Ticket } from "./types";
|
|
9
|
+
/**
|
|
10
|
+
* Flight SQL client for executing queries and managing data with Arrow Flight SQL servers.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const client = new FlightSqlClient({
|
|
15
|
+
* host: "localhost",
|
|
16
|
+
* port: 50051,
|
|
17
|
+
* tls: false,
|
|
18
|
+
* auth: { type: "bearer", token: "my-token" }
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* await client.connect()
|
|
22
|
+
*
|
|
23
|
+
* const result = await client.execute("SELECT * FROM my_table")
|
|
24
|
+
* for await (const batch of result.stream()) {
|
|
25
|
+
* console.log(batch.numRows)
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* await client.close()
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class FlightSqlClient {
|
|
32
|
+
private readonly options;
|
|
33
|
+
private grpcClient;
|
|
34
|
+
private flightService;
|
|
35
|
+
private authToken;
|
|
36
|
+
private connected;
|
|
37
|
+
constructor(options: FlightSqlClientOptions);
|
|
38
|
+
/**
|
|
39
|
+
* Establish connection to the Flight SQL server and perform authentication.
|
|
40
|
+
*
|
|
41
|
+
* @throws {ConnectionError} If connection cannot be established
|
|
42
|
+
* @throws {AuthenticationError} If authentication fails
|
|
43
|
+
*/
|
|
44
|
+
connect(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Close the connection and release resources.
|
|
47
|
+
*/
|
|
48
|
+
close(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Check if the client is connected.
|
|
51
|
+
*/
|
|
52
|
+
isConnected(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Execute a SQL query and return a QueryResult for retrieving results.
|
|
55
|
+
*
|
|
56
|
+
* @param query - SQL query string
|
|
57
|
+
* @param options - Optional execution options
|
|
58
|
+
* @returns QueryResult with stream() and collect() methods
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const result = await client.query("SELECT * FROM users")
|
|
63
|
+
*
|
|
64
|
+
* // Stream record batches
|
|
65
|
+
* for await (const batch of result.stream()) {
|
|
66
|
+
* console.log(batch.numRows)
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* // Or collect all into a table
|
|
70
|
+
* const table = await result.collect()
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
query(query: string, options?: ExecuteOptions): Promise<QueryResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Execute a SQL query and return flight info for retrieving results.
|
|
76
|
+
* @deprecated Use query() instead for a more ergonomic API
|
|
77
|
+
*
|
|
78
|
+
* @param query - SQL query string
|
|
79
|
+
* @param options - Optional execution options
|
|
80
|
+
* @returns FlightInfo containing endpoints for data retrieval
|
|
81
|
+
*/
|
|
82
|
+
execute(query: string, options?: ExecuteOptions): Promise<FlightInfo>;
|
|
83
|
+
/**
|
|
84
|
+
* Execute a SQL update statement (INSERT, UPDATE, DELETE).
|
|
85
|
+
*
|
|
86
|
+
* @param query - SQL statement
|
|
87
|
+
* @param options - Optional execution options
|
|
88
|
+
* @returns Number of rows affected
|
|
89
|
+
*/
|
|
90
|
+
executeUpdate(query: string, options?: ExecuteOptions): Promise<bigint>;
|
|
91
|
+
/**
|
|
92
|
+
* Create a prepared statement for repeated execution.
|
|
93
|
+
*
|
|
94
|
+
* @param query - SQL query with optional parameter placeholders
|
|
95
|
+
* @param options - Optional prepared statement options
|
|
96
|
+
* @returns PreparedStatement that can be executed multiple times
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const stmt = await client.prepare("SELECT * FROM users WHERE id = ?")
|
|
101
|
+
* const result = await stmt.executeQuery()
|
|
102
|
+
* await stmt.close()
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
prepare(query: string, options?: ExecuteOptions): Promise<PreparedStatement>;
|
|
106
|
+
/**
|
|
107
|
+
* Get the list of catalogs available on the server.
|
|
108
|
+
*
|
|
109
|
+
* @returns Array of catalog information
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const catalogs = await client.getCatalogs()
|
|
114
|
+
* for (const catalog of catalogs) {
|
|
115
|
+
* console.log(catalog.catalogName)
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
getCatalogs(): Promise<CatalogInfo[]>;
|
|
120
|
+
/**
|
|
121
|
+
* Get the list of schemas available in a catalog.
|
|
122
|
+
*
|
|
123
|
+
* @param catalog - Optional catalog name to filter by
|
|
124
|
+
* @param schemaFilterPattern - Optional SQL LIKE pattern to filter schema names
|
|
125
|
+
* @returns Array of schema information
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // Get all schemas
|
|
130
|
+
* const schemas = await client.getSchemas()
|
|
131
|
+
*
|
|
132
|
+
* // Get schemas in specific catalog
|
|
133
|
+
* const schemas = await client.getSchemas("my_catalog")
|
|
134
|
+
*
|
|
135
|
+
* // Get schemas matching pattern
|
|
136
|
+
* const schemas = await client.getSchemas(undefined, "public%")
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
getSchemas(catalog?: string, schemaFilterPattern?: string): Promise<SchemaInfo[]>;
|
|
140
|
+
/**
|
|
141
|
+
* Get the list of tables available.
|
|
142
|
+
*
|
|
143
|
+
* @param options - Filter options
|
|
144
|
+
* @returns Array of table information
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* // Get all tables
|
|
149
|
+
* const tables = await client.getTables()
|
|
150
|
+
*
|
|
151
|
+
* // Get tables in specific catalog/schema
|
|
152
|
+
* const tables = await client.getTables({
|
|
153
|
+
* catalog: "my_catalog",
|
|
154
|
+
* schemaPattern: "public"
|
|
155
|
+
* })
|
|
156
|
+
*
|
|
157
|
+
* // Get only views
|
|
158
|
+
* const views = await client.getTables({ tableTypes: ["VIEW"] })
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
getTables(options?: {
|
|
162
|
+
catalog?: string;
|
|
163
|
+
schemaPattern?: string;
|
|
164
|
+
tablePattern?: string;
|
|
165
|
+
tableTypes?: string[];
|
|
166
|
+
includeSchema?: boolean;
|
|
167
|
+
}): Promise<TableInfo[]>;
|
|
168
|
+
/**
|
|
169
|
+
* Get the list of table types supported by the server.
|
|
170
|
+
*
|
|
171
|
+
* @returns Array of table type names (e.g., "TABLE", "VIEW", "SYSTEM TABLE")
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* const tableTypes = await client.getTableTypes()
|
|
176
|
+
* console.log(tableTypes) // [{ tableType: "TABLE" }, { tableType: "VIEW" }, ...]
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
getTableTypes(): Promise<TableType[]>;
|
|
180
|
+
/**
|
|
181
|
+
* Get the primary keys for a table.
|
|
182
|
+
*
|
|
183
|
+
* @param table - Table name
|
|
184
|
+
* @param catalog - Optional catalog name
|
|
185
|
+
* @param schema - Optional schema name
|
|
186
|
+
* @returns Array of primary key information
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const primaryKeys = await client.getPrimaryKeys("users")
|
|
191
|
+
* for (const pk of primaryKeys) {
|
|
192
|
+
* console.log(`${pk.columnName} (sequence: ${pk.keySequence})`)
|
|
193
|
+
* }
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
getPrimaryKeys(table: string, catalog?: string, schema?: string): Promise<PrimaryKeyInfo[]>;
|
|
197
|
+
/**
|
|
198
|
+
* Get the foreign keys that reference a table's primary key (exported keys).
|
|
199
|
+
*
|
|
200
|
+
* @param table - Table name
|
|
201
|
+
* @param catalog - Optional catalog name
|
|
202
|
+
* @param schema - Optional schema name
|
|
203
|
+
* @returns Array of foreign key information
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* // Find all tables that reference the "users" table
|
|
208
|
+
* const exportedKeys = await client.getExportedKeys("users")
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
getExportedKeys(table: string, catalog?: string, schema?: string): Promise<ForeignKeyInfo[]>;
|
|
212
|
+
/**
|
|
213
|
+
* Get the foreign keys in a table (imported keys).
|
|
214
|
+
*
|
|
215
|
+
* @param table - Table name
|
|
216
|
+
* @param catalog - Optional catalog name
|
|
217
|
+
* @param schema - Optional schema name
|
|
218
|
+
* @returns Array of foreign key information
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* // Find all foreign keys in the "orders" table
|
|
223
|
+
* const importedKeys = await client.getImportedKeys("orders")
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
getImportedKeys(table: string, catalog?: string, schema?: string): Promise<ForeignKeyInfo[]>;
|
|
227
|
+
/**
|
|
228
|
+
* Helper to fetch catalog results and map rows to typed objects
|
|
229
|
+
*/
|
|
230
|
+
private fetchCatalogResults;
|
|
231
|
+
/**
|
|
232
|
+
* Helper to fetch foreign key results with the complex schema
|
|
233
|
+
*/
|
|
234
|
+
private fetchForeignKeyResults;
|
|
235
|
+
/**
|
|
236
|
+
* Get flight information for a descriptor.
|
|
237
|
+
*
|
|
238
|
+
* @param descriptor - Flight descriptor
|
|
239
|
+
* @returns FlightInfo with schema and endpoints
|
|
240
|
+
*/
|
|
241
|
+
getFlightInfo(descriptor: FlightDescriptor): Promise<FlightInfo>;
|
|
242
|
+
/**
|
|
243
|
+
* Get the schema for a flight descriptor without fetching data.
|
|
244
|
+
*
|
|
245
|
+
* @param descriptor - Flight descriptor
|
|
246
|
+
* @returns Schema result
|
|
247
|
+
*/
|
|
248
|
+
getSchema(descriptor: FlightDescriptor): Promise<SchemaResult>;
|
|
249
|
+
/**
|
|
250
|
+
* Retrieve data for a ticket as an async iterator of FlightData.
|
|
251
|
+
*
|
|
252
|
+
* @param ticket - Ticket from FlightInfo endpoint
|
|
253
|
+
* @yields FlightData chunks containing dataHeader and dataBody
|
|
254
|
+
*/
|
|
255
|
+
doGet(ticket: Ticket): AsyncGenerator<{
|
|
256
|
+
dataHeader?: Uint8Array;
|
|
257
|
+
dataBody?: Uint8Array;
|
|
258
|
+
}, void, unknown>;
|
|
259
|
+
/**
|
|
260
|
+
* Upload Arrow data to the server.
|
|
261
|
+
*
|
|
262
|
+
* @param descriptor - Flight descriptor describing the data
|
|
263
|
+
* @param dataStream - Async iterable of FlightData messages
|
|
264
|
+
* @returns Async iterator of PutResult messages
|
|
265
|
+
*/
|
|
266
|
+
doPut(descriptor: FlightDescriptor, dataStream: AsyncIterable<{
|
|
267
|
+
dataHeader: Uint8Array;
|
|
268
|
+
dataBody: Uint8Array;
|
|
269
|
+
appMetadata?: Uint8Array;
|
|
270
|
+
}>): AsyncGenerator<{
|
|
271
|
+
appMetadata?: Uint8Array;
|
|
272
|
+
}, void, unknown>;
|
|
273
|
+
/**
|
|
274
|
+
* Helper to get the first item from an async iterable without consuming the rest
|
|
275
|
+
*/
|
|
276
|
+
private getFirstFromIterable;
|
|
277
|
+
/**
|
|
278
|
+
* Execute an action on the server.
|
|
279
|
+
*
|
|
280
|
+
* @param action - Action to execute
|
|
281
|
+
* @returns Async iterator of results
|
|
282
|
+
*/
|
|
283
|
+
doAction(action: Action): AsyncGenerator<ActionResult, void, unknown>;
|
|
284
|
+
/**
|
|
285
|
+
* List available action types.
|
|
286
|
+
*
|
|
287
|
+
* @returns Array of available action types
|
|
288
|
+
*/
|
|
289
|
+
listActions(): Promise<ActionType[]>;
|
|
290
|
+
private authenticate;
|
|
291
|
+
private handshake;
|
|
292
|
+
private encodeBasicAuth;
|
|
293
|
+
private createCredentials;
|
|
294
|
+
private waitForReady;
|
|
295
|
+
private createRequestMetadata;
|
|
296
|
+
private cleanup;
|
|
297
|
+
private ensureConnected;
|
|
298
|
+
private wrapGrpcError;
|
|
299
|
+
/**
|
|
300
|
+
* Wraps a gRPC stream to convert errors to FlightSqlError types.
|
|
301
|
+
* gRPC streams are already async iterable, so we just need error handling.
|
|
302
|
+
*/
|
|
303
|
+
private wrapStream;
|
|
304
|
+
private serializeFlightDescriptor;
|
|
305
|
+
private parseFlightInfo;
|
|
306
|
+
private parseSchemaResult;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Result of a query execution with methods to stream or collect data.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```typescript
|
|
313
|
+
* const result = await client.query("SELECT * FROM users")
|
|
314
|
+
*
|
|
315
|
+
* // Option 1: Stream record batches (memory efficient)
|
|
316
|
+
* for await (const batch of result.stream()) {
|
|
317
|
+
* console.log(`Batch with ${batch.numRows} rows`)
|
|
318
|
+
* }
|
|
319
|
+
*
|
|
320
|
+
* // Option 2: Collect all data into a table
|
|
321
|
+
* const table = await result.collect()
|
|
322
|
+
* console.log(`Total rows: ${table.numRows}`)
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
export declare class QueryResult {
|
|
326
|
+
private readonly client;
|
|
327
|
+
private readonly info;
|
|
328
|
+
private readonly parsedSchema;
|
|
329
|
+
constructor(client: FlightSqlClient, flightInfo: FlightInfo, schema: Schema | null);
|
|
330
|
+
/**
|
|
331
|
+
* Get the FlightInfo for this query result
|
|
332
|
+
*/
|
|
333
|
+
get flightInfo(): FlightInfo;
|
|
334
|
+
/**
|
|
335
|
+
* Get the Arrow schema for this query result
|
|
336
|
+
* May be null if schema could not be parsed
|
|
337
|
+
*/
|
|
338
|
+
get schema(): Schema | null;
|
|
339
|
+
/**
|
|
340
|
+
* Get the total number of records (if known)
|
|
341
|
+
* Returns -1 if unknown
|
|
342
|
+
*/
|
|
343
|
+
get totalRecords(): bigint;
|
|
344
|
+
/**
|
|
345
|
+
* Stream record batches from all endpoints.
|
|
346
|
+
* This is memory-efficient for large result sets.
|
|
347
|
+
*
|
|
348
|
+
* Flight SQL streams data as:
|
|
349
|
+
* 1. Schema message (dataHeader only)
|
|
350
|
+
* 2. RecordBatch messages (dataHeader + dataBody)
|
|
351
|
+
*
|
|
352
|
+
* We collect all messages and parse them as a complete IPC stream.
|
|
353
|
+
*/
|
|
354
|
+
stream(): AsyncGenerator<RecordBatch, void, unknown>;
|
|
355
|
+
/**
|
|
356
|
+
* Frame raw flatbuffer bytes with IPC continuation marker and length prefix
|
|
357
|
+
*/
|
|
358
|
+
private frameAsIPC;
|
|
359
|
+
/**
|
|
360
|
+
* Concatenate multiple Uint8Arrays
|
|
361
|
+
*/
|
|
362
|
+
private concatArrays;
|
|
363
|
+
/**
|
|
364
|
+
* Collect all data from all endpoints into a single Table.
|
|
365
|
+
* Warning: This loads the entire result set into memory.
|
|
366
|
+
*/
|
|
367
|
+
collect(): Promise<Table>;
|
|
368
|
+
/**
|
|
369
|
+
* Helper to convert batches array to async generator
|
|
370
|
+
*/
|
|
371
|
+
private streamBatches;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* A prepared statement that can be executed multiple times with different parameters.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```typescript
|
|
378
|
+
* const stmt = await client.prepare("SELECT * FROM users WHERE id = ?")
|
|
379
|
+
*
|
|
380
|
+
* // Execute with parameters
|
|
381
|
+
* const result = await stmt.execute()
|
|
382
|
+
* const table = await result.collect()
|
|
383
|
+
*
|
|
384
|
+
* // Clean up
|
|
385
|
+
* await stmt.close()
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
export declare class PreparedStatement {
|
|
389
|
+
private readonly client;
|
|
390
|
+
private handle;
|
|
391
|
+
private datasetSchema;
|
|
392
|
+
private parameterSchema;
|
|
393
|
+
private closed;
|
|
394
|
+
constructor(client: FlightSqlClient, handle: Uint8Array, datasetSchema: Schema | null, parameterSchema: Schema | null);
|
|
395
|
+
/**
|
|
396
|
+
* Get the schema of the result set
|
|
397
|
+
*/
|
|
398
|
+
get resultSchema(): Schema | null;
|
|
399
|
+
/**
|
|
400
|
+
* Get the schema of the parameters
|
|
401
|
+
*/
|
|
402
|
+
get parametersSchema(): Schema | null;
|
|
403
|
+
/**
|
|
404
|
+
* Check if the prepared statement is closed
|
|
405
|
+
*/
|
|
406
|
+
get isClosed(): boolean;
|
|
407
|
+
/**
|
|
408
|
+
* Execute the prepared statement as a query
|
|
409
|
+
*/
|
|
410
|
+
executeQuery(): Promise<QueryResult>;
|
|
411
|
+
/**
|
|
412
|
+
* Close the prepared statement and release server resources
|
|
413
|
+
*/
|
|
414
|
+
close(): Promise<void>;
|
|
415
|
+
}
|
|
416
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,KAAK,WAAW,EAAqB,KAAK,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,cAAc,CAAA;AAqB3F,OAAO,KAAK,EACV,MAAM,EACN,YAAY,EACZ,UAAU,EAEV,WAAW,EAEX,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,sBAAsB,EACtB,cAAc,EAEd,cAAc,EACd,UAAU,EACV,YAAY,EACZ,SAAS,EACT,SAAS,EACT,MAAM,EACP,MAAM,SAAS,CAAA;AAMhB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAGA;IAExB,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,aAAa,CAA6C;IAClE,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,SAAS,CAAQ;gBAEb,OAAO,EAAE,sBAAsB;IAc3C;;;;;OAKG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAmD9B;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,WAAW,IAAI,OAAO;IAQt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