@databricks/sql 1.8.3 → 1.9.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/README.md +4 -8
- package/dist/DBSQLClient.d.ts +8 -5
- package/dist/DBSQLClient.js +70 -82
- 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 +7 -2
- package/dist/DBSQLOperation.js +227 -237
- package/dist/DBSQLOperation.js.map +1 -1
- package/dist/DBSQLSession.d.ts +3 -1
- package/dist/DBSQLSession.js +284 -220
- 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 -47
- 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/IDBSQLSession.d.ts +21 -13
- package/dist/contracts/IOperation.d.ts +23 -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 +3 -2
- 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 +33 -42
- package/dist/result/ArrowResultHandler.js.map +1 -1
- package/dist/result/CloudFetchResultHandler.d.ts +1 -1
- package/dist/result/CloudFetchResultHandler.js +53 -66
- 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/index.d.ts +2 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/lz4.d.ts +3 -0
- package/dist/utils/lz4.js +15 -0
- package/dist/utils/lz4.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +15 -8
- 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,24 +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"));
|
|
32
|
+
const node_stream_1 = __importDefault(require("node:stream"));
|
|
33
|
+
const node_util_1 = __importDefault(require("node:util"));
|
|
40
34
|
const uuid_1 = require("uuid");
|
|
35
|
+
const node_int64_1 = __importDefault(require("node-int64"));
|
|
41
36
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
42
|
-
const Types_1 = require("./hive/Types");
|
|
43
37
|
const DBSQLOperation_1 = __importDefault(require("./DBSQLOperation"));
|
|
44
38
|
const Status_1 = __importDefault(require("./dto/Status"));
|
|
45
39
|
const InfoValue_1 = __importDefault(require("./dto/InfoValue"));
|
|
@@ -50,14 +44,28 @@ const HiveDriverError_1 = __importDefault(require("./errors/HiveDriverError"));
|
|
|
50
44
|
const StagingError_1 = __importDefault(require("./errors/StagingError"));
|
|
51
45
|
const DBSQLParameter_1 = require("./DBSQLParameter");
|
|
52
46
|
const ParameterError_1 = __importDefault(require("./errors/ParameterError"));
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
// Explicitly promisify a callback-style `pipeline` because `node:stream/promises` is not available in Node 14
|
|
48
|
+
const pipeline = node_util_1.default.promisify(node_stream_1.default.pipeline);
|
|
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) {
|
|
55
63
|
if (maxRows === null) {
|
|
56
64
|
return {};
|
|
57
65
|
}
|
|
58
66
|
return {
|
|
59
67
|
getDirectResults: {
|
|
60
|
-
maxRows:
|
|
68
|
+
maxRows: numberToInt64(maxRows !== null && maxRows !== void 0 ? maxRows : config.directResultsDefaultMaxRows),
|
|
61
69
|
},
|
|
62
70
|
};
|
|
63
71
|
}
|
|
@@ -79,7 +87,7 @@ function getArrowOptions(config) {
|
|
|
79
87
|
},
|
|
80
88
|
};
|
|
81
89
|
}
|
|
82
|
-
function getQueryParameters(
|
|
90
|
+
function getQueryParameters(namedParameters, ordinalParameters) {
|
|
83
91
|
const namedParametersProvided = namedParameters !== undefined && Object.keys(namedParameters).length > 0;
|
|
84
92
|
const ordinalParametersProvided = ordinalParameters !== undefined && ordinalParameters.length > 0;
|
|
85
93
|
if (namedParametersProvided && ordinalParametersProvided) {
|
|
@@ -110,11 +118,12 @@ class DBSQLSession {
|
|
|
110
118
|
this.operations = new CloseableCollection_1.default();
|
|
111
119
|
this.sessionHandle = handle;
|
|
112
120
|
this.context = context;
|
|
113
|
-
this.context.getLogger().log(IDBSQLLogger_1.LogLevel.debug, `Session created with id: ${this.
|
|
121
|
+
this.context.getLogger().log(IDBSQLLogger_1.LogLevel.debug, `Session created with id: ${this.id}`);
|
|
114
122
|
}
|
|
115
|
-
|
|
123
|
+
get id() {
|
|
116
124
|
var _a, _b;
|
|
117
|
-
|
|
125
|
+
const sessionId = (_b = (_a = this.sessionHandle) === null || _a === void 0 ? void 0 : _a.sessionId) === null || _b === void 0 ? void 0 : _b.guid;
|
|
126
|
+
return sessionId ? (0, uuid_1.stringify)(sessionId) : uuid_1.NIL;
|
|
118
127
|
}
|
|
119
128
|
/**
|
|
120
129
|
* Fetches info
|
|
@@ -124,18 +133,16 @@ class DBSQLSession {
|
|
|
124
133
|
* @example
|
|
125
134
|
* const response = await session.getInfo(thrift.TCLIService_types.TGetInfoType.CLI_DBMS_VER);
|
|
126
135
|
*/
|
|
127
|
-
getInfo(infoType) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
infoType,
|
|
134
|
-
});
|
|
135
|
-
const response = yield this.handleResponse(operationPromise);
|
|
136
|
-
Status_1.default.assert(response.status);
|
|
137
|
-
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,
|
|
138
142
|
});
|
|
143
|
+
const response = await this.handleResponse(operationPromise);
|
|
144
|
+
Status_1.default.assert(response.status);
|
|
145
|
+
return new InfoValue_1.default(response.infoValue);
|
|
139
146
|
}
|
|
140
147
|
/**
|
|
141
148
|
* Executes statement
|
|
@@ -146,112 +153,126 @@ class DBSQLSession {
|
|
|
146
153
|
* @example
|
|
147
154
|
* const operation = await session.executeStatement(query);
|
|
148
155
|
*/
|
|
149
|
-
executeStatement(statement, options = {}) {
|
|
156
|
+
async executeStatement(statement, options = {}) {
|
|
150
157
|
var _a;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
// other query - it will be possible to get data from it as usual, or use other operation methods.
|
|
165
|
-
if (options.stagingAllowedLocalPath !== undefined) {
|
|
166
|
-
const metadata = yield operation.getMetadata();
|
|
167
|
-
if (metadata.isStagingOperation) {
|
|
168
|
-
const allowedLocalPath = Array.isArray(options.stagingAllowedLocalPath)
|
|
169
|
-
? options.stagingAllowedLocalPath
|
|
170
|
-
: [options.stagingAllowedLocalPath];
|
|
171
|
-
return this.handleStagingOperation(operation, allowedLocalPath);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
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),
|
|
175
171
|
});
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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);
|
|
182
188
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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;
|
|
195
205
|
}
|
|
196
206
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
case 'GET':
|
|
200
|
-
yield this.handleStagingGet(localFile, presignedUrl, headers);
|
|
201
|
-
return operation;
|
|
202
|
-
case 'PUT':
|
|
203
|
-
yield this.handleStagingPut(localFile, presignedUrl, headers);
|
|
204
|
-
return operation;
|
|
205
|
-
case 'REMOVE':
|
|
206
|
-
yield this.handleStagingRemove(presignedUrl, headers);
|
|
207
|
-
return operation;
|
|
208
|
-
default:
|
|
209
|
-
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.');
|
|
210
209
|
}
|
|
211
|
-
}
|
|
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
|
+
}
|
|
212
225
|
}
|
|
213
|
-
handleStagingGet(localFile, presignedUrl, headers) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
});
|
|
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);
|
|
227
239
|
}
|
|
228
|
-
handleStagingRemove(presignedUrl, headers) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
+
}
|
|
241
254
|
}
|
|
242
|
-
handleStagingPut(localFile, presignedUrl, headers) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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,
|
|
254
272
|
});
|
|
273
|
+
if (!response.ok) {
|
|
274
|
+
throw new StagingError_1.default(`HTTP error ${response.status} ${response.statusText}`);
|
|
275
|
+
}
|
|
255
276
|
}
|
|
256
277
|
/**
|
|
257
278
|
* Information about supported data types
|
|
@@ -259,14 +280,17 @@ class DBSQLSession {
|
|
|
259
280
|
* @param request
|
|
260
281
|
* @returns DBSQLOperation
|
|
261
282
|
*/
|
|
262
|
-
getTypeInfo(request = {}) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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),
|
|
269
291
|
});
|
|
292
|
+
const response = await this.handleResponse(operationPromise);
|
|
293
|
+
return this.createOperation(response);
|
|
270
294
|
}
|
|
271
295
|
/**
|
|
272
296
|
* Get list of catalogs
|
|
@@ -274,14 +298,17 @@ class DBSQLSession {
|
|
|
274
298
|
* @param request
|
|
275
299
|
* @returns DBSQLOperation
|
|
276
300
|
*/
|
|
277
|
-
getCatalogs(request = {}) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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),
|
|
284
309
|
});
|
|
310
|
+
const response = await this.handleResponse(operationPromise);
|
|
311
|
+
return this.createOperation(response);
|
|
285
312
|
}
|
|
286
313
|
/**
|
|
287
314
|
* Get list of schemas
|
|
@@ -289,14 +316,19 @@ class DBSQLSession {
|
|
|
289
316
|
* @param request
|
|
290
317
|
* @returns DBSQLOperation
|
|
291
318
|
*/
|
|
292
|
-
getSchemas(request = {}) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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),
|
|
299
329
|
});
|
|
330
|
+
const response = await this.handleResponse(operationPromise);
|
|
331
|
+
return this.createOperation(response);
|
|
300
332
|
}
|
|
301
333
|
/**
|
|
302
334
|
* Get list of tables
|
|
@@ -304,14 +336,21 @@ class DBSQLSession {
|
|
|
304
336
|
* @param request
|
|
305
337
|
* @returns DBSQLOperation
|
|
306
338
|
*/
|
|
307
|
-
getTables(request = {}) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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),
|
|
314
351
|
});
|
|
352
|
+
const response = await this.handleResponse(operationPromise);
|
|
353
|
+
return this.createOperation(response);
|
|
315
354
|
}
|
|
316
355
|
/**
|
|
317
356
|
* Get list of supported table types
|
|
@@ -319,14 +358,17 @@ class DBSQLSession {
|
|
|
319
358
|
* @param request
|
|
320
359
|
* @returns DBSQLOperation
|
|
321
360
|
*/
|
|
322
|
-
getTableTypes(request = {}) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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),
|
|
329
369
|
});
|
|
370
|
+
const response = await this.handleResponse(operationPromise);
|
|
371
|
+
return this.createOperation(response);
|
|
330
372
|
}
|
|
331
373
|
/**
|
|
332
374
|
* Get full information about columns of the table
|
|
@@ -334,14 +376,21 @@ class DBSQLSession {
|
|
|
334
376
|
* @param request
|
|
335
377
|
* @returns DBSQLOperation
|
|
336
378
|
*/
|
|
337
|
-
getColumns(request = {}) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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),
|
|
344
391
|
});
|
|
392
|
+
const response = await this.handleResponse(operationPromise);
|
|
393
|
+
return this.createOperation(response);
|
|
345
394
|
}
|
|
346
395
|
/**
|
|
347
396
|
* Get information about function
|
|
@@ -349,23 +398,35 @@ class DBSQLSession {
|
|
|
349
398
|
* @param request
|
|
350
399
|
* @returns DBSQLOperation
|
|
351
400
|
*/
|
|
352
|
-
getFunctions(request) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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),
|
|
359
412
|
});
|
|
413
|
+
const response = await this.handleResponse(operationPromise);
|
|
414
|
+
return this.createOperation(response);
|
|
360
415
|
}
|
|
361
|
-
getPrimaryKeys(request) {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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),
|
|
368
427
|
});
|
|
428
|
+
const response = await this.handleResponse(operationPromise);
|
|
429
|
+
return this.createOperation(response);
|
|
369
430
|
}
|
|
370
431
|
/**
|
|
371
432
|
* Request information about foreign keys between two tables
|
|
@@ -373,40 +434,47 @@ class DBSQLSession {
|
|
|
373
434
|
* @param request
|
|
374
435
|
* @returns DBSQLOperation
|
|
375
436
|
*/
|
|
376
|
-
getCrossReference(request) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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),
|
|
383
451
|
});
|
|
452
|
+
const response = await this.handleResponse(operationPromise);
|
|
453
|
+
return this.createOperation(response);
|
|
384
454
|
}
|
|
385
455
|
/**
|
|
386
456
|
* Closes the session
|
|
387
457
|
* @public
|
|
388
458
|
* @returns Operation status
|
|
389
459
|
*/
|
|
390
|
-
close() {
|
|
460
|
+
async close() {
|
|
391
461
|
var _a;
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
sessionHandle: this.sessionHandle,
|
|
401
|
-
});
|
|
402
|
-
// check status for being successful
|
|
403
|
-
Status_1.default.assert(response.status);
|
|
404
|
-
// notify owner connection
|
|
405
|
-
(_a = this.onClose) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
406
|
-
this.isOpen = false;
|
|
407
|
-
this.context.getLogger().log(IDBSQLLogger_1.LogLevel.debug, `Session closed with id: ${this.getId()}`);
|
|
408
|
-
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,
|
|
409
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);
|
|
410
478
|
}
|
|
411
479
|
createOperation(response) {
|
|
412
480
|
Status_1.default.assert(response.status);
|
|
@@ -419,22 +487,18 @@ class DBSQLSession {
|
|
|
419
487
|
this.operations.add(operation);
|
|
420
488
|
return operation;
|
|
421
489
|
}
|
|
422
|
-
failIfClosed() {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
}
|
|
427
|
-
});
|
|
490
|
+
async failIfClosed() {
|
|
491
|
+
if (!this.isOpen) {
|
|
492
|
+
throw new HiveDriverError_1.default('The session was closed or has expired');
|
|
493
|
+
}
|
|
428
494
|
}
|
|
429
|
-
handleResponse(requestPromise) {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
return result;
|
|
437
|
-
});
|
|
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;
|
|
438
502
|
}
|
|
439
503
|
}
|
|
440
504
|
exports.default = DBSQLSession;
|