@databricks/sql 1.8.4 → 1.10.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/dist/DBSQLClient.d.ts +8 -5
- package/dist/DBSQLClient.js +78 -83
- package/dist/DBSQLClient.js.map +1 -1
- package/dist/DBSQLLogger.js +2 -13
- package/dist/DBSQLLogger.js.map +1 -1
- package/dist/DBSQLOperation.d.ts +6 -1
- package/dist/DBSQLOperation.js +223 -234
- package/dist/DBSQLOperation.js.map +1 -1
- package/dist/DBSQLSession.d.ts +2 -0
- package/dist/DBSQLSession.js +276 -229
- package/dist/DBSQLSession.js.map +1 -1
- package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.d.ts +7 -2
- package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js +91 -104
- package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js.map +1 -1
- package/dist/connection/auth/DatabricksOAuth/OAuthManager.js +114 -134
- package/dist/connection/auth/DatabricksOAuth/OAuthManager.js.map +1 -1
- package/dist/connection/auth/DatabricksOAuth/OAuthPersistence.js +4 -17
- package/dist/connection/auth/DatabricksOAuth/OAuthPersistence.js.map +1 -1
- package/dist/connection/auth/DatabricksOAuth/index.d.ts +3 -2
- package/dist/connection/auth/DatabricksOAuth/index.js +19 -22
- package/dist/connection/auth/DatabricksOAuth/index.js.map +1 -1
- package/dist/connection/auth/PlainHttpAuthentication.js +5 -13
- package/dist/connection/auth/PlainHttpAuthentication.js.map +1 -1
- package/dist/connection/connections/HttpConnection.d.ts +1 -1
- package/dist/connection/connections/HttpConnection.js +49 -46
- package/dist/connection/connections/HttpConnection.js.map +1 -1
- package/dist/connection/connections/HttpRetryPolicy.d.ts +1 -1
- package/dist/connection/connections/HttpRetryPolicy.js +28 -41
- package/dist/connection/connections/HttpRetryPolicy.js.map +1 -1
- package/dist/connection/connections/NullRetryPolicy.js +5 -18
- package/dist/connection/connections/NullRetryPolicy.js.map +1 -1
- package/dist/connection/connections/ThriftHttpConnection.js +22 -20
- package/dist/connection/connections/ThriftHttpConnection.js.map +1 -1
- package/dist/connection/contracts/IConnectionProvider.d.ts +1 -1
- package/dist/contracts/IClientContext.d.ts +4 -2
- package/dist/contracts/IDBSQLClient.d.ts +1 -1
- package/dist/contracts/IDBSQLSession.d.ts +17 -13
- package/dist/contracts/IOperation.d.ts +19 -0
- package/dist/contracts/IThriftClient.d.ts +8 -0
- package/dist/contracts/IThriftClient.js +3 -0
- package/dist/contracts/IThriftClient.js.map +1 -0
- package/dist/dto/InfoValue.d.ts +1 -2
- package/dist/hive/Commands/BaseCommand.d.ts +3 -4
- package/dist/hive/Commands/BaseCommand.js +22 -33
- package/dist/hive/Commands/BaseCommand.js.map +1 -1
- package/dist/hive/Commands/CancelDelegationTokenCommand.d.ts +4 -1
- package/dist/hive/Commands/CancelDelegationTokenCommand.js.map +1 -1
- package/dist/hive/Commands/CancelOperationCommand.d.ts +4 -1
- package/dist/hive/Commands/CancelOperationCommand.js.map +1 -1
- package/dist/hive/Commands/CloseOperationCommand.d.ts +4 -1
- package/dist/hive/Commands/CloseOperationCommand.js.map +1 -1
- package/dist/hive/Commands/CloseSessionCommand.d.ts +4 -1
- package/dist/hive/Commands/CloseSessionCommand.js.map +1 -1
- package/dist/hive/Commands/ExecuteStatementCommand.d.ts +4 -1
- package/dist/hive/Commands/ExecuteStatementCommand.js.map +1 -1
- package/dist/hive/Commands/FetchResultsCommand.d.ts +4 -1
- package/dist/hive/Commands/FetchResultsCommand.js.map +1 -1
- package/dist/hive/Commands/GetCatalogsCommand.d.ts +4 -1
- package/dist/hive/Commands/GetCatalogsCommand.js.map +1 -1
- package/dist/hive/Commands/GetColumnsCommand.d.ts +4 -1
- package/dist/hive/Commands/GetColumnsCommand.js.map +1 -1
- package/dist/hive/Commands/GetCrossReferenceCommand.d.ts +4 -1
- package/dist/hive/Commands/GetCrossReferenceCommand.js.map +1 -1
- package/dist/hive/Commands/GetDelegationTokenCommand.d.ts +4 -1
- package/dist/hive/Commands/GetDelegationTokenCommand.js.map +1 -1
- package/dist/hive/Commands/GetFunctionsCommand.d.ts +4 -1
- package/dist/hive/Commands/GetFunctionsCommand.js.map +1 -1
- package/dist/hive/Commands/GetInfoCommand.d.ts +4 -1
- package/dist/hive/Commands/GetInfoCommand.js.map +1 -1
- package/dist/hive/Commands/GetOperationStatusCommand.d.ts +4 -1
- package/dist/hive/Commands/GetOperationStatusCommand.js.map +1 -1
- package/dist/hive/Commands/GetPrimaryKeysCommand.d.ts +4 -1
- package/dist/hive/Commands/GetPrimaryKeysCommand.js.map +1 -1
- package/dist/hive/Commands/GetResultSetMetadataCommand.d.ts +4 -1
- package/dist/hive/Commands/GetResultSetMetadataCommand.js.map +1 -1
- package/dist/hive/Commands/GetSchemasCommand.d.ts +4 -1
- package/dist/hive/Commands/GetSchemasCommand.js.map +1 -1
- package/dist/hive/Commands/GetTableTypesCommand.d.ts +4 -1
- package/dist/hive/Commands/GetTableTypesCommand.js.map +1 -1
- package/dist/hive/Commands/GetTablesCommand.d.ts +4 -1
- package/dist/hive/Commands/GetTablesCommand.js.map +1 -1
- package/dist/hive/Commands/GetTypeInfoCommand.d.ts +4 -1
- package/dist/hive/Commands/GetTypeInfoCommand.js.map +1 -1
- package/dist/hive/Commands/OpenSessionCommand.d.ts +4 -1
- package/dist/hive/Commands/OpenSessionCommand.js.map +1 -1
- package/dist/hive/Commands/RenewDelegationTokenCommand.d.ts +4 -1
- package/dist/hive/Commands/RenewDelegationTokenCommand.js.map +1 -1
- package/dist/hive/HiveDriver.js +104 -155
- package/dist/hive/HiveDriver.js.map +1 -1
- package/dist/polyfills.d.ts +1 -1
- package/dist/polyfills.js +1 -1
- package/dist/polyfills.js.map +1 -1
- package/dist/result/ArrowResultConverter.d.ts +1 -1
- package/dist/result/ArrowResultConverter.js +69 -84
- package/dist/result/ArrowResultConverter.js.map +1 -1
- package/dist/result/ArrowResultHandler.d.ts +1 -1
- package/dist/result/ArrowResultHandler.js +28 -41
- package/dist/result/ArrowResultHandler.js.map +1 -1
- package/dist/result/CloudFetchResultHandler.d.ts +1 -1
- package/dist/result/CloudFetchResultHandler.js +48 -65
- package/dist/result/CloudFetchResultHandler.js.map +1 -1
- package/dist/result/JsonResultHandler.d.ts +0 -1
- package/dist/result/JsonResultHandler.js +14 -41
- package/dist/result/JsonResultHandler.js.map +1 -1
- package/dist/result/ResultSlicer.js +40 -53
- package/dist/result/ResultSlicer.js.map +1 -1
- package/dist/result/RowSetProvider.d.ts +4 -0
- package/dist/result/RowSetProvider.js +42 -59
- package/dist/result/RowSetProvider.js.map +1 -1
- package/dist/result/utils.d.ts +2 -1
- package/dist/result/utils.js +9 -1
- package/dist/result/utils.js.map +1 -1
- package/dist/utils/CloseableCollection.js +7 -18
- package/dist/utils/CloseableCollection.js.map +1 -1
- package/dist/utils/OperationIterator.d.ts +23 -0
- package/dist/utils/OperationIterator.js +71 -0
- package/dist/utils/OperationIterator.js.map +1 -0
- package/dist/utils/buildUserAgentString.d.ts +1 -1
- package/dist/utils/buildUserAgentString.js +14 -2
- package/dist/utils/buildUserAgentString.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +12 -7
- package/thrift/TCLIService.d.ts +0 -42
- package/dist/hive/Types/index.d.ts +0 -18
- package/dist/hive/Types/index.js +0 -25
- package/dist/hive/Types/index.js.map +0 -1
package/dist/DBSQLSession.js
CHANGED
|
@@ -22,26 +22,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
27
|
};
|
|
37
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.numberToInt64 = void 0;
|
|
38
30
|
const fs = __importStar(require("fs"));
|
|
39
31
|
const path = __importStar(require("path"));
|
|
40
32
|
const node_stream_1 = __importDefault(require("node:stream"));
|
|
41
33
|
const node_util_1 = __importDefault(require("node:util"));
|
|
42
34
|
const uuid_1 = require("uuid");
|
|
35
|
+
const node_int64_1 = __importDefault(require("node-int64"));
|
|
43
36
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
44
|
-
const Types_1 = require("./hive/Types");
|
|
45
37
|
const DBSQLOperation_1 = __importDefault(require("./DBSQLOperation"));
|
|
46
38
|
const Status_1 = __importDefault(require("./dto/Status"));
|
|
47
39
|
const InfoValue_1 = __importDefault(require("./dto/InfoValue"));
|
|
@@ -54,14 +46,26 @@ const DBSQLParameter_1 = require("./DBSQLParameter");
|
|
|
54
46
|
const ParameterError_1 = __importDefault(require("./errors/ParameterError"));
|
|
55
47
|
// Explicitly promisify a callback-style `pipeline` because `node:stream/promises` is not available in Node 14
|
|
56
48
|
const pipeline = node_util_1.default.promisify(node_stream_1.default.pipeline);
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
function numberToInt64(value) {
|
|
50
|
+
if (value instanceof node_int64_1.default) {
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
if (typeof value === 'bigint') {
|
|
54
|
+
const buffer = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT);
|
|
55
|
+
const view = new DataView(buffer);
|
|
56
|
+
view.setBigInt64(0, value, false); // `false` to use big-endian order
|
|
57
|
+
return new node_int64_1.default(Buffer.from(buffer));
|
|
58
|
+
}
|
|
59
|
+
return new node_int64_1.default(value);
|
|
60
|
+
}
|
|
61
|
+
exports.numberToInt64 = numberToInt64;
|
|
62
|
+
function getDirectResultsOptions(maxRows, config) {
|
|
59
63
|
if (maxRows === null) {
|
|
60
64
|
return {};
|
|
61
65
|
}
|
|
62
66
|
return {
|
|
63
67
|
getDirectResults: {
|
|
64
|
-
maxRows:
|
|
68
|
+
maxRows: numberToInt64(maxRows !== null && maxRows !== void 0 ? maxRows : config.directResultsDefaultMaxRows),
|
|
65
69
|
},
|
|
66
70
|
};
|
|
67
71
|
}
|
|
@@ -83,7 +87,7 @@ function getArrowOptions(config) {
|
|
|
83
87
|
},
|
|
84
88
|
};
|
|
85
89
|
}
|
|
86
|
-
function getQueryParameters(
|
|
90
|
+
function getQueryParameters(namedParameters, ordinalParameters) {
|
|
87
91
|
const namedParametersProvided = namedParameters !== undefined && Object.keys(namedParameters).length > 0;
|
|
88
92
|
const ordinalParametersProvided = ordinalParameters !== undefined && ordinalParameters.length > 0;
|
|
89
93
|
if (namedParametersProvided && ordinalParametersProvided) {
|
|
@@ -129,18 +133,16 @@ class DBSQLSession {
|
|
|
129
133
|
* @example
|
|
130
134
|
* const response = await session.getInfo(thrift.TCLIService_types.TGetInfoType.CLI_DBMS_VER);
|
|
131
135
|
*/
|
|
132
|
-
getInfo(infoType) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
infoType,
|
|
139
|
-
});
|
|
140
|
-
const response = yield this.handleResponse(operationPromise);
|
|
141
|
-
Status_1.default.assert(response.status);
|
|
142
|
-
return new InfoValue_1.default(response.infoValue);
|
|
136
|
+
async getInfo(infoType) {
|
|
137
|
+
await this.failIfClosed();
|
|
138
|
+
const driver = await this.context.getDriver();
|
|
139
|
+
const operationPromise = driver.getInfo({
|
|
140
|
+
sessionHandle: this.sessionHandle,
|
|
141
|
+
infoType,
|
|
143
142
|
});
|
|
143
|
+
const response = await this.handleResponse(operationPromise);
|
|
144
|
+
Status_1.default.assert(response.status);
|
|
145
|
+
return new InfoValue_1.default(response.infoValue);
|
|
144
146
|
}
|
|
145
147
|
/**
|
|
146
148
|
* Executes statement
|
|
@@ -151,124 +153,126 @@ class DBSQLSession {
|
|
|
151
153
|
* @example
|
|
152
154
|
* const operation = await session.executeStatement(query);
|
|
153
155
|
*/
|
|
154
|
-
executeStatement(statement, options = {}) {
|
|
156
|
+
async executeStatement(statement, options = {}) {
|
|
155
157
|
var _a;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
// other query - it will be possible to get data from it as usual, or use other operation methods.
|
|
170
|
-
if (options.stagingAllowedLocalPath !== undefined) {
|
|
171
|
-
const metadata = yield operation.getMetadata();
|
|
172
|
-
if (metadata.isStagingOperation) {
|
|
173
|
-
const allowedLocalPath = Array.isArray(options.stagingAllowedLocalPath)
|
|
174
|
-
? options.stagingAllowedLocalPath
|
|
175
|
-
: [options.stagingAllowedLocalPath];
|
|
176
|
-
return this.handleStagingOperation(operation, allowedLocalPath);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return operation;
|
|
158
|
+
await this.failIfClosed();
|
|
159
|
+
const driver = await this.context.getDriver();
|
|
160
|
+
const clientConfig = this.context.getConfig();
|
|
161
|
+
const operationPromise = driver.executeStatement({
|
|
162
|
+
sessionHandle: this.sessionHandle,
|
|
163
|
+
statement,
|
|
164
|
+
queryTimeout: options.queryTimeout ? numberToInt64(options.queryTimeout) : undefined,
|
|
165
|
+
runAsync: true,
|
|
166
|
+
...getDirectResultsOptions(options.maxRows, clientConfig),
|
|
167
|
+
...getArrowOptions(clientConfig),
|
|
168
|
+
canDownloadResult: (_a = options.useCloudFetch) !== null && _a !== void 0 ? _a : clientConfig.useCloudFetch,
|
|
169
|
+
parameters: getQueryParameters(options.namedParameters, options.ordinalParameters),
|
|
170
|
+
canDecompressLZ4Result: clientConfig.useLZ4Compression && Boolean(utils_1.LZ4),
|
|
180
171
|
});
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
172
|
+
const response = await this.handleResponse(operationPromise);
|
|
173
|
+
const operation = this.createOperation(response);
|
|
174
|
+
// If `stagingAllowedLocalPath` is provided - assume that operation possibly may be a staging operation.
|
|
175
|
+
// To know for sure, fetch metadata and check a `isStagingOperation` flag. If it happens that it wasn't
|
|
176
|
+
// a staging operation - not a big deal, we just fetched metadata earlier, but operation is still usable
|
|
177
|
+
// and user can get data from it.
|
|
178
|
+
// If `stagingAllowedLocalPath` is not provided - don't do anything to the operation. In a case of regular
|
|
179
|
+
// operation, everything will work as usual. In a case of staging operation, it will be processed like any
|
|
180
|
+
// other query - it will be possible to get data from it as usual, or use other operation methods.
|
|
181
|
+
if (options.stagingAllowedLocalPath !== undefined) {
|
|
182
|
+
const metadata = await operation.getMetadata();
|
|
183
|
+
if (metadata.isStagingOperation) {
|
|
184
|
+
const allowedLocalPath = Array.isArray(options.stagingAllowedLocalPath)
|
|
185
|
+
? options.stagingAllowedLocalPath
|
|
186
|
+
: [options.stagingAllowedLocalPath];
|
|
187
|
+
return this.handleStagingOperation(operation, allowedLocalPath);
|
|
187
188
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
189
|
+
}
|
|
190
|
+
return operation;
|
|
191
|
+
}
|
|
192
|
+
async handleStagingOperation(operation, allowedLocalPath) {
|
|
193
|
+
const rows = await operation.fetchAll();
|
|
194
|
+
if (rows.length !== 1) {
|
|
195
|
+
throw new StagingError_1.default('Staging operation: expected only one row in result');
|
|
196
|
+
}
|
|
197
|
+
const row = rows[0];
|
|
198
|
+
// For REMOVE operation local file is not available, so no need to validate it
|
|
199
|
+
if (row.localFile !== undefined) {
|
|
200
|
+
let allowOperation = false;
|
|
201
|
+
for (const filepath of allowedLocalPath) {
|
|
202
|
+
const relativePath = path.relative(filepath, row.localFile);
|
|
203
|
+
if (!relativePath.startsWith('..') && !path.isAbsolute(relativePath)) {
|
|
204
|
+
allowOperation = true;
|
|
200
205
|
}
|
|
201
206
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
case 'GET':
|
|
205
|
-
yield this.handleStagingGet(localFile, presignedUrl, headers);
|
|
206
|
-
return operation;
|
|
207
|
-
case 'PUT':
|
|
208
|
-
yield this.handleStagingPut(localFile, presignedUrl, headers);
|
|
209
|
-
return operation;
|
|
210
|
-
case 'REMOVE':
|
|
211
|
-
yield this.handleStagingRemove(presignedUrl, headers);
|
|
212
|
-
return operation;
|
|
213
|
-
default:
|
|
214
|
-
throw new StagingError_1.default(`Staging query operation is not supported: ${row.operation}`);
|
|
207
|
+
if (!allowOperation) {
|
|
208
|
+
throw new StagingError_1.default('Staging path not a subset of allowed local paths.');
|
|
215
209
|
}
|
|
216
|
-
}
|
|
210
|
+
}
|
|
211
|
+
const { localFile, presignedUrl, headers } = row;
|
|
212
|
+
switch (row.operation) {
|
|
213
|
+
case 'GET':
|
|
214
|
+
await this.handleStagingGet(localFile, presignedUrl, headers);
|
|
215
|
+
return operation;
|
|
216
|
+
case 'PUT':
|
|
217
|
+
await this.handleStagingPut(localFile, presignedUrl, headers);
|
|
218
|
+
return operation;
|
|
219
|
+
case 'REMOVE':
|
|
220
|
+
await this.handleStagingRemove(presignedUrl, headers);
|
|
221
|
+
return operation;
|
|
222
|
+
default:
|
|
223
|
+
throw new StagingError_1.default(`Staging query operation is not supported: ${row.operation}`);
|
|
224
|
+
}
|
|
217
225
|
}
|
|
218
|
-
handleStagingGet(localFile, presignedUrl, headers) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return pipeline(response.body, fileStream);
|
|
232
|
-
});
|
|
226
|
+
async handleStagingGet(localFile, presignedUrl, headers) {
|
|
227
|
+
if (localFile === undefined) {
|
|
228
|
+
throw new StagingError_1.default('Local file path not provided');
|
|
229
|
+
}
|
|
230
|
+
const connectionProvider = await this.context.getConnectionProvider();
|
|
231
|
+
const agent = await connectionProvider.getAgent();
|
|
232
|
+
const response = await (0, node_fetch_1.default)(presignedUrl, { method: 'GET', headers, agent });
|
|
233
|
+
if (!response.ok) {
|
|
234
|
+
throw new StagingError_1.default(`HTTP error ${response.status} ${response.statusText}`);
|
|
235
|
+
}
|
|
236
|
+
const fileStream = fs.createWriteStream(localFile);
|
|
237
|
+
// `pipeline` will do all the dirty job for us, including error handling and closing all the streams properly
|
|
238
|
+
return pipeline(response.body, fileStream);
|
|
233
239
|
}
|
|
234
|
-
handleStagingRemove(presignedUrl, headers) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
});
|
|
240
|
+
async handleStagingRemove(presignedUrl, headers) {
|
|
241
|
+
const connectionProvider = await this.context.getConnectionProvider();
|
|
242
|
+
const agent = await connectionProvider.getAgent();
|
|
243
|
+
const response = await (0, node_fetch_1.default)(presignedUrl, { method: 'DELETE', headers, agent });
|
|
244
|
+
// Looks that AWS and Azure have a different behavior of HTTP `DELETE` for non-existing files.
|
|
245
|
+
// AWS assumes that - since file already doesn't exist - the goal is achieved, and returns HTTP 200.
|
|
246
|
+
// Azure, on the other hand, is somewhat stricter and check if file exists before deleting it. And if
|
|
247
|
+
// file doesn't exist - Azure returns HTTP 404.
|
|
248
|
+
//
|
|
249
|
+
// For us, it's totally okay if file didn't exist before removing. So when we get an HTTP 404 -
|
|
250
|
+
// just ignore it and report success. This way we can have a uniform library behavior for all clouds
|
|
251
|
+
if (!response.ok && response.status !== 404) {
|
|
252
|
+
throw new StagingError_1.default(`HTTP error ${response.status} ${response.statusText}`);
|
|
253
|
+
}
|
|
250
254
|
}
|
|
251
|
-
handleStagingPut(localFile, presignedUrl, headers) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
headers
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (!response.ok) {
|
|
269
|
-
throw new StagingError_1.default(`HTTP error ${response.status} ${response.statusText}`);
|
|
270
|
-
}
|
|
255
|
+
async handleStagingPut(localFile, presignedUrl, headers) {
|
|
256
|
+
if (localFile === undefined) {
|
|
257
|
+
throw new StagingError_1.default('Local file path not provided');
|
|
258
|
+
}
|
|
259
|
+
const connectionProvider = await this.context.getConnectionProvider();
|
|
260
|
+
const agent = await connectionProvider.getAgent();
|
|
261
|
+
const fileStream = fs.createReadStream(localFile);
|
|
262
|
+
const fileInfo = fs.statSync(localFile, { bigint: true });
|
|
263
|
+
const response = await (0, node_fetch_1.default)(presignedUrl, {
|
|
264
|
+
method: 'PUT',
|
|
265
|
+
headers: {
|
|
266
|
+
...headers,
|
|
267
|
+
// This header is required by server
|
|
268
|
+
'Content-Length': fileInfo.size.toString(),
|
|
269
|
+
},
|
|
270
|
+
agent,
|
|
271
|
+
body: fileStream,
|
|
271
272
|
});
|
|
273
|
+
if (!response.ok) {
|
|
274
|
+
throw new StagingError_1.default(`HTTP error ${response.status} ${response.statusText}`);
|
|
275
|
+
}
|
|
272
276
|
}
|
|
273
277
|
/**
|
|
274
278
|
* Information about supported data types
|
|
@@ -276,14 +280,17 @@ class DBSQLSession {
|
|
|
276
280
|
* @param request
|
|
277
281
|
* @returns DBSQLOperation
|
|
278
282
|
*/
|
|
279
|
-
getTypeInfo(request = {}) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
283
|
+
async getTypeInfo(request = {}) {
|
|
284
|
+
await this.failIfClosed();
|
|
285
|
+
const driver = await this.context.getDriver();
|
|
286
|
+
const clientConfig = this.context.getConfig();
|
|
287
|
+
const operationPromise = driver.getTypeInfo({
|
|
288
|
+
sessionHandle: this.sessionHandle,
|
|
289
|
+
runAsync: true,
|
|
290
|
+
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
286
291
|
});
|
|
292
|
+
const response = await this.handleResponse(operationPromise);
|
|
293
|
+
return this.createOperation(response);
|
|
287
294
|
}
|
|
288
295
|
/**
|
|
289
296
|
* Get list of catalogs
|
|
@@ -291,14 +298,17 @@ class DBSQLSession {
|
|
|
291
298
|
* @param request
|
|
292
299
|
* @returns DBSQLOperation
|
|
293
300
|
*/
|
|
294
|
-
getCatalogs(request = {}) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
+
async getCatalogs(request = {}) {
|
|
302
|
+
await this.failIfClosed();
|
|
303
|
+
const driver = await this.context.getDriver();
|
|
304
|
+
const clientConfig = this.context.getConfig();
|
|
305
|
+
const operationPromise = driver.getCatalogs({
|
|
306
|
+
sessionHandle: this.sessionHandle,
|
|
307
|
+
runAsync: true,
|
|
308
|
+
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
301
309
|
});
|
|
310
|
+
const response = await this.handleResponse(operationPromise);
|
|
311
|
+
return this.createOperation(response);
|
|
302
312
|
}
|
|
303
313
|
/**
|
|
304
314
|
* Get list of schemas
|
|
@@ -306,14 +316,19 @@ class DBSQLSession {
|
|
|
306
316
|
* @param request
|
|
307
317
|
* @returns DBSQLOperation
|
|
308
318
|
*/
|
|
309
|
-
getSchemas(request = {}) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
319
|
+
async getSchemas(request = {}) {
|
|
320
|
+
await this.failIfClosed();
|
|
321
|
+
const driver = await this.context.getDriver();
|
|
322
|
+
const clientConfig = this.context.getConfig();
|
|
323
|
+
const operationPromise = driver.getSchemas({
|
|
324
|
+
sessionHandle: this.sessionHandle,
|
|
325
|
+
catalogName: request.catalogName,
|
|
326
|
+
schemaName: request.schemaName,
|
|
327
|
+
runAsync: true,
|
|
328
|
+
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
316
329
|
});
|
|
330
|
+
const response = await this.handleResponse(operationPromise);
|
|
331
|
+
return this.createOperation(response);
|
|
317
332
|
}
|
|
318
333
|
/**
|
|
319
334
|
* Get list of tables
|
|
@@ -321,14 +336,21 @@ class DBSQLSession {
|
|
|
321
336
|
* @param request
|
|
322
337
|
* @returns DBSQLOperation
|
|
323
338
|
*/
|
|
324
|
-
getTables(request = {}) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
339
|
+
async getTables(request = {}) {
|
|
340
|
+
await this.failIfClosed();
|
|
341
|
+
const driver = await this.context.getDriver();
|
|
342
|
+
const clientConfig = this.context.getConfig();
|
|
343
|
+
const operationPromise = driver.getTables({
|
|
344
|
+
sessionHandle: this.sessionHandle,
|
|
345
|
+
catalogName: request.catalogName,
|
|
346
|
+
schemaName: request.schemaName,
|
|
347
|
+
tableName: request.tableName,
|
|
348
|
+
tableTypes: request.tableTypes,
|
|
349
|
+
runAsync: true,
|
|
350
|
+
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
331
351
|
});
|
|
352
|
+
const response = await this.handleResponse(operationPromise);
|
|
353
|
+
return this.createOperation(response);
|
|
332
354
|
}
|
|
333
355
|
/**
|
|
334
356
|
* Get list of supported table types
|
|
@@ -336,14 +358,17 @@ class DBSQLSession {
|
|
|
336
358
|
* @param request
|
|
337
359
|
* @returns DBSQLOperation
|
|
338
360
|
*/
|
|
339
|
-
getTableTypes(request = {}) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
361
|
+
async getTableTypes(request = {}) {
|
|
362
|
+
await this.failIfClosed();
|
|
363
|
+
const driver = await this.context.getDriver();
|
|
364
|
+
const clientConfig = this.context.getConfig();
|
|
365
|
+
const operationPromise = driver.getTableTypes({
|
|
366
|
+
sessionHandle: this.sessionHandle,
|
|
367
|
+
runAsync: true,
|
|
368
|
+
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
346
369
|
});
|
|
370
|
+
const response = await this.handleResponse(operationPromise);
|
|
371
|
+
return this.createOperation(response);
|
|
347
372
|
}
|
|
348
373
|
/**
|
|
349
374
|
* Get full information about columns of the table
|
|
@@ -351,14 +376,21 @@ class DBSQLSession {
|
|
|
351
376
|
* @param request
|
|
352
377
|
* @returns DBSQLOperation
|
|
353
378
|
*/
|
|
354
|
-
getColumns(request = {}) {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
379
|
+
async getColumns(request = {}) {
|
|
380
|
+
await this.failIfClosed();
|
|
381
|
+
const driver = await this.context.getDriver();
|
|
382
|
+
const clientConfig = this.context.getConfig();
|
|
383
|
+
const operationPromise = driver.getColumns({
|
|
384
|
+
sessionHandle: this.sessionHandle,
|
|
385
|
+
catalogName: request.catalogName,
|
|
386
|
+
schemaName: request.schemaName,
|
|
387
|
+
tableName: request.tableName,
|
|
388
|
+
columnName: request.columnName,
|
|
389
|
+
runAsync: true,
|
|
390
|
+
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
361
391
|
});
|
|
392
|
+
const response = await this.handleResponse(operationPromise);
|
|
393
|
+
return this.createOperation(response);
|
|
362
394
|
}
|
|
363
395
|
/**
|
|
364
396
|
* Get information about function
|
|
@@ -366,23 +398,35 @@ class DBSQLSession {
|
|
|
366
398
|
* @param request
|
|
367
399
|
* @returns DBSQLOperation
|
|
368
400
|
*/
|
|
369
|
-
getFunctions(request) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
401
|
+
async getFunctions(request) {
|
|
402
|
+
await this.failIfClosed();
|
|
403
|
+
const driver = await this.context.getDriver();
|
|
404
|
+
const clientConfig = this.context.getConfig();
|
|
405
|
+
const operationPromise = driver.getFunctions({
|
|
406
|
+
sessionHandle: this.sessionHandle,
|
|
407
|
+
catalogName: request.catalogName,
|
|
408
|
+
schemaName: request.schemaName,
|
|
409
|
+
functionName: request.functionName,
|
|
410
|
+
runAsync: true,
|
|
411
|
+
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
376
412
|
});
|
|
413
|
+
const response = await this.handleResponse(operationPromise);
|
|
414
|
+
return this.createOperation(response);
|
|
377
415
|
}
|
|
378
|
-
getPrimaryKeys(request) {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
416
|
+
async getPrimaryKeys(request) {
|
|
417
|
+
await this.failIfClosed();
|
|
418
|
+
const driver = await this.context.getDriver();
|
|
419
|
+
const clientConfig = this.context.getConfig();
|
|
420
|
+
const operationPromise = driver.getPrimaryKeys({
|
|
421
|
+
sessionHandle: this.sessionHandle,
|
|
422
|
+
catalogName: request.catalogName,
|
|
423
|
+
schemaName: request.schemaName,
|
|
424
|
+
tableName: request.tableName,
|
|
425
|
+
runAsync: true,
|
|
426
|
+
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
385
427
|
});
|
|
428
|
+
const response = await this.handleResponse(operationPromise);
|
|
429
|
+
return this.createOperation(response);
|
|
386
430
|
}
|
|
387
431
|
/**
|
|
388
432
|
* Request information about foreign keys between two tables
|
|
@@ -390,40 +434,47 @@ class DBSQLSession {
|
|
|
390
434
|
* @param request
|
|
391
435
|
* @returns DBSQLOperation
|
|
392
436
|
*/
|
|
393
|
-
getCrossReference(request) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
437
|
+
async getCrossReference(request) {
|
|
438
|
+
await this.failIfClosed();
|
|
439
|
+
const driver = await this.context.getDriver();
|
|
440
|
+
const clientConfig = this.context.getConfig();
|
|
441
|
+
const operationPromise = driver.getCrossReference({
|
|
442
|
+
sessionHandle: this.sessionHandle,
|
|
443
|
+
parentCatalogName: request.parentCatalogName,
|
|
444
|
+
parentSchemaName: request.parentSchemaName,
|
|
445
|
+
parentTableName: request.parentTableName,
|
|
446
|
+
foreignCatalogName: request.foreignCatalogName,
|
|
447
|
+
foreignSchemaName: request.foreignSchemaName,
|
|
448
|
+
foreignTableName: request.foreignTableName,
|
|
449
|
+
runAsync: true,
|
|
450
|
+
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
400
451
|
});
|
|
452
|
+
const response = await this.handleResponse(operationPromise);
|
|
453
|
+
return this.createOperation(response);
|
|
401
454
|
}
|
|
402
455
|
/**
|
|
403
456
|
* Closes the session
|
|
404
457
|
* @public
|
|
405
458
|
* @returns Operation status
|
|
406
459
|
*/
|
|
407
|
-
close() {
|
|
460
|
+
async close() {
|
|
408
461
|
var _a;
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
sessionHandle: this.sessionHandle,
|
|
418
|
-
});
|
|
419
|
-
// check status for being successful
|
|
420
|
-
Status_1.default.assert(response.status);
|
|
421
|
-
// notify owner connection
|
|
422
|
-
(_a = this.onClose) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
423
|
-
this.isOpen = false;
|
|
424
|
-
this.context.getLogger().log(IDBSQLLogger_1.LogLevel.debug, `Session closed with id: ${this.id}`);
|
|
425
|
-
return new Status_1.default(response.status);
|
|
462
|
+
if (!this.isOpen) {
|
|
463
|
+
return Status_1.default.success();
|
|
464
|
+
}
|
|
465
|
+
// Close owned operations one by one, removing successfully closed ones from the list
|
|
466
|
+
await this.operations.closeAll();
|
|
467
|
+
const driver = await this.context.getDriver();
|
|
468
|
+
const response = await driver.closeSession({
|
|
469
|
+
sessionHandle: this.sessionHandle,
|
|
426
470
|
});
|
|
471
|
+
// check status for being successful
|
|
472
|
+
Status_1.default.assert(response.status);
|
|
473
|
+
// notify owner connection
|
|
474
|
+
(_a = this.onClose) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
475
|
+
this.isOpen = false;
|
|
476
|
+
this.context.getLogger().log(IDBSQLLogger_1.LogLevel.debug, `Session closed with id: ${this.id}`);
|
|
477
|
+
return new Status_1.default(response.status);
|
|
427
478
|
}
|
|
428
479
|
createOperation(response) {
|
|
429
480
|
Status_1.default.assert(response.status);
|
|
@@ -436,22 +487,18 @@ class DBSQLSession {
|
|
|
436
487
|
this.operations.add(operation);
|
|
437
488
|
return operation;
|
|
438
489
|
}
|
|
439
|
-
failIfClosed() {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
});
|
|
490
|
+
async failIfClosed() {
|
|
491
|
+
if (!this.isOpen) {
|
|
492
|
+
throw new HiveDriverError_1.default('The session was closed or has expired');
|
|
493
|
+
}
|
|
445
494
|
}
|
|
446
|
-
handleResponse(requestPromise) {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
return result;
|
|
454
|
-
});
|
|
495
|
+
async handleResponse(requestPromise) {
|
|
496
|
+
// Currently, after being closed sessions remains usable - server will not
|
|
497
|
+
// error out when trying to run operations on closed session. So it's
|
|
498
|
+
// basically useless to process any errors here
|
|
499
|
+
const result = await requestPromise;
|
|
500
|
+
await this.failIfClosed();
|
|
501
|
+
return result;
|
|
455
502
|
}
|
|
456
503
|
}
|
|
457
504
|
exports.default = DBSQLSession;
|