@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.
Files changed (128) hide show
  1. package/dist/DBSQLClient.d.ts +8 -5
  2. package/dist/DBSQLClient.js +78 -83
  3. package/dist/DBSQLClient.js.map +1 -1
  4. package/dist/DBSQLLogger.js +2 -13
  5. package/dist/DBSQLLogger.js.map +1 -1
  6. package/dist/DBSQLOperation.d.ts +6 -1
  7. package/dist/DBSQLOperation.js +223 -234
  8. package/dist/DBSQLOperation.js.map +1 -1
  9. package/dist/DBSQLSession.d.ts +2 -0
  10. package/dist/DBSQLSession.js +276 -229
  11. package/dist/DBSQLSession.js.map +1 -1
  12. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.d.ts +7 -2
  13. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js +91 -104
  14. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js.map +1 -1
  15. package/dist/connection/auth/DatabricksOAuth/OAuthManager.js +114 -134
  16. package/dist/connection/auth/DatabricksOAuth/OAuthManager.js.map +1 -1
  17. package/dist/connection/auth/DatabricksOAuth/OAuthPersistence.js +4 -17
  18. package/dist/connection/auth/DatabricksOAuth/OAuthPersistence.js.map +1 -1
  19. package/dist/connection/auth/DatabricksOAuth/index.d.ts +3 -2
  20. package/dist/connection/auth/DatabricksOAuth/index.js +19 -22
  21. package/dist/connection/auth/DatabricksOAuth/index.js.map +1 -1
  22. package/dist/connection/auth/PlainHttpAuthentication.js +5 -13
  23. package/dist/connection/auth/PlainHttpAuthentication.js.map +1 -1
  24. package/dist/connection/connections/HttpConnection.d.ts +1 -1
  25. package/dist/connection/connections/HttpConnection.js +49 -46
  26. package/dist/connection/connections/HttpConnection.js.map +1 -1
  27. package/dist/connection/connections/HttpRetryPolicy.d.ts +1 -1
  28. package/dist/connection/connections/HttpRetryPolicy.js +28 -41
  29. package/dist/connection/connections/HttpRetryPolicy.js.map +1 -1
  30. package/dist/connection/connections/NullRetryPolicy.js +5 -18
  31. package/dist/connection/connections/NullRetryPolicy.js.map +1 -1
  32. package/dist/connection/connections/ThriftHttpConnection.js +22 -20
  33. package/dist/connection/connections/ThriftHttpConnection.js.map +1 -1
  34. package/dist/connection/contracts/IConnectionProvider.d.ts +1 -1
  35. package/dist/contracts/IClientContext.d.ts +4 -2
  36. package/dist/contracts/IDBSQLClient.d.ts +1 -1
  37. package/dist/contracts/IDBSQLSession.d.ts +17 -13
  38. package/dist/contracts/IOperation.d.ts +19 -0
  39. package/dist/contracts/IThriftClient.d.ts +8 -0
  40. package/dist/contracts/IThriftClient.js +3 -0
  41. package/dist/contracts/IThriftClient.js.map +1 -0
  42. package/dist/dto/InfoValue.d.ts +1 -2
  43. package/dist/hive/Commands/BaseCommand.d.ts +3 -4
  44. package/dist/hive/Commands/BaseCommand.js +22 -33
  45. package/dist/hive/Commands/BaseCommand.js.map +1 -1
  46. package/dist/hive/Commands/CancelDelegationTokenCommand.d.ts +4 -1
  47. package/dist/hive/Commands/CancelDelegationTokenCommand.js.map +1 -1
  48. package/dist/hive/Commands/CancelOperationCommand.d.ts +4 -1
  49. package/dist/hive/Commands/CancelOperationCommand.js.map +1 -1
  50. package/dist/hive/Commands/CloseOperationCommand.d.ts +4 -1
  51. package/dist/hive/Commands/CloseOperationCommand.js.map +1 -1
  52. package/dist/hive/Commands/CloseSessionCommand.d.ts +4 -1
  53. package/dist/hive/Commands/CloseSessionCommand.js.map +1 -1
  54. package/dist/hive/Commands/ExecuteStatementCommand.d.ts +4 -1
  55. package/dist/hive/Commands/ExecuteStatementCommand.js.map +1 -1
  56. package/dist/hive/Commands/FetchResultsCommand.d.ts +4 -1
  57. package/dist/hive/Commands/FetchResultsCommand.js.map +1 -1
  58. package/dist/hive/Commands/GetCatalogsCommand.d.ts +4 -1
  59. package/dist/hive/Commands/GetCatalogsCommand.js.map +1 -1
  60. package/dist/hive/Commands/GetColumnsCommand.d.ts +4 -1
  61. package/dist/hive/Commands/GetColumnsCommand.js.map +1 -1
  62. package/dist/hive/Commands/GetCrossReferenceCommand.d.ts +4 -1
  63. package/dist/hive/Commands/GetCrossReferenceCommand.js.map +1 -1
  64. package/dist/hive/Commands/GetDelegationTokenCommand.d.ts +4 -1
  65. package/dist/hive/Commands/GetDelegationTokenCommand.js.map +1 -1
  66. package/dist/hive/Commands/GetFunctionsCommand.d.ts +4 -1
  67. package/dist/hive/Commands/GetFunctionsCommand.js.map +1 -1
  68. package/dist/hive/Commands/GetInfoCommand.d.ts +4 -1
  69. package/dist/hive/Commands/GetInfoCommand.js.map +1 -1
  70. package/dist/hive/Commands/GetOperationStatusCommand.d.ts +4 -1
  71. package/dist/hive/Commands/GetOperationStatusCommand.js.map +1 -1
  72. package/dist/hive/Commands/GetPrimaryKeysCommand.d.ts +4 -1
  73. package/dist/hive/Commands/GetPrimaryKeysCommand.js.map +1 -1
  74. package/dist/hive/Commands/GetResultSetMetadataCommand.d.ts +4 -1
  75. package/dist/hive/Commands/GetResultSetMetadataCommand.js.map +1 -1
  76. package/dist/hive/Commands/GetSchemasCommand.d.ts +4 -1
  77. package/dist/hive/Commands/GetSchemasCommand.js.map +1 -1
  78. package/dist/hive/Commands/GetTableTypesCommand.d.ts +4 -1
  79. package/dist/hive/Commands/GetTableTypesCommand.js.map +1 -1
  80. package/dist/hive/Commands/GetTablesCommand.d.ts +4 -1
  81. package/dist/hive/Commands/GetTablesCommand.js.map +1 -1
  82. package/dist/hive/Commands/GetTypeInfoCommand.d.ts +4 -1
  83. package/dist/hive/Commands/GetTypeInfoCommand.js.map +1 -1
  84. package/dist/hive/Commands/OpenSessionCommand.d.ts +4 -1
  85. package/dist/hive/Commands/OpenSessionCommand.js.map +1 -1
  86. package/dist/hive/Commands/RenewDelegationTokenCommand.d.ts +4 -1
  87. package/dist/hive/Commands/RenewDelegationTokenCommand.js.map +1 -1
  88. package/dist/hive/HiveDriver.js +104 -155
  89. package/dist/hive/HiveDriver.js.map +1 -1
  90. package/dist/polyfills.d.ts +1 -1
  91. package/dist/polyfills.js +1 -1
  92. package/dist/polyfills.js.map +1 -1
  93. package/dist/result/ArrowResultConverter.d.ts +1 -1
  94. package/dist/result/ArrowResultConverter.js +69 -84
  95. package/dist/result/ArrowResultConverter.js.map +1 -1
  96. package/dist/result/ArrowResultHandler.d.ts +1 -1
  97. package/dist/result/ArrowResultHandler.js +28 -41
  98. package/dist/result/ArrowResultHandler.js.map +1 -1
  99. package/dist/result/CloudFetchResultHandler.d.ts +1 -1
  100. package/dist/result/CloudFetchResultHandler.js +48 -65
  101. package/dist/result/CloudFetchResultHandler.js.map +1 -1
  102. package/dist/result/JsonResultHandler.d.ts +0 -1
  103. package/dist/result/JsonResultHandler.js +14 -41
  104. package/dist/result/JsonResultHandler.js.map +1 -1
  105. package/dist/result/ResultSlicer.js +40 -53
  106. package/dist/result/ResultSlicer.js.map +1 -1
  107. package/dist/result/RowSetProvider.d.ts +4 -0
  108. package/dist/result/RowSetProvider.js +42 -59
  109. package/dist/result/RowSetProvider.js.map +1 -1
  110. package/dist/result/utils.d.ts +2 -1
  111. package/dist/result/utils.js +9 -1
  112. package/dist/result/utils.js.map +1 -1
  113. package/dist/utils/CloseableCollection.js +7 -18
  114. package/dist/utils/CloseableCollection.js.map +1 -1
  115. package/dist/utils/OperationIterator.d.ts +23 -0
  116. package/dist/utils/OperationIterator.js +71 -0
  117. package/dist/utils/OperationIterator.js.map +1 -0
  118. package/dist/utils/buildUserAgentString.d.ts +1 -1
  119. package/dist/utils/buildUserAgentString.js +14 -2
  120. package/dist/utils/buildUserAgentString.js.map +1 -1
  121. package/dist/version.d.ts +1 -1
  122. package/dist/version.js +1 -1
  123. package/dist/version.js.map +1 -1
  124. package/package.json +12 -7
  125. package/thrift/TCLIService.d.ts +0 -42
  126. package/dist/hive/Types/index.d.ts +0 -18
  127. package/dist/hive/Types/index.js +0 -25
  128. package/dist/hive/Types/index.js.map +0 -1
