@databricks/sdk-statementexecution 0.1.0-dev.4 → 0.1.0-dev.6

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/src/v1/client.ts DELETED
@@ -1,256 +0,0 @@
1
- // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
-
3
- import {VERSION as AUTH_VERSION} from '@databricks/sdk-auth';
4
- import {createDefault} from '@databricks/sdk-core/clientinfo';
5
- import type {Logger} from '@databricks/sdk-core/logger';
6
- import {NoOpLogger} from '@databricks/sdk-core/logger';
7
- import type {CallOptions} from '@databricks/sdk-options/call';
8
- import type {ClientOptions} from '@databricks/sdk-options/client';
9
- import type {HttpClient} from '@databricks/sdk-core/http';
10
- import {newHttpClient} from './transport';
11
- import {
12
- buildHttpRequest,
13
- executeCall,
14
- executeHttpCall,
15
- marshalRequest,
16
- parseResponse,
17
- } from './utils';
18
- import pkgJson from '../../package.json' with {type: 'json'};
19
- import type {
20
- CancelStatementRequest,
21
- CancelStatementResponse,
22
- ExecuteStatementRequest,
23
- GetResultDataRequest,
24
- GetStatementResultRequest,
25
- ResultData,
26
- StatementResponse,
27
- } from './model';
28
- import {
29
- marshalCancelStatementRequestSchema,
30
- marshalExecuteStatementRequestSchema,
31
- unmarshalCancelStatementResponseSchema,
32
- unmarshalResultDataSchema,
33
- unmarshalStatementResponseSchema,
34
- } from './model';
35
-
36
- // Package identity segment for this client to be used in the User-Agent header.
37
- const PACKAGE_SEGMENT = {
38
- key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
39
- value: pkgJson.version,
40
- };
41
-
42
- export class StatementExecutionClient {
43
- private readonly host: string;
44
- // Workspace ID used to route workspace-level calls on unified hosts (SPOG).
45
- // When set, workspace-level methods send X-Databricks-Org-Id on every
46
- // request.
47
- private readonly workspaceId: string | undefined;
48
- private readonly httpClient: HttpClient;
49
- private readonly logger: Logger;
50
- // User-Agent header value. Composed once at construction from
51
- // createDefault() merged with this package's identity and the active
52
- // credential's name.
53
- private readonly userAgent: string;
54
-
55
- constructor(options: ClientOptions) {
56
- if (options.host === undefined) {
57
- throw new Error('Host is required.');
58
- }
59
- this.host = options.host.replace(/\/$/, '');
60
- this.workspaceId = options.workspaceId;
61
- this.logger = options.logger ?? new NoOpLogger();
62
- const info = createDefault()
63
- .with(PACKAGE_SEGMENT)
64
- .with({key: 'sdk-js-auth', value: AUTH_VERSION})
65
- .with({key: 'auth', value: options.credentials?.name() ?? 'default'});
66
- this.userAgent = info.toString();
67
- this.httpClient = newHttpClient(options);
68
- }
69
-
70
- /**
71
- * Requests that an executing statement be canceled. Callers must poll for status to see the
72
- * terminal state. Cancel response is empty; receiving response indicates successful receipt.
73
- */
74
- async cancelStatement(
75
- req: CancelStatementRequest,
76
- options?: CallOptions
77
- ): Promise<CancelStatementResponse> {
78
- const url = `${this.host}/api/2.0/sql/statements/${req.statementId ?? ''}/cancel`;
79
- const body = marshalRequest(req, marshalCancelStatementRequestSchema);
80
- let resp: CancelStatementResponse | undefined;
81
- const call = async (callSignal?: AbortSignal): Promise<void> => {
82
- const headers = new Headers({'Content-Type': 'application/json'});
83
- if (this.workspaceId !== undefined) {
84
- headers.set('X-Databricks-Org-Id', this.workspaceId);
85
- }
86
- headers.set('User-Agent', this.userAgent);
87
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
88
- const respBody = await executeHttpCall({
89
- request: httpReq,
90
- httpClient: this.httpClient,
91
- logger: this.logger,
92
- });
93
- resp = parseResponse(respBody, unmarshalCancelStatementResponseSchema);
94
- };
95
- await executeCall(call, options);
96
- if (resp === undefined) {
97
- throw new Error('operation completed without a result.');
98
- }
99
- return resp;
100
- }
101
-
102
- /**
103
- * Execute a SQL statement and optionally await its results for a specified time.
104
- *
105
- * **Use case: small result sets with INLINE + JSON_ARRAY**
106
- *
107
- * For flows that generate small and predictable result sets (<= 25 MiB), `INLINE` responses of `JSON_ARRAY` result
108
- * data are typically the simplest way to execute and fetch result data.
109
- *
110
- * **Use case: large result sets with EXTERNAL_LINKS**
111
- *
112
- * Using `EXTERNAL_LINKS` to fetch result data allows you to fetch large result sets efficiently.
113
- * The main differences from using `INLINE` disposition are that the result data is accessed
114
- * with URLs, and
115
- * that there are 3 supported formats: `JSON_ARRAY`, `ARROW_STREAM` and `CSV` compared to only `JSON_ARRAY` with
116
- * `INLINE`.
117
- *
118
- * ** URLs**
119
- *
120
- * External links point to data stored within your workspace's internal storage, in the form of
121
- * a URL. The URLs are valid for only a short
122
- * period, <= 15 minutes. Alongside each `external_link` is an expiration field indicating the time at which the URL
123
- * is no longer valid. In `EXTERNAL_LINKS` mode, chunks can be resolved and fetched multiple times and in parallel.
124
- *
125
- * ----
126
- *
127
- * ### **Warning: Databricks strongly recommends that you protect the URLs that are returned by the `EXTERNAL_LINKS` disposition.**
128
- *
129
- * When you use the `EXTERNAL_LINKS` disposition, a
130
- * short-lived, URL is generated, which can be
131
- * used to download the results directly
132
- * from . As a
133
- * short-lived is
134
- * embedded in this URL, you should protect
135
- * the URL.
136
- *
137
- * Because URLs are already generated with
138
- * embedded temporary s,
139
- * you must not set an `Authorization` header in the download requests.
140
- *
141
- * The `EXTERNAL_LINKS` disposition can be disabled upon request by creating a support
142
- * case.
143
- *
144
- * See also [Security best practices](/sql/admin/sql-execution-tutorial.html#security-best-practices).
145
- *
146
- * ----
147
- *
148
- * StatementResponse contains `statement_id` and `status`; other fields might be absent or present depending on
149
- * context. If the SQL warehouse fails to execute the provided statement, a 200 response is returned with
150
- * `status.state` set to `FAILED` (in contrast to a failure when accepting the request, which results in a non-200
151
- * response). Details of the error can be found at `status.error` in case of execution failures.
152
- */
153
- async executeStatement(
154
- req: ExecuteStatementRequest,
155
- options?: CallOptions
156
- ): Promise<StatementResponse> {
157
- const url = `${this.host}/api/2.0/sql/statements`;
158
- const body = marshalRequest(req, marshalExecuteStatementRequestSchema);
159
- let resp: StatementResponse | undefined;
160
- const call = async (callSignal?: AbortSignal): Promise<void> => {
161
- const headers = new Headers({'Content-Type': 'application/json'});
162
- if (this.workspaceId !== undefined) {
163
- headers.set('X-Databricks-Org-Id', this.workspaceId);
164
- }
165
- headers.set('User-Agent', this.userAgent);
166
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
167
- const respBody = await executeHttpCall({
168
- request: httpReq,
169
- httpClient: this.httpClient,
170
- logger: this.logger,
171
- });
172
- resp = parseResponse(respBody, unmarshalStatementResponseSchema);
173
- };
174
- await executeCall(call, options);
175
- if (resp === undefined) {
176
- throw new Error('operation completed without a result.');
177
- }
178
- return resp;
179
- }
180
-
181
- /**
182
- * After the statement execution has `SUCCEEDED`, this request can be used to fetch any chunk by
183
- * index. Whereas the first chunk with `chunk_index=0` is typically fetched with
184
- * :method:statementexecution/executeStatement or :method:statementexecution/getStatement, this
185
- * request can be used to fetch subsequent chunks. The response structure is identical to the
186
- * nested `result` element described in the :method:statementexecution/getStatement request, and
187
- * similarly includes the `next_chunk_index` and `next_chunk_internal_link` fields for simple
188
- * iteration through the result set. Depending on `disposition`, the response returns chunks of
189
- * data either inline, or as links.
190
- */
191
- async getResultData(
192
- req: GetResultDataRequest,
193
- options?: CallOptions
194
- ): Promise<ResultData> {
195
- const url = `${this.host}/api/2.0/sql/statements/${req.statementId ?? ''}/result/chunks/${String(req.chunkIndex ?? '')}`;
196
- let resp: ResultData | undefined;
197
- const call = async (callSignal?: AbortSignal): Promise<void> => {
198
- const headers = new Headers();
199
- if (this.workspaceId !== undefined) {
200
- headers.set('X-Databricks-Org-Id', this.workspaceId);
201
- }
202
- headers.set('User-Agent', this.userAgent);
203
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
204
- const respBody = await executeHttpCall({
205
- request: httpReq,
206
- httpClient: this.httpClient,
207
- logger: this.logger,
208
- });
209
- resp = parseResponse(respBody, unmarshalResultDataSchema);
210
- };
211
- await executeCall(call, options);
212
- if (resp === undefined) {
213
- throw new Error('operation completed without a result.');
214
- }
215
- return resp;
216
- }
217
-
218
- /**
219
- * This request can be used to poll for the statement's status. StatementResponse contains
220
- * `statement_id` and `status`; other fields might be absent or present depending on context.
221
- * When the `status.state` field is `SUCCEEDED` it will also return the result manifest and the
222
- * first chunk of the result data. When the statement is in the terminal states `CANCELED`,
223
- * `CLOSED` or `FAILED`, it returns HTTP 200 with the state set. After at least 12 hours in
224
- * terminal state, the statement is removed from the warehouse and further calls will receive an
225
- * HTTP 404 response.
226
- *
227
- * **NOTE**
228
- * This call currently might take up to 5 seconds to get the latest status and result.
229
- */
230
- async getStatementResult(
231
- req: GetStatementResultRequest,
232
- options?: CallOptions
233
- ): Promise<StatementResponse> {
234
- const url = `${this.host}/api/2.0/sql/statements/${req.statementId ?? ''}`;
235
- let resp: StatementResponse | undefined;
236
- const call = async (callSignal?: AbortSignal): Promise<void> => {
237
- const headers = new Headers();
238
- if (this.workspaceId !== undefined) {
239
- headers.set('X-Databricks-Org-Id', this.workspaceId);
240
- }
241
- headers.set('User-Agent', this.userAgent);
242
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
243
- const respBody = await executeHttpCall({
244
- request: httpReq,
245
- httpClient: this.httpClient,
246
- logger: this.logger,
247
- });
248
- resp = parseResponse(respBody, unmarshalStatementResponseSchema);
249
- };
250
- await executeCall(call, options);
251
- if (resp === undefined) {
252
- throw new Error('operation completed without a result.');
253
- }
254
- return resp;
255
- }
256
- }
package/src/v1/index.ts DELETED
@@ -1,32 +0,0 @@
1
- // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
-
3
- export {StatementExecutionClient} from './client';
4
-
5
- export {
6
- ColumnTypeName,
7
- Disposition,
8
- Format,
9
- ServiceErrorCode,
10
- TimeoutAction,
11
- StatementStatus_State,
12
- } from './model';
13
-
14
- export type {
15
- CancelStatementRequest,
16
- CancelStatementResponse,
17
- ChunkInfo,
18
- ColumnInfo,
19
- ExecuteStatementRequest,
20
- ExternalLink,
21
- ExternalLink_HttpHeadersEntry,
22
- GetResultDataRequest,
23
- GetStatementResultRequest,
24
- QueryTag,
25
- ResultData,
26
- ResultManifest,
27
- Schema,
28
- ServiceError,
29
- StatementParameter,
30
- StatementResponse,
31
- StatementStatus,
32
- } from './model';