@qualithm/arrow-flight-sql-js 1.1.0 → 1.2.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/LICENSE +146 -14
- package/dist/client.d.ts +120 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +217 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/results.d.ts +89 -0
- package/dist/results.d.ts.map +1 -0
- package/dist/results.js +138 -0
- package/dist/results.js.map +1 -0
- package/package.json +6 -4
- package/dist/greet.d.ts +0 -26
- package/dist/greet.d.ts.map +0 -1
- package/dist/greet.js +0 -23
- package/dist/greet.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,18 +1,150 @@
|
|
|
1
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
7
|
-
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
8
|
-
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
furnished to do so, subject to the following conditions:
|
|
7
|
+
1. Definitions.
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined
|
|
10
|
+
by Sections 1 through 9 of this document.
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is
|
|
13
|
+
granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control,
|
|
16
|
+
are controlled by, or are under common control with that entity. For the purposes of this
|
|
17
|
+
definition, "control" means (i) the power, direct or indirect, to cause the direction or
|
|
18
|
+
management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent
|
|
19
|
+
(50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
20
|
+
|
|
21
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by
|
|
22
|
+
this License.
|
|
23
|
+
|
|
24
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited
|
|
25
|
+
to software source code, documentation source, and configuration files.
|
|
26
|
+
|
|
27
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a
|
|
28
|
+
Source form, including but not limited to compiled object code, generated documentation, and
|
|
29
|
+
conversions to other media types.
|
|
30
|
+
|
|
31
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under
|
|
32
|
+
the License, as indicated by a copyright notice that is included in or attached to the work (an
|
|
33
|
+
example is provided in the Appendix below).
|
|
34
|
+
|
|
35
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or
|
|
36
|
+
derived from) the Work and for which the editorial revisions, annotations, elaborations, or
|
|
37
|
+
other modifications represent, as a whole, an original work of authorship. For the purposes of
|
|
38
|
+
this License, Derivative Works shall not include works that remain separable from, or merely
|
|
39
|
+
link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
40
|
+
|
|
41
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and
|
|
42
|
+
any modifications or additions to that Work or Derivative Works thereof, that is intentionally
|
|
43
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner or by an individual
|
|
44
|
+
or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this
|
|
45
|
+
definition, "submitted" means any form of electronic, verbal, or written communication sent to
|
|
46
|
+
the Licensor or its representatives, including but not limited to communication on electronic
|
|
47
|
+
mailing lists, source code control systems, and issue tracking systems that are managed by, or
|
|
48
|
+
on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding
|
|
49
|
+
communication that is conspicuously marked or otherwise designated in writing by the copyright
|
|
50
|
+
owner as "Not a Contribution."
|
|
51
|
+
|
|
52
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a
|
|
53
|
+
Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
54
|
+
|
|
55
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each
|
|
56
|
+
Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
|
57
|
+
irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display,
|
|
58
|
+
publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or
|
|
59
|
+
Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor
|
|
62
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
63
|
+
(except as stated in this section) patent license to make, have made, use, offer to sell, sell,
|
|
64
|
+
import, and otherwise transfer the Work, where such license applies only to those patent claims
|
|
65
|
+
licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or
|
|
66
|
+
by combination of their Contribution(s) with the Work to which such Contribution(s) was
|
|
67
|
+
submitted. If You institute patent litigation against any entity (including a cross-claim or
|
|
68
|
+
counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work
|
|
69
|
+
constitutes direct or contributory patent infringement, then any patent licenses granted to You
|
|
70
|
+
under this License for that Work shall terminate as of the date such litigation is filed.
|
|
71
|
+
|
|
72
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof
|
|
73
|
+
in any medium, with or without modifications, and in Source or Object form, provided that You
|
|
74
|
+
meet the following conditions:
|
|
75
|
+
|
|
76
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License;
|
|
77
|
+
and
|
|
78
|
+
|
|
79
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the
|
|
80
|
+
files; and
|
|
81
|
+
|
|
82
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all
|
|
83
|
+
copyright, patent, trademark, and attribution notices from the Source form of the Work,
|
|
84
|
+
excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
85
|
+
|
|
86
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative
|
|
87
|
+
Works that You distribute must include a readable copy of the attribution notices contained
|
|
88
|
+
within such NOTICE file, excluding those notices that do not pertain to any part of the
|
|
89
|
+
Derivative Works, in at least one of the following places: within a NOTICE text file distributed
|
|
90
|
+
as part of the Derivative Works; within the Source form or documentation, if provided along with
|
|
91
|
+
the Derivative Works; or, within a display generated by the Derivative Works, if and wherever
|
|
92
|
+
such third-party notices normally appear. The contents of the NOTICE file are for informational
|
|
93
|
+
purposes only and do not modify the License. You may add Your own attribution notices within
|
|
94
|
+
Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the
|
|
95
|
+
Work, provided that such additional attribution notices cannot be construed as modifying the
|
|
96
|
+
License.
|
|
97
|
+
|
|
98
|
+
You may add Your own copyright statement to Your modifications and may provide additional or
|
|
99
|
+
different license terms and conditions for use, reproduction, or distribution of Your
|
|
100
|
+
modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and
|
|
101
|
+
distribution of the Work otherwise complies with the conditions stated in this License.
|
|
102
|
+
|
|
103
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution
|
|
104
|
+
intentionally submitted for inclusion in the Work by You to the Licensor shall be under the
|
|
105
|
+
terms and conditions of this License, without any additional terms or conditions.
|
|
106
|
+
Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate
|
|
107
|
+
license agreement you may have executed with Licensor regarding such Contributions.
|
|
108
|
+
|
|
109
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service
|
|
110
|
+
marks, or product names of the Licensor, except as required for reasonable and customary use in
|
|
111
|
+
describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
112
|
+
|
|
113
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor
|
|
114
|
+
provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT
|
|
115
|
+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation,
|
|
116
|
+
any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
117
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or
|
|
118
|
+
redistributing the Work and assume any risks associated with Your exercise of permissions under
|
|
119
|
+
this License.
|
|
120
|
+
|
|
121
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including
|
|
122
|
+
negligence), contract, or otherwise, unless required by applicable law (such as deliberate and
|
|
123
|
+
grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for
|
|
124
|
+
damages, including any direct, indirect, special, incidental, or consequential damages of any
|
|
125
|
+
character arising as a result of this License or out of the use or inability to use the Work
|
|
126
|
+
(including but not limited to damages for loss of goodwill, work stoppage, computer failure or
|
|
127
|
+
malfunction, or any and all other commercial damages or losses), even if such Contributor has
|
|
128
|
+
been advised of the possibility of such damages.
|
|
129
|
+
|
|
130
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works
|
|
131
|
+
thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty,
|
|
132
|
+
indemnity, or other liability obligations and/or rights consistent with this License. However,
|
|
133
|
+
in accepting such obligations, You may act only on Your own behalf and on Your sole
|
|
134
|
+
responsibility, not on behalf of any other Contributor, and only if You agree to indemnify,
|
|
135
|
+
defend, and hold each Contributor harmless for any liability incurred by, or claims asserted
|
|
136
|
+
against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
137
|
+
|
|
138
|
+
END OF TERMS AND CONDITIONS
|
|
139
|
+
|
|
140
|
+
Copyright 2026 Qualithm
|
|
141
|
+
|
|
142
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
|
|
143
|
+
compliance with the License. You may obtain a copy of the License at
|
|
144
|
+
|
|
145
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
146
|
+
|
|
147
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is
|
|
148
|
+
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied. See the License for the specific language governing permissions and limitations under the
|
|
150
|
+
License.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flight SQL client implementation.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import { type CallOptions, FlightClient, type FlightClientOptions, type FlightInfo } from "@qualithm/arrow-flight-js";
|
|
7
|
+
/**
|
|
8
|
+
* Options for creating a FlightSqlClient.
|
|
9
|
+
*/
|
|
10
|
+
export type FlightSqlClientOptions = FlightClientOptions;
|
|
11
|
+
/**
|
|
12
|
+
* Options for executing a query.
|
|
13
|
+
*/
|
|
14
|
+
export type QueryOptions = CallOptions & {
|
|
15
|
+
/**
|
|
16
|
+
* Transaction ID for executing the query as part of a transaction.
|
|
17
|
+
* If not provided, the query is auto-committed.
|
|
18
|
+
*/
|
|
19
|
+
transactionId?: Buffer;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Result of a statement update operation.
|
|
23
|
+
*/
|
|
24
|
+
export type UpdateResult = {
|
|
25
|
+
/**
|
|
26
|
+
* The number of records affected by the update.
|
|
27
|
+
* A value of -1 indicates an unknown count.
|
|
28
|
+
*/
|
|
29
|
+
recordCount: number;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Arrow Flight SQL client for executing SQL queries and commands.
|
|
33
|
+
*
|
|
34
|
+
* Extends the base FlightClient with SQL-specific functionality including
|
|
35
|
+
* query execution, updates, and metadata queries.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const client = new FlightSqlClient({
|
|
40
|
+
* host: "localhost",
|
|
41
|
+
* port: 8815,
|
|
42
|
+
* tls: false
|
|
43
|
+
* })
|
|
44
|
+
*
|
|
45
|
+
* await client.connect()
|
|
46
|
+
*
|
|
47
|
+
* // Execute a query
|
|
48
|
+
* const info = await client.query("SELECT * FROM users")
|
|
49
|
+
*
|
|
50
|
+
* // Execute an update
|
|
51
|
+
* const result = await client.executeUpdate("INSERT INTO users (name) VALUES ('Alice')")
|
|
52
|
+
* console.log("Rows affected:", result.recordCount)
|
|
53
|
+
*
|
|
54
|
+
* client.close()
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare class FlightSqlClient extends FlightClient {
|
|
58
|
+
/**
|
|
59
|
+
* Executes a SQL query and returns flight information for retrieving results.
|
|
60
|
+
*
|
|
61
|
+
* This method sends a CommandStatementQuery to the server and returns
|
|
62
|
+
* FlightInfo containing endpoints for data retrieval. Use the returned
|
|
63
|
+
* FlightInfo with `doGet()` to retrieve the actual data.
|
|
64
|
+
*
|
|
65
|
+
* @param query - The SQL query to execute
|
|
66
|
+
* @param options - Optional query options
|
|
67
|
+
* @returns Flight information for retrieving query results
|
|
68
|
+
* @throws {FlightError} If the query fails
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const info = await client.query("SELECT * FROM users WHERE active = true")
|
|
73
|
+
*
|
|
74
|
+
* // Retrieve data from each endpoint
|
|
75
|
+
* for (const endpoint of info.endpoint) {
|
|
76
|
+
* for await (const data of client.doGet(endpoint.ticket!)) {
|
|
77
|
+
* // Process data
|
|
78
|
+
* }
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
query(query: string, options?: QueryOptions): Promise<FlightInfo>;
|
|
83
|
+
/**
|
|
84
|
+
* Executes a SQL update statement (INSERT, UPDATE, DELETE).
|
|
85
|
+
*
|
|
86
|
+
* @param query - The SQL update statement to execute
|
|
87
|
+
* @param options - Optional query options
|
|
88
|
+
* @returns The update result containing the number of affected records
|
|
89
|
+
* @throws {FlightError} If the update fails
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* const result = await client.executeUpdate(
|
|
94
|
+
* "UPDATE users SET active = false WHERE last_login < '2024-01-01'"
|
|
95
|
+
* )
|
|
96
|
+
* console.log("Rows updated:", result.recordCount)
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
executeUpdate(query: string, options?: QueryOptions): Promise<UpdateResult>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Creates a new FlightSqlClient and connects to the server.
|
|
103
|
+
*
|
|
104
|
+
* This is a convenience function that combines creating a client
|
|
105
|
+
* and calling connect() in one step.
|
|
106
|
+
*
|
|
107
|
+
* @param options - Connection options
|
|
108
|
+
* @returns A connected FlightSqlClient
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const client = await createFlightSqlClient({
|
|
113
|
+
* host: "localhost",
|
|
114
|
+
* port: 8815,
|
|
115
|
+
* tls: false
|
|
116
|
+
* })
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function createFlightSqlClient(options: FlightSqlClientOptions): Promise<FlightSqlClient>;
|
|
120
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,KAAK,WAAW,EAGhB,YAAY,EACZ,KAAK,mBAAmB,EAExB,KAAK,UAAU,EAChB,MAAM,2BAA2B,CAAA;AAalC;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,mBAAmB,CAAA;AAExD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG;IACvC;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAiFD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,eAAgB,SAAQ,YAAY;IAC/C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;IAYvE;;;;;;;;;;;;;;;OAeG;IACG,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;CA6ClF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,eAAe,CAAC,CAI1B"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flight SQL client implementation.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import { cmdDescriptor, FlightClient, FlightError } from "@qualithm/arrow-flight-js";
|
|
7
|
+
import { CommandStatementQuery, CommandStatementUpdate, DoPutUpdateResult } from "./generated/arrow/flight/protocol/sql/FlightSql.js";
|
|
8
|
+
/**
|
|
9
|
+
* Flight SQL type URL prefix for encoding commands in Any messages.
|
|
10
|
+
*/
|
|
11
|
+
const TYPE_URL_PREFIX = "type.googleapis.com/arrow.flight.protocol.sql";
|
|
12
|
+
/**
|
|
13
|
+
* Encodes a Flight SQL command as a descriptor command buffer.
|
|
14
|
+
*
|
|
15
|
+
* Flight SQL commands are encoded as protobuf Any messages with a type URL
|
|
16
|
+
* and the serialised command bytes.
|
|
17
|
+
*
|
|
18
|
+
* @param typeUrl - The type URL for the command
|
|
19
|
+
* @param data - The serialised command bytes
|
|
20
|
+
* @returns The encoded Any message buffer
|
|
21
|
+
*/
|
|
22
|
+
function packAny(typeUrl, data) {
|
|
23
|
+
// Any message format:
|
|
24
|
+
// field 1 (type_url): string - wire type 2 (length-delimited)
|
|
25
|
+
// field 2 (value): bytes - wire type 2 (length-delimited)
|
|
26
|
+
const typeUrlBytes = Buffer.from(typeUrl, "utf8");
|
|
27
|
+
const typeUrlLen = typeUrlBytes.length;
|
|
28
|
+
const dataLen = data.length;
|
|
29
|
+
// Calculate varint sizes
|
|
30
|
+
const typeUrlVarIntSize = varIntSize(typeUrlLen);
|
|
31
|
+
const dataVarIntSize = varIntSize(dataLen);
|
|
32
|
+
// Total size: 1 (tag) + varint + typeUrl + 1 (tag) + varint + data
|
|
33
|
+
const totalSize = 1 + typeUrlVarIntSize + typeUrlLen + 1 + dataVarIntSize + dataLen;
|
|
34
|
+
const buffer = Buffer.alloc(totalSize);
|
|
35
|
+
let offset = 0;
|
|
36
|
+
// Field 1: type_url (tag = 0x0a = field 1, wire type 2)
|
|
37
|
+
buffer[offset++] = 0x0a;
|
|
38
|
+
offset = writeVarInt(buffer, offset, typeUrlLen);
|
|
39
|
+
typeUrlBytes.copy(buffer, offset);
|
|
40
|
+
offset += typeUrlLen;
|
|
41
|
+
// Field 2: value (tag = 0x12 = field 2, wire type 2)
|
|
42
|
+
buffer[offset++] = 0x12;
|
|
43
|
+
offset = writeVarInt(buffer, offset, dataLen);
|
|
44
|
+
Buffer.from(data).copy(buffer, offset);
|
|
45
|
+
return buffer;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Calculates the size of a varint encoding.
|
|
49
|
+
*/
|
|
50
|
+
function varIntSize(value) {
|
|
51
|
+
let size = 1;
|
|
52
|
+
while (value >= 0x80) {
|
|
53
|
+
value >>>= 7;
|
|
54
|
+
size++;
|
|
55
|
+
}
|
|
56
|
+
return size;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Writes a varint to a buffer.
|
|
60
|
+
*/
|
|
61
|
+
function writeVarInt(buffer, offset, value) {
|
|
62
|
+
while (value >= 0x80) {
|
|
63
|
+
buffer[offset++] = (value & 0x7f) | 0x80;
|
|
64
|
+
value >>>= 7;
|
|
65
|
+
}
|
|
66
|
+
buffer[offset++] = value;
|
|
67
|
+
return offset;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates a command descriptor for a Flight SQL command.
|
|
71
|
+
*
|
|
72
|
+
* @param typeName - The protobuf type name (without the prefix)
|
|
73
|
+
* @param encodedCommand - The encoded command bytes
|
|
74
|
+
* @returns A Flight descriptor
|
|
75
|
+
*/
|
|
76
|
+
function createCommandDescriptor(typeName, encodedCommand) {
|
|
77
|
+
const typeUrl = `${TYPE_URL_PREFIX}.${typeName}`;
|
|
78
|
+
const anyBytes = packAny(typeUrl, encodedCommand);
|
|
79
|
+
return cmdDescriptor(anyBytes);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Arrow Flight SQL client for executing SQL queries and commands.
|
|
83
|
+
*
|
|
84
|
+
* Extends the base FlightClient with SQL-specific functionality including
|
|
85
|
+
* query execution, updates, and metadata queries.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const client = new FlightSqlClient({
|
|
90
|
+
* host: "localhost",
|
|
91
|
+
* port: 8815,
|
|
92
|
+
* tls: false
|
|
93
|
+
* })
|
|
94
|
+
*
|
|
95
|
+
* await client.connect()
|
|
96
|
+
*
|
|
97
|
+
* // Execute a query
|
|
98
|
+
* const info = await client.query("SELECT * FROM users")
|
|
99
|
+
*
|
|
100
|
+
* // Execute an update
|
|
101
|
+
* const result = await client.executeUpdate("INSERT INTO users (name) VALUES ('Alice')")
|
|
102
|
+
* console.log("Rows affected:", result.recordCount)
|
|
103
|
+
*
|
|
104
|
+
* client.close()
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export class FlightSqlClient extends FlightClient {
|
|
108
|
+
/**
|
|
109
|
+
* Executes a SQL query and returns flight information for retrieving results.
|
|
110
|
+
*
|
|
111
|
+
* This method sends a CommandStatementQuery to the server and returns
|
|
112
|
+
* FlightInfo containing endpoints for data retrieval. Use the returned
|
|
113
|
+
* FlightInfo with `doGet()` to retrieve the actual data.
|
|
114
|
+
*
|
|
115
|
+
* @param query - The SQL query to execute
|
|
116
|
+
* @param options - Optional query options
|
|
117
|
+
* @returns Flight information for retrieving query results
|
|
118
|
+
* @throws {FlightError} If the query fails
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* const info = await client.query("SELECT * FROM users WHERE active = true")
|
|
123
|
+
*
|
|
124
|
+
* // Retrieve data from each endpoint
|
|
125
|
+
* for (const endpoint of info.endpoint) {
|
|
126
|
+
* for await (const data of client.doGet(endpoint.ticket!)) {
|
|
127
|
+
* // Process data
|
|
128
|
+
* }
|
|
129
|
+
* }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
async query(query, options) {
|
|
133
|
+
const command = {
|
|
134
|
+
query,
|
|
135
|
+
transactionId: options?.transactionId
|
|
136
|
+
};
|
|
137
|
+
const encoded = CommandStatementQuery.encode(command).finish();
|
|
138
|
+
const descriptor = createCommandDescriptor("CommandStatementQuery", encoded);
|
|
139
|
+
return this.getFlightInfo(descriptor, options);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Executes a SQL update statement (INSERT, UPDATE, DELETE).
|
|
143
|
+
*
|
|
144
|
+
* @param query - The SQL update statement to execute
|
|
145
|
+
* @param options - Optional query options
|
|
146
|
+
* @returns The update result containing the number of affected records
|
|
147
|
+
* @throws {FlightError} If the update fails
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* const result = await client.executeUpdate(
|
|
152
|
+
* "UPDATE users SET active = false WHERE last_login < '2024-01-01'"
|
|
153
|
+
* )
|
|
154
|
+
* console.log("Rows updated:", result.recordCount)
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
async executeUpdate(query, options) {
|
|
158
|
+
const command = {
|
|
159
|
+
query,
|
|
160
|
+
transactionId: options?.transactionId
|
|
161
|
+
};
|
|
162
|
+
const encoded = CommandStatementUpdate.encode(command).finish();
|
|
163
|
+
const descriptor = createCommandDescriptor("CommandStatementUpdate", encoded);
|
|
164
|
+
const stream = this.doPut(options);
|
|
165
|
+
// Send the command as the first message with descriptor
|
|
166
|
+
stream.write({
|
|
167
|
+
flightDescriptor: {
|
|
168
|
+
type: 2, // CMD
|
|
169
|
+
path: [],
|
|
170
|
+
cmd: descriptor.cmd
|
|
171
|
+
},
|
|
172
|
+
dataHeader: Buffer.alloc(0),
|
|
173
|
+
appMetadata: Buffer.alloc(0),
|
|
174
|
+
dataBody: Buffer.alloc(0)
|
|
175
|
+
});
|
|
176
|
+
stream.end();
|
|
177
|
+
// Collect results
|
|
178
|
+
const results = await stream.collectResults();
|
|
179
|
+
const firstResult = results.at(0);
|
|
180
|
+
if (!firstResult) {
|
|
181
|
+
throw new FlightError("no result returned from update", "INTERNAL");
|
|
182
|
+
}
|
|
183
|
+
// Decode the DoPutUpdateResult from appMetadata
|
|
184
|
+
const { appMetadata } = firstResult;
|
|
185
|
+
if (appMetadata.length === 0) {
|
|
186
|
+
throw new FlightError("update result missing app metadata", "INTERNAL");
|
|
187
|
+
}
|
|
188
|
+
const updateResult = DoPutUpdateResult.decode(appMetadata);
|
|
189
|
+
return {
|
|
190
|
+
recordCount: updateResult.recordCount
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Creates a new FlightSqlClient and connects to the server.
|
|
196
|
+
*
|
|
197
|
+
* This is a convenience function that combines creating a client
|
|
198
|
+
* and calling connect() in one step.
|
|
199
|
+
*
|
|
200
|
+
* @param options - Connection options
|
|
201
|
+
* @returns A connected FlightSqlClient
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* const client = await createFlightSqlClient({
|
|
206
|
+
* host: "localhost",
|
|
207
|
+
* port: 8815,
|
|
208
|
+
* tls: false
|
|
209
|
+
* })
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export async function createFlightSqlClient(options) {
|
|
213
|
+
const client = new FlightSqlClient(options);
|
|
214
|
+
await client.connect();
|
|
215
|
+
return client;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAGL,aAAa,EACb,YAAY,EAEZ,WAAW,EAEZ,MAAM,2BAA2B,CAAA;AAElC,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,oDAAoD,CAAA;AAE3D;;GAEG;AACH,MAAM,eAAe,GAAG,+CAA+C,CAAA;AA6BvE;;;;;;;;;GASG;AACH,SAAS,OAAO,CAAC,OAAe,EAAE,IAAgB;IAChD,sBAAsB;IACtB,8DAA8D;IAC9D,0DAA0D;IAC1D,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACjD,MAAM,UAAU,GAAG,YAAY,CAAC,MAAM,CAAA;IACtC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAA;IAE3B,yBAAyB;IACzB,MAAM,iBAAiB,GAAG,UAAU,CAAC,UAAU,CAAC,CAAA;IAChD,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;IAE1C,mEAAmE;IACnE,MAAM,SAAS,GAAG,CAAC,GAAG,iBAAiB,GAAG,UAAU,GAAG,CAAC,GAAG,cAAc,GAAG,OAAO,CAAA;IACnF,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IAEtC,IAAI,MAAM,GAAG,CAAC,CAAA;IAEd,wDAAwD;IACxD,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG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QAEF,MAAM,CAAC,GAAG,EAAE,CAAA;QAEZ,kBAAkB;QAClB,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,cAAc,EAAE,CAAA;QAC7C,MAAM,WAAW,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAEjC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,WAAW,CAAC,gCAAgC,EAAE,UAAU,CAAC,CAAA;QACrE,CAAC;QAED,gDAAgD;QAChD,MAAM,EAAE,WAAW,EAAE,GAAG,WAAW,CAAA;QACnC,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,WAAW,CAAC,oCAAoC,EAAE,UAAU,CAAC,CAAA;QACzE,CAAC;QAED,MAAM,YAAY,GAAG,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;QAE1D,OAAO;YACL,WAAW,EAAE,YAAY,CAAC,WAAW;SACtC,CAAA;IACH,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAA+B;IAE/B,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC,CAAA;IAC3C,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;IACtB,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Arrow Flight SQL client for JavaScript and TypeScript.
|
|
3
|
+
*
|
|
4
|
+
* Provides SQL-specific functionality on top of Arrow Flight for database
|
|
5
|
+
* interactions including query execution, updates, and metadata queries.
|
|
3
6
|
*
|
|
4
7
|
* @packageDocumentation
|
|
5
8
|
*/
|
|
6
|
-
export type {
|
|
7
|
-
export {
|
|
9
|
+
export type { FlightSqlClientOptions, QueryOptions, UpdateResult } from "./client.js";
|
|
10
|
+
export { createFlightSqlClient, FlightSqlClient } from "./client.js";
|
|
11
|
+
export type { ResultIteratorOptions } from "./results.js";
|
|
12
|
+
export { flightInfoToTable, iterateResults, queryToTable, ticketToTable } from "./results.js";
|
|
13
|
+
export { type CallOptions, type FlightClientOptions, type FlightData, FlightError, type FlightInfo, type Ticket } from "@qualithm/arrow-flight-js";
|
|
8
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,YAAY,EAAE,sBAAsB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACrF,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAGpE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAG7F,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,UAAU,EACf,WAAW,EACX,KAAK,UAAU,EACf,KAAK,MAAM,EACZ,MAAM,2BAA2B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Arrow Flight SQL client for JavaScript and TypeScript.
|
|
3
|
+
*
|
|
4
|
+
* Provides SQL-specific functionality on top of Arrow Flight for database
|
|
5
|
+
* interactions including query execution, updates, and metadata queries.
|
|
3
6
|
*
|
|
4
7
|
* @packageDocumentation
|
|
5
8
|
*/
|
|
6
|
-
export {
|
|
9
|
+
export { createFlightSqlClient, FlightSqlClient } from "./client.js";
|
|
10
|
+
export { flightInfoToTable, iterateResults, queryToTable, ticketToTable } from "./results.js";
|
|
11
|
+
// Re-export base Flight client types for convenience
|
|
12
|
+
export { FlightError } from "@qualithm/arrow-flight-js";
|
|
7
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIpE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAE7F,qDAAqD;AACrD,OAAO,EAIL,WAAW,EAGZ,MAAM,2BAA2B,CAAA"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result set iteration utilities for Flight SQL queries.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import type { FlightData, FlightInfo, Ticket } from "@qualithm/arrow-flight-js";
|
|
7
|
+
import { tableFromIPC } from "apache-arrow";
|
|
8
|
+
import type { FlightSqlClient } from "./client.js";
|
|
9
|
+
/**
|
|
10
|
+
* Options for iterating over query results.
|
|
11
|
+
*/
|
|
12
|
+
export type ResultIteratorOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* Maximum number of rows to return.
|
|
15
|
+
* If not specified, all rows are returned.
|
|
16
|
+
*/
|
|
17
|
+
limit?: number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Executes a query and returns results as an Arrow Table.
|
|
21
|
+
*
|
|
22
|
+
* This is a convenience function that handles the entire query workflow:
|
|
23
|
+
* 1. Executes the query to get FlightInfo
|
|
24
|
+
* 2. Retrieves data from all endpoints
|
|
25
|
+
* 3. Combines the data into an Arrow Table
|
|
26
|
+
*
|
|
27
|
+
* @param client - The FlightSqlClient to use
|
|
28
|
+
* @param query - The SQL query to execute
|
|
29
|
+
* @returns An Arrow Table containing all query results
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { queryToTable } from "@qualithm/arrow-flight-sql-js"
|
|
34
|
+
*
|
|
35
|
+
* const table = await queryToTable(client, "SELECT * FROM users LIMIT 100")
|
|
36
|
+
* console.log("Rows:", table.numRows)
|
|
37
|
+
* console.log("Columns:", table.schema.fields.map(f => f.name))
|
|
38
|
+
*
|
|
39
|
+
* // Iterate over rows
|
|
40
|
+
* for (const row of table) {
|
|
41
|
+
* console.log(row.toJSON())
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function queryToTable(client: FlightSqlClient, query: string): Promise<ReturnType<typeof tableFromIPC>>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves data from FlightInfo and returns it as an Arrow Table.
|
|
48
|
+
*
|
|
49
|
+
* @param client - The FlightSqlClient to use
|
|
50
|
+
* @param info - The FlightInfo from a query
|
|
51
|
+
* @returns An Arrow Table containing all data from the endpoints
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const info = await client.query("SELECT * FROM users")
|
|
56
|
+
* const table = await flightInfoToTable(client, info)
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function flightInfoToTable(client: FlightSqlClient, info: FlightInfo): Promise<ReturnType<typeof tableFromIPC>>;
|
|
60
|
+
/**
|
|
61
|
+
* Iterates over query results as Arrow record batches.
|
|
62
|
+
*
|
|
63
|
+
* This is useful for processing large result sets without loading
|
|
64
|
+
* everything into memory at once.
|
|
65
|
+
*
|
|
66
|
+
* @param client - The FlightSqlClient to use
|
|
67
|
+
* @param info - The FlightInfo from a query
|
|
68
|
+
* @yields FlightData messages containing Arrow IPC data
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const info = await client.query("SELECT * FROM large_table")
|
|
73
|
+
*
|
|
74
|
+
* for await (const data of iterateResults(client, info)) {
|
|
75
|
+
* // Process each batch of data
|
|
76
|
+
* console.log("Received batch:", data.dataBody.length, "bytes")
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function iterateResults(client: FlightSqlClient, info: FlightInfo): AsyncGenerator<FlightData, void, undefined>;
|
|
81
|
+
/**
|
|
82
|
+
* Gets a single ticket's data as an Arrow Table.
|
|
83
|
+
*
|
|
84
|
+
* @param client - The FlightSqlClient to use
|
|
85
|
+
* @param ticket - The ticket to retrieve
|
|
86
|
+
* @returns An Arrow Table containing the ticket's data
|
|
87
|
+
*/
|
|
88
|
+
export declare function ticketToTable(client: FlightSqlClient, ticket: Ticket): Promise<ReturnType<typeof tableFromIPC>>;
|
|
89
|
+
//# sourceMappingURL=results.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../src/results.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AA2BD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,eAAe,EACvB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAG1C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CA2B1C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAuB,cAAc,CACnC,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE,UAAU,GACf,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC,CAO7C;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAiB1C"}
|
package/dist/results.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { tableFromIPC } from "apache-arrow";
|
|
2
|
+
/**
|
|
3
|
+
* Collects all FlightData from a doGet stream into Arrow IPC bytes.
|
|
4
|
+
*
|
|
5
|
+
* @param dataStream - The async iterable of FlightData messages
|
|
6
|
+
* @returns Combined IPC bytes for all batches
|
|
7
|
+
*/
|
|
8
|
+
async function collectFlightData(dataStream) {
|
|
9
|
+
const chunks = [];
|
|
10
|
+
for await (const data of dataStream) {
|
|
11
|
+
// The first message contains the schema in dataHeader
|
|
12
|
+
if (data.dataHeader.length > 0) {
|
|
13
|
+
chunks.push(data.dataHeader);
|
|
14
|
+
}
|
|
15
|
+
// Data body contains the actual record batch
|
|
16
|
+
if (data.dataBody.length > 0) {
|
|
17
|
+
chunks.push(data.dataBody);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return chunks;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Executes a query and returns results as an Arrow Table.
|
|
24
|
+
*
|
|
25
|
+
* This is a convenience function that handles the entire query workflow:
|
|
26
|
+
* 1. Executes the query to get FlightInfo
|
|
27
|
+
* 2. Retrieves data from all endpoints
|
|
28
|
+
* 3. Combines the data into an Arrow Table
|
|
29
|
+
*
|
|
30
|
+
* @param client - The FlightSqlClient to use
|
|
31
|
+
* @param query - The SQL query to execute
|
|
32
|
+
* @returns An Arrow Table containing all query results
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { queryToTable } from "@qualithm/arrow-flight-sql-js"
|
|
37
|
+
*
|
|
38
|
+
* const table = await queryToTable(client, "SELECT * FROM users LIMIT 100")
|
|
39
|
+
* console.log("Rows:", table.numRows)
|
|
40
|
+
* console.log("Columns:", table.schema.fields.map(f => f.name))
|
|
41
|
+
*
|
|
42
|
+
* // Iterate over rows
|
|
43
|
+
* for (const row of table) {
|
|
44
|
+
* console.log(row.toJSON())
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export async function queryToTable(client, query) {
|
|
49
|
+
const info = await client.query(query);
|
|
50
|
+
return flightInfoToTable(client, info);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves data from FlightInfo and returns it as an Arrow Table.
|
|
54
|
+
*
|
|
55
|
+
* @param client - The FlightSqlClient to use
|
|
56
|
+
* @param info - The FlightInfo from a query
|
|
57
|
+
* @returns An Arrow Table containing all data from the endpoints
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const info = await client.query("SELECT * FROM users")
|
|
62
|
+
* const table = await flightInfoToTable(client, info)
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export async function flightInfoToTable(client, info) {
|
|
66
|
+
const allChunks = [];
|
|
67
|
+
for (const endpoint of info.endpoint) {
|
|
68
|
+
if (!endpoint.ticket) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const dataStream = client.doGet(endpoint.ticket);
|
|
72
|
+
const chunks = await collectFlightData(dataStream);
|
|
73
|
+
allChunks.push(...chunks);
|
|
74
|
+
}
|
|
75
|
+
if (allChunks.length === 0) {
|
|
76
|
+
throw new Error("no data returned from query");
|
|
77
|
+
}
|
|
78
|
+
// Combine all chunks and parse as IPC
|
|
79
|
+
const totalLength = allChunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
80
|
+
const combined = new Uint8Array(totalLength);
|
|
81
|
+
let offset = 0;
|
|
82
|
+
for (const chunk of allChunks) {
|
|
83
|
+
combined.set(chunk, offset);
|
|
84
|
+
offset += chunk.length;
|
|
85
|
+
}
|
|
86
|
+
return tableFromIPC(combined);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Iterates over query results as Arrow record batches.
|
|
90
|
+
*
|
|
91
|
+
* This is useful for processing large result sets without loading
|
|
92
|
+
* everything into memory at once.
|
|
93
|
+
*
|
|
94
|
+
* @param client - The FlightSqlClient to use
|
|
95
|
+
* @param info - The FlightInfo from a query
|
|
96
|
+
* @yields FlightData messages containing Arrow IPC data
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const info = await client.query("SELECT * FROM large_table")
|
|
101
|
+
*
|
|
102
|
+
* for await (const data of iterateResults(client, info)) {
|
|
103
|
+
* // Process each batch of data
|
|
104
|
+
* console.log("Received batch:", data.dataBody.length, "bytes")
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export async function* iterateResults(client, info) {
|
|
109
|
+
for (const endpoint of info.endpoint) {
|
|
110
|
+
if (!endpoint.ticket) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
yield* client.doGet(endpoint.ticket);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Gets a single ticket's data as an Arrow Table.
|
|
118
|
+
*
|
|
119
|
+
* @param client - The FlightSqlClient to use
|
|
120
|
+
* @param ticket - The ticket to retrieve
|
|
121
|
+
* @returns An Arrow Table containing the ticket's data
|
|
122
|
+
*/
|
|
123
|
+
export async function ticketToTable(client, ticket) {
|
|
124
|
+
const dataStream = client.doGet(ticket);
|
|
125
|
+
const chunks = await collectFlightData(dataStream);
|
|
126
|
+
if (chunks.length === 0) {
|
|
127
|
+
throw new Error("no data returned from ticket");
|
|
128
|
+
}
|
|
129
|
+
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
130
|
+
const combined = new Uint8Array(totalLength);
|
|
131
|
+
let offset = 0;
|
|
132
|
+
for (const chunk of chunks) {
|
|
133
|
+
combined.set(chunk, offset);
|
|
134
|
+
offset += chunk.length;
|
|
135
|
+
}
|
|
136
|
+
return tableFromIPC(combined);
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=results.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.js","sourceRoot":"","sources":["../src/results.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAe3C;;;;;GAKG;AACH,KAAK,UAAU,iBAAiB,CAC9B,UAAuD;IAEvD,MAAM,MAAM,GAAiB,EAAE,CAAA;IAE/B,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QACpC,sDAAsD;QACtD,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAC9B,CAAC;QACD,6CAA6C;QAC7C,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC5B,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAuB,EACvB,KAAa;IAEb,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACtC,OAAO,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA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AQ,EAAE,CAAC;QACrC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;YACrB,SAAQ;QACV,CAAC;QACD,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACtC,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAuB,EACvB,MAAc;IAEd,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACvC,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,UAAU,CAAC,CAAA;IAElD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IACxE,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAA;IAC5C,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC3B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAA;IACxB,CAAC;IAED,OAAO,YAAY,CAAC,QAAQ,CAAC,CAAA;AAC/B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qualithm/arrow-flight-sql-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Arrow Flight SQL client for JavaScript and TypeScript runtimes.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"typescript",
|
|
13
13
|
"apache-arrow"
|
|
14
14
|
],
|
|
15
|
-
"license": "
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
16
|
"author": "Qualithm",
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
@@ -64,10 +64,12 @@
|
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@qualithm/arrow-flight-js": "1.
|
|
67
|
+
"@qualithm/arrow-flight-js": ">=1.0.0",
|
|
68
|
+
"apache-arrow": ">=17.0.0"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
|
-
"@qualithm/arrow-flight-js": "1.
|
|
71
|
+
"@qualithm/arrow-flight-js": "1.5.0",
|
|
72
|
+
"apache-arrow": "19.0.1",
|
|
71
73
|
"@eslint/js": "10.0.1",
|
|
72
74
|
"grpc-tools": "1.13.1",
|
|
73
75
|
"ts-proto": "2.11.2",
|
package/dist/greet.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Options for the greet function.
|
|
3
|
-
*/
|
|
4
|
-
export type GreetOptions = {
|
|
5
|
-
/** Name to greet. */
|
|
6
|
-
name: string;
|
|
7
|
-
/** Whether to use formal greeting. */
|
|
8
|
-
formal?: boolean;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Generate a greeting message.
|
|
12
|
-
*
|
|
13
|
-
* @param options - The greeting options.
|
|
14
|
-
* @returns A greeting string.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* const message = greet({ name: "World" })
|
|
19
|
-
* // => "Hello, World!"
|
|
20
|
-
*
|
|
21
|
-
* const formal = greet({ name: "World", formal: true })
|
|
22
|
-
* // => "Good day, World."
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export declare function greet(options: GreetOptions): string;
|
|
26
|
-
//# sourceMappingURL=greet.d.ts.map
|
package/dist/greet.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"greet.d.ts","sourceRoot":"","sources":["../src/greet.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,sCAAsC;IACtC,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAQnD"}
|
package/dist/greet.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate a greeting message.
|
|
3
|
-
*
|
|
4
|
-
* @param options - The greeting options.
|
|
5
|
-
* @returns A greeting string.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const message = greet({ name: "World" })
|
|
10
|
-
* // => "Hello, World!"
|
|
11
|
-
*
|
|
12
|
-
* const formal = greet({ name: "World", formal: true })
|
|
13
|
-
* // => "Good day, World."
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export function greet(options) {
|
|
17
|
-
const { name, formal = false } = options;
|
|
18
|
-
if (formal) {
|
|
19
|
-
return `Good day, ${name}.`;
|
|
20
|
-
}
|
|
21
|
-
return `Hello, ${name}!`;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=greet.js.map
|
package/dist/greet.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"greet.js","sourceRoot":"","sources":["../src/greet.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,KAAK,CAAC,OAAqB;IACzC,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,OAAO,CAAA;IAExC,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,aAAa,IAAI,GAAG,CAAA;IAC7B,CAAC;IAED,OAAO,UAAU,IAAI,GAAG,CAAA;AAC1B,CAAC"}
|