@@ -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
- const defaultMaxRows = 100000;
58
- function getDirectResultsOptions(maxRows = defaultMaxRows) {
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: new Types_1.Int64(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(sessionHandle, namedParameters, ordinalParameters) {
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
- return __awaiter(this, void 0, void 0, function* () {
134
- yield this.failIfClosed();
135
- const driver = yield this.context.getDriver();
136
- const operationPromise = driver.getInfo({
137
- sessionHandle: this.sessionHandle,
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
- return __awaiter(this, void 0, void 0, function* () {
157
- yield this.failIfClosed();
158
- const driver = yield this.context.getDriver();
159
- const clientConfig = this.context.getConfig();
160
- const operationPromise = driver.executeStatement(Object.assign(Object.assign(Object.assign({ sessionHandle: this.sessionHandle, statement, queryTimeout: options.queryTimeout, runAsync: true }, getDirectResultsOptions(options.maxRows)), getArrowOptions(clientConfig)), { canDownloadResult: (_a = options.useCloudFetch) !== null && _a !== void 0 ? _a : clientConfig.useCloudFetch, parameters: getQueryParameters(this.sessionHandle, options.namedParameters, options.ordinalParameters), canDecompressLZ4Result: clientConfig.useLZ4Compression && Boolean(utils_1.LZ4) }));
161
- const response = yield this.handleResponse(operationPromise);
162
- const operation = this.createOperation(response);
163
- // If `stagingAllowedLocalPath` is provided - assume that operation possibly may be a staging operation.
164
- // To know for sure, fetch metadata and check a `isStagingOperation` flag. If it happens that it wasn't
165
- // a staging operation - not a big deal, we just fetched metadata earlier, but operation is still usable
166
- // and user can get data from it.
167
- // If `stagingAllowedLocalPath` is not provided - don't do anything to the operation. In a case of regular
168
- // operation, everything will work as usual. In a case of staging operation, it will be processed like any
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
- handleStagingOperation(operation, allowedLocalPath) {
183
- return __awaiter(this, void 0, void 0, function* () {
184
- const rows = yield operation.fetchAll();
185
- if (rows.length !== 1) {
186
- throw new StagingError_1.default('Staging operation: expected only one row in result');
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
- const row = rows[0];
189
- // For REMOVE operation local file is not available, so no need to validate it
190
- if (row.localFile !== undefined) {
191
- let allowOperation = false;
192
- for (const filepath of allowedLocalPath) {
193
- const relativePath = path.relative(filepath, row.localFile);
194
- if (!relativePath.startsWith('..') && !path.isAbsolute(relativePath)) {
195
- allowOperation = true;
196
- }
197
- }
198
- if (!allowOperation) {
199
- throw new StagingError_1.default('Staging path not a subset of allowed local paths.');
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
- const { localFile, presignedUrl, headers } = row;
203
- switch (row.operation) {
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
- return __awaiter(this, void 0, void 0, function* () {
220
- if (localFile === undefined) {
221
- throw new StagingError_1.default('Local file path not provided');
222
- }
223
- const connectionProvider = yield this.context.getConnectionProvider();
224
- const agent = yield connectionProvider.getAgent();
225
- const response = yield (0, node_fetch_1.default)(presignedUrl, { method: 'GET', headers, agent });
226
- if (!response.ok) {
227
- throw new StagingError_1.default(`HTTP error ${response.status} ${response.statusText}`);
228
- }
229
- const fileStream = fs.createWriteStream(localFile);
230
- // `pipeline` will do all the dirty job for us, including error handling and closing all the streams properly
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
- return __awaiter(this, void 0, void 0, function* () {
236
- const connectionProvider = yield this.context.getConnectionProvider();
237
- const agent = yield connectionProvider.getAgent();
238
- const response = yield (0, node_fetch_1.default)(presignedUrl, { method: 'DELETE', headers, agent });
239
- // Looks that AWS and Azure have a different behavior of HTTP `DELETE` for non-existing files.
240
- // AWS assumes that - since file already doesn't exist - the goal is achieved, and returns HTTP 200.
241
- // Azure, on the other hand, is somewhat stricter and check if file exists before deleting it. And if
242
- // file doesn't exist - Azure returns HTTP 404.
243
- //
244
- // For us, it's totally okay if file didn't exist before removing. So when we get an HTTP 404 -
245
- // just ignore it and report success. This way we can have a uniform library behavior for all clouds
246
- if (!response.ok && response.status !== 404) {
247
- throw new StagingError_1.default(`HTTP error ${response.status} ${response.statusText}`);
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
- return __awaiter(this, void 0, void 0, function* () {
253
- if (localFile === undefined) {
254
- throw new StagingError_1.default('Local file path not provided');
255
- }
256
- const connectionProvider = yield this.context.getConnectionProvider();
257
- const agent = yield connectionProvider.getAgent();
258
- const fileStream = fs.createReadStream(localFile);
259
- const fileInfo = fs.statSync(localFile, { bigint: true });
260
- const response = yield (0, node_fetch_1.default)(presignedUrl, {
261
- method: 'PUT',
262
- headers: Object.assign(Object.assign({}, headers), {
263
- // This header is required by server
264
- 'Content-Length': fileInfo.size.toString() }),
265
- agent,
266
- body: fileStream,
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
- return __awaiter(this, void 0, void 0, function* () {
281
- yield this.failIfClosed();
282
- const driver = yield this.context.getDriver();
283
- const operationPromise = driver.getTypeInfo(Object.assign({ sessionHandle: this.sessionHandle, runAsync: true }, getDirectResultsOptions(request.maxRows)));
284
- const response = yield this.handleResponse(operationPromise);
285
- return this.createOperation(response);
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
- return __awaiter(this, void 0, void 0, function* () {
296
- yield this.failIfClosed();
297
- const driver = yield this.context.getDriver();
298
- const operationPromise = driver.getCatalogs(Object.assign({ sessionHandle: this.sessionHandle, runAsync: true }, getDirectResultsOptions(request.maxRows)));
299
- const response = yield this.handleResponse(operationPromise);
300
- return this.createOperation(response);
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
- return __awaiter(this, void 0, void 0, function* () {
311
- yield this.failIfClosed();
312
- const driver = yield this.context.getDriver();
313
- const operationPromise = driver.getSchemas(Object.assign({ sessionHandle: this.sessionHandle, catalogName: request.catalogName, schemaName: request.schemaName, runAsync: true }, getDirectResultsOptions(request.maxRows)));
314
- const response = yield this.handleResponse(operationPromise);
315
- return this.createOperation(response);
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
- return __awaiter(this, void 0, void 0, function* () {
326
- yield this.failIfClosed();
327
- const driver = yield this.context.getDriver();
328
- const operationPromise = driver.getTables(Object.assign({ sessionHandle: this.sessionHandle, catalogName: request.catalogName, schemaName: request.schemaName, tableName: request.tableName, tableTypes: request.tableTypes, runAsync: true }, getDirectResultsOptions(request.maxRows)));
329
- const response = yield this.handleResponse(operationPromise);
330
- return this.createOperation(response);
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
- return __awaiter(this, void 0, void 0, function* () {
341
- yield this.failIfClosed();
342
- const driver = yield this.context.getDriver();
343
- const operationPromise = driver.getTableTypes(Object.assign({ sessionHandle: this.sessionHandle, runAsync: true }, getDirectResultsOptions(request.maxRows)));
344
- const response = yield this.handleResponse(operationPromise);
345
- return this.createOperation(response);
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
- return __awaiter(this, void 0, void 0, function* () {
356
- yield this.failIfClosed();
357
- const driver = yield this.context.getDriver();
358
- const operationPromise = driver.getColumns(Object.assign({ sessionHandle: this.sessionHandle, catalogName: request.catalogName, schemaName: request.schemaName, tableName: request.tableName, columnName: request.columnName, runAsync: true }, getDirectResultsOptions(request.maxRows)));
359
- const response = yield this.handleResponse(operationPromise);
360
- return this.createOperation(response);
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
- return __awaiter(this, void 0, void 0, function* () {
371
- yield this.failIfClosed();
372
- const driver = yield this.context.getDriver();
373
- const operationPromise = driver.getFunctions(Object.assign({ sessionHandle: this.sessionHandle, catalogName: request.catalogName, schemaName: request.schemaName, functionName: request.functionName, runAsync: true }, getDirectResultsOptions(request.maxRows)));
374
- const response = yield this.handleResponse(operationPromise);
375
- return this.createOperation(response);
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
- return __awaiter(this, void 0, void 0, function* () {
380
- yield this.failIfClosed();
381
- const driver = yield this.context.getDriver();
382
- const operationPromise = driver.getPrimaryKeys(Object.assign({ sessionHandle: this.sessionHandle, catalogName: request.catalogName, schemaName: request.schemaName, tableName: request.tableName, runAsync: true }, getDirectResultsOptions(request.maxRows)));
383
- const response = yield this.handleResponse(operationPromise);
384
- return this.createOperation(response);
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
- return __awaiter(this, void 0, void 0, function* () {
395
- yield this.failIfClosed();
396
- const driver = yield this.context.getDriver();
397
- const operationPromise = driver.getCrossReference(Object.assign({ sessionHandle: this.sessionHandle, parentCatalogName: request.parentCatalogName, parentSchemaName: request.parentSchemaName, parentTableName: request.parentTableName, foreignCatalogName: request.foreignCatalogName, foreignSchemaName: request.foreignSchemaName, foreignTableName: request.foreignTableName, runAsync: true }, getDirectResultsOptions(request.maxRows)));
398
- const response = yield this.handleResponse(operationPromise);
399
- return this.createOperation(response);
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
- return __awaiter(this, void 0, void 0, function* () {
410
- if (!this.isOpen) {
411
- return Status_1.default.success();
412
- }
413
- // Close owned operations one by one, removing successfully closed ones from the list
414
- yield this.operations.closeAll();
415
- const driver = yield this.context.getDriver();
416
- const response = yield driver.closeSession({
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
- return __awaiter(this, void 0, void 0, function* () {
441
- if (!this.isOpen) {
442
- throw new HiveDriverError_1.default('The session was closed or has expired');
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
- return __awaiter(this, void 0, void 0, function* () {
448
- // Currently, after being closed sessions remains usable - server will not
449
- // error out when trying to run operations on closed session. So it's
450
- // basically useless to process any errors here
451
- const result = yield requestPromise;
452
- yield this.failIfClosed();
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;