@databricks/sql 1.15.0 → 1.16.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 +3 -0
- package/dist/DBSQLClient.js +97 -56
- package/dist/DBSQLClient.js.map +1 -1
- package/dist/DBSQLLogger.d.ts +3 -0
- package/dist/DBSQLLogger.js +25 -0
- package/dist/DBSQLLogger.js.map +1 -1
- package/dist/DBSQLOperation.d.ts +36 -17
- package/dist/DBSQLOperation.js +133 -214
- package/dist/DBSQLOperation.js.map +1 -1
- package/dist/DBSQLParameter.d.ts +2 -0
- package/dist/DBSQLParameter.js +63 -7
- package/dist/DBSQLParameter.js.map +1 -1
- package/dist/DBSQLSession.d.ts +24 -17
- package/dist/DBSQLSession.js +45 -263
- package/dist/DBSQLSession.js.map +1 -1
- package/dist/connection/connections/HttpRetryPolicy.d.ts +3 -0
- package/dist/connection/connections/HttpRetryPolicy.js +116 -21
- package/dist/connection/connections/HttpRetryPolicy.js.map +1 -1
- package/dist/connection/connections/ThriftHttpConnection.js +18 -3
- package/dist/connection/connections/ThriftHttpConnection.js.map +1 -1
- package/dist/contracts/IBackend.d.ts +31 -0
- package/dist/contracts/IBackend.js +3 -0
- package/dist/contracts/IBackend.js.map +1 -0
- package/dist/contracts/IClientContext.d.ts +1 -0
- package/dist/contracts/IDBSQLClient.d.ts +31 -0
- package/dist/contracts/IDBSQLLogger.d.ts +17 -0
- package/dist/contracts/IDBSQLLogger.js.map +1 -1
- package/dist/contracts/IDBSQLSession.d.ts +24 -1
- package/dist/contracts/IOperation.d.ts +10 -1
- package/dist/contracts/IOperationBackend.d.ts +98 -0
- package/dist/contracts/IOperationBackend.js +3 -0
- package/dist/contracts/IOperationBackend.js.map +1 -0
- package/dist/contracts/ISessionBackend.d.ts +36 -0
- package/dist/contracts/ISessionBackend.js +3 -0
- package/dist/contracts/ISessionBackend.js.map +1 -0
- package/dist/contracts/InternalConnectionOptions.d.ts +72 -0
- package/dist/contracts/InternalConnectionOptions.js +3 -0
- package/dist/contracts/InternalConnectionOptions.js.map +1 -0
- package/dist/contracts/OperationStatus.d.ts +76 -0
- package/dist/contracts/OperationStatus.js +28 -0
- package/dist/contracts/OperationStatus.js.map +1 -0
- package/dist/contracts/ResultMetadata.d.ts +34 -0
- package/dist/contracts/ResultMetadata.js +16 -0
- package/dist/contracts/ResultMetadata.js.map +1 -0
- package/dist/errors/AuthenticationError.d.ts +1 -0
- package/dist/errors/AuthenticationError.js +4 -0
- package/dist/errors/AuthenticationError.js.map +1 -1
- package/dist/kernel/KernelArrowIpc.d.ts +54 -0
- package/dist/kernel/KernelArrowIpc.js +292 -0
- package/dist/kernel/KernelArrowIpc.js.map +1 -0
- package/dist/kernel/KernelArrowIpcDurationFix.d.ts +29 -0
- package/dist/kernel/KernelArrowIpcDurationFix.js +605 -0
- package/dist/kernel/KernelArrowIpcDurationFix.js.map +1 -0
- package/dist/kernel/KernelAuth.d.ts +300 -0
- package/dist/kernel/KernelAuth.js +463 -0
- package/dist/kernel/KernelAuth.js.map +1 -0
- package/dist/kernel/KernelBackend.d.ts +53 -0
- package/dist/kernel/KernelBackend.js +164 -0
- package/dist/kernel/KernelBackend.js.map +1 -0
- package/dist/kernel/KernelErrorMapping.d.ts +109 -0
- package/dist/kernel/KernelErrorMapping.js +249 -0
- package/dist/kernel/KernelErrorMapping.js.map +1 -0
- package/dist/kernel/KernelInputValidation.d.ts +16 -0
- package/dist/kernel/KernelInputValidation.js +49 -0
- package/dist/kernel/KernelInputValidation.js.map +1 -0
- package/dist/kernel/KernelLogging.d.ts +63 -0
- package/dist/kernel/KernelLogging.js +128 -0
- package/dist/kernel/KernelLogging.js.map +1 -0
- package/dist/kernel/KernelNativeLoader.d.ts +77 -0
- package/dist/kernel/KernelNativeLoader.js +178 -0
- package/dist/kernel/KernelNativeLoader.js.map +1 -0
- package/dist/kernel/KernelOperationBackend.d.ts +154 -0
- package/dist/kernel/KernelOperationBackend.js +640 -0
- package/dist/kernel/KernelOperationBackend.js.map +1 -0
- package/dist/kernel/KernelOperationLifecycle.d.ts +130 -0
- package/dist/kernel/KernelOperationLifecycle.js +245 -0
- package/dist/kernel/KernelOperationLifecycle.js.map +1 -0
- package/dist/kernel/KernelPositionalParams.d.ts +16 -0
- package/dist/kernel/KernelPositionalParams.js +120 -0
- package/dist/kernel/KernelPositionalParams.js.map +1 -0
- package/dist/kernel/KernelResultsProvider.d.ts +44 -0
- package/dist/kernel/KernelResultsProvider.js +102 -0
- package/dist/kernel/KernelResultsProvider.js.map +1 -0
- package/dist/kernel/KernelServerInfo.d.ts +44 -0
- package/dist/kernel/KernelServerInfo.js +73 -0
- package/dist/kernel/KernelServerInfo.js.map +1 -0
- package/dist/kernel/KernelSessionBackend.d.ts +100 -0
- package/dist/kernel/KernelSessionBackend.js +384 -0
- package/dist/kernel/KernelSessionBackend.js.map +1 -0
- package/dist/result/ArrowResultConverter.d.ts +31 -2
- package/dist/result/ArrowResultConverter.js +226 -14
- package/dist/result/ArrowResultConverter.js.map +1 -1
- package/dist/result/CloudFetchResultHandler.js +36 -8
- package/dist/result/CloudFetchResultHandler.js.map +1 -1
- package/dist/telemetry/DatabricksTelemetryExporter.js +34 -1
- package/dist/telemetry/DatabricksTelemetryExporter.js.map +1 -1
- package/dist/telemetry/telemetryTypeMappers.d.ts +1 -1
- package/dist/telemetry/telemetryTypeMappers.js +1 -1
- package/dist/telemetry/telemetryTypeMappers.js.map +1 -1
- package/dist/telemetry/types.d.ts +15 -0
- package/dist/thrift-backend/ThriftBackend.d.ts +17 -0
- package/dist/thrift-backend/ThriftBackend.js +80 -0
- package/dist/thrift-backend/ThriftBackend.js.map +1 -0
- package/dist/thrift-backend/ThriftOperationBackend.d.ts +70 -0
- package/dist/thrift-backend/ThriftOperationBackend.js +330 -0
- package/dist/thrift-backend/ThriftOperationBackend.js.map +1 -0
- package/dist/thrift-backend/ThriftSessionBackend.d.ts +36 -0
- package/dist/thrift-backend/ThriftSessionBackend.js +266 -0
- package/dist/thrift-backend/ThriftSessionBackend.js.map +1 -0
- package/dist/thrift-backend/wireSynthesis.d.ts +30 -0
- package/dist/thrift-backend/wireSynthesis.js +128 -0
- package/dist/thrift-backend/wireSynthesis.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/native/kernel/README.md +97 -0
- package/native/kernel/index.d.ts +1069 -0
- package/native/kernel/index.js +325 -0
- package/package.json +13 -2
package/dist/DBSQLParameter.js
CHANGED
|
@@ -12,6 +12,15 @@ var DBSQLParameterType;
|
|
|
12
12
|
DBSQLParameterType["STRING"] = "STRING";
|
|
13
13
|
DBSQLParameterType["DATE"] = "DATE";
|
|
14
14
|
DBSQLParameterType["TIMESTAMP"] = "TIMESTAMP";
|
|
15
|
+
// `TIMESTAMP_NTZ` binds a timezone-free (wall-clock) timestamp. It is a real
|
|
16
|
+
// Spark type, bound natively on both the Thrift and kernel backends (requires
|
|
17
|
+
// a server that supports TIMESTAMP_NTZ; Spark 3.4+ / recent DBR).
|
|
18
|
+
DBSQLParameterType["TIMESTAMP_NTZ"] = "TIMESTAMP_NTZ";
|
|
19
|
+
// `TIMESTAMP_LTZ` is an alias for `TIMESTAMP`: Spark has no distinct
|
|
20
|
+
// TIMESTAMP_LTZ type — `TIMESTAMP` already carries local/instant (LTZ)
|
|
21
|
+
// semantics. `toSparkParameter` therefore binds it as `TIMESTAMP` on the wire
|
|
22
|
+
// (valid on both backends); it exists only as a self-documenting alias.
|
|
23
|
+
DBSQLParameterType["TIMESTAMP_LTZ"] = "TIMESTAMP_LTZ";
|
|
15
24
|
DBSQLParameterType["FLOAT"] = "FLOAT";
|
|
16
25
|
DBSQLParameterType["DECIMAL"] = "DECIMAL";
|
|
17
26
|
DBSQLParameterType["DOUBLE"] = "DOUBLE";
|
|
@@ -23,13 +32,41 @@ var DBSQLParameterType;
|
|
|
23
32
|
DBSQLParameterType["INTERVALMONTH"] = "INTERVAL MONTH";
|
|
24
33
|
DBSQLParameterType["INTERVALDAY"] = "INTERVAL DAY";
|
|
25
34
|
})(DBSQLParameterType = exports.DBSQLParameterType || (exports.DBSQLParameterType = {}));
|
|
35
|
+
// 32-bit signed integer bounds — the range of the Spark `INT` type.
|
|
36
|
+
const INT32_MIN = -2147483648;
|
|
37
|
+
const INT32_MAX = 2147483647;
|
|
38
|
+
/**
|
|
39
|
+
* Infer the Spark parameter type for a JS `number` when the caller didn't set
|
|
40
|
+
* one explicitly.
|
|
41
|
+
*
|
|
42
|
+
* A JS `number` is an IEEE-754 double, so a whole-number value can still be far
|
|
43
|
+
* outside the `INT` range (e.g. `1e30`). Typing such a value as `INTEGER`
|
|
44
|
+
* makes the server reject it (`invalid INT literal "1e+30"`). Pick the
|
|
45
|
+
* narrowest type that actually fits:
|
|
46
|
+
* - non-integer / non-finite → `DOUBLE`
|
|
47
|
+
* - integer within INT (i32) range → `INTEGER`
|
|
48
|
+
* - integer within the safe-integer range → `BIGINT`
|
|
49
|
+
* - anything larger → `DOUBLE` (can't be represented exactly as an integer
|
|
50
|
+
* anyway; callers needing exact 64-bit integers should pass a `bigint`).
|
|
51
|
+
*/
|
|
52
|
+
function inferNumberType(value) {
|
|
53
|
+
if (!Number.isInteger(value)) {
|
|
54
|
+
return DBSQLParameterType.DOUBLE;
|
|
55
|
+
}
|
|
56
|
+
if (value >= INT32_MIN && value <= INT32_MAX) {
|
|
57
|
+
return DBSQLParameterType.INTEGER;
|
|
58
|
+
}
|
|
59
|
+
if (Number.isSafeInteger(value)) {
|
|
60
|
+
return DBSQLParameterType.BIGINT;
|
|
61
|
+
}
|
|
62
|
+
return DBSQLParameterType.DOUBLE;
|
|
63
|
+
}
|
|
26
64
|
class DBSQLParameter {
|
|
27
65
|
constructor({ type, value }) {
|
|
28
66
|
this.type = type;
|
|
29
67
|
this.value = value;
|
|
30
68
|
}
|
|
31
69
|
toSparkParameter({ name } = {}) {
|
|
32
|
-
var _a, _b, _c, _d, _e;
|
|
33
70
|
// If VOID type was set explicitly - ignore value
|
|
34
71
|
if (this.type === DBSQLParameterType.VOID) {
|
|
35
72
|
return new TCLIService_types_1.TSparkParameter({ name }); // for NULL neither `type` nor `value` should be set
|
|
@@ -38,10 +75,15 @@ class DBSQLParameter {
|
|
|
38
75
|
if (this.value === undefined || this.value === null) {
|
|
39
76
|
return new TCLIService_types_1.TSparkParameter({ name }); // for NULL neither `type` nor `value` should be set
|
|
40
77
|
}
|
|
78
|
+
// Map timezone-explicit timestamp aliases to their Spark wire type. Spark
|
|
79
|
+
// has no distinct TIMESTAMP_LTZ type (TIMESTAMP carries LTZ semantics), so
|
|
80
|
+
// bind it as TIMESTAMP — valid on both the Thrift and kernel backends.
|
|
81
|
+
// TIMESTAMP_NTZ is a real Spark type and is bound natively.
|
|
82
|
+
const wireType = this.type === DBSQLParameterType.TIMESTAMP_LTZ ? DBSQLParameterType.TIMESTAMP : this.type;
|
|
41
83
|
if (typeof this.value === 'boolean') {
|
|
42
84
|
return new TCLIService_types_1.TSparkParameter({
|
|
43
85
|
name,
|
|
44
|
-
type:
|
|
86
|
+
type: wireType !== null && wireType !== void 0 ? wireType : DBSQLParameterType.BOOLEAN,
|
|
45
87
|
value: new TCLIService_types_1.TSparkParameterValue({
|
|
46
88
|
stringValue: this.value ? 'TRUE' : 'FALSE',
|
|
47
89
|
}),
|
|
@@ -50,7 +92,7 @@ class DBSQLParameter {
|
|
|
50
92
|
if (typeof this.value === 'number') {
|
|
51
93
|
return new TCLIService_types_1.TSparkParameter({
|
|
52
94
|
name,
|
|
53
|
-
type:
|
|
95
|
+
type: wireType !== null && wireType !== void 0 ? wireType : inferNumberType(this.value),
|
|
54
96
|
value: new TCLIService_types_1.TSparkParameterValue({
|
|
55
97
|
stringValue: Number(this.value).toString(),
|
|
56
98
|
}),
|
|
@@ -59,24 +101,38 @@ class DBSQLParameter {
|
|
|
59
101
|
if (this.value instanceof node_int64_1.default || typeof this.value === 'bigint') {
|
|
60
102
|
return new TCLIService_types_1.TSparkParameter({
|
|
61
103
|
name,
|
|
62
|
-
type:
|
|
104
|
+
type: wireType !== null && wireType !== void 0 ? wireType : DBSQLParameterType.BIGINT,
|
|
63
105
|
value: new TCLIService_types_1.TSparkParameterValue({
|
|
64
106
|
stringValue: this.value.toString(),
|
|
65
107
|
}),
|
|
66
108
|
});
|
|
67
109
|
}
|
|
68
110
|
if (this.value instanceof Date) {
|
|
111
|
+
// A `Date` bound as `DATE` must project a calendar date (`yyyy-mm-dd`),
|
|
112
|
+
// not a full ISO-8601 timestamp: the SEA wire rejects
|
|
113
|
+
// `2024-03-14T00:00:00.000Z` as a DATE literal ("trailing input"), and
|
|
114
|
+
// Thrift accepts the date-only form just as well. Without an explicit
|
|
115
|
+
// DATE type the value still binds as a TIMESTAMP from the full ISO string.
|
|
116
|
+
const isDateType = wireType === DBSQLParameterType.DATE;
|
|
69
117
|
return new TCLIService_types_1.TSparkParameter({
|
|
70
118
|
name,
|
|
71
|
-
type:
|
|
119
|
+
type: wireType !== null && wireType !== void 0 ? wireType : DBSQLParameterType.TIMESTAMP,
|
|
72
120
|
value: new TCLIService_types_1.TSparkParameterValue({
|
|
73
|
-
|
|
121
|
+
// For DATE, project the *calendar* date using local-time accessors
|
|
122
|
+
// rather than `toISOString().slice(0, 10)`. `toISOString()` first
|
|
123
|
+
// converts to UTC, so a `new Date(2024, 2, 14)` constructed in a
|
|
124
|
+
// positive-offset zone (e.g. UTC+10, internal `2024-03-13T14:00Z`)
|
|
125
|
+
// would yield "2024-03-13" — off by one. Users reason about a DATE
|
|
126
|
+
// as the wall-calendar date they constructed, so extract that.
|
|
127
|
+
stringValue: isDateType
|
|
128
|
+
? `${this.value.getFullYear()}-${String(this.value.getMonth() + 1).padStart(2, '0')}-${String(this.value.getDate()).padStart(2, '0')}`
|
|
129
|
+
: this.value.toISOString(),
|
|
74
130
|
}),
|
|
75
131
|
});
|
|
76
132
|
}
|
|
77
133
|
return new TCLIService_types_1.TSparkParameter({
|
|
78
134
|
name,
|
|
79
|
-
type:
|
|
135
|
+
type: wireType !== null && wireType !== void 0 ? wireType : DBSQLParameterType.STRING,
|
|
80
136
|
value: new TCLIService_types_1.TSparkParameterValue({
|
|
81
137
|
stringValue: this.value,
|
|
82
138
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DBSQLParameter.js","sourceRoot":"","sources":["../lib/DBSQLParameter.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA+B;AAC/B,mEAAoF;AAIpF,IAAY,
|
|
1
|
+
{"version":3,"file":"DBSQLParameter.js","sourceRoot":"","sources":["../lib/DBSQLParameter.ts"],"names":[],"mappings":"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"}
|
package/dist/DBSQLSession.d.ts
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
import Int64 from 'node-int64';
|
|
2
|
-
import { TSessionHandle, TProtocolVersion } from '../thrift/TCLIService_types';
|
|
3
1
|
import IDBSQLSession, { ExecuteStatementOptions, TypeInfoRequest, CatalogsRequest, SchemasRequest, TablesRequest, TableTypesRequest, ColumnsRequest, FunctionsRequest, PrimaryKeysRequest, CrossReferenceRequest } from './contracts/IDBSQLSession';
|
|
4
2
|
import IOperation from './contracts/IOperation';
|
|
5
3
|
import Status from './dto/Status';
|
|
6
4
|
import InfoValue from './dto/InfoValue';
|
|
7
5
|
import IClientContext from './contracts/IClientContext';
|
|
8
|
-
|
|
6
|
+
import ISessionBackend from './contracts/ISessionBackend';
|
|
7
|
+
import { numberToInt64 as numberToInt64Impl } from './thrift-backend/ThriftSessionBackend';
|
|
8
|
+
/**
|
|
9
|
+
* Convert a JS number to a Thrift-wire `node-int64`.
|
|
10
|
+
*
|
|
11
|
+
* @deprecated Thrift-only utility re-exported for back-compat with existing
|
|
12
|
+
* external consumers. Backends other than Thrift do not use `node-int64`;
|
|
13
|
+
* new code should not import this from `DBSQLSession`. It will be removed
|
|
14
|
+
* when the public API stops exposing Thrift wire types.
|
|
15
|
+
*/
|
|
16
|
+
export declare const numberToInt64: typeof numberToInt64Impl;
|
|
9
17
|
interface DBSQLSessionConstructorOptions {
|
|
10
|
-
|
|
18
|
+
backend: ISessionBackend;
|
|
11
19
|
context: IClientContext;
|
|
12
|
-
serverProtocolVersion?: TProtocolVersion;
|
|
13
20
|
}
|
|
14
21
|
export default class DBSQLSession implements IDBSQLSession {
|
|
15
22
|
private readonly context;
|
|
16
|
-
private readonly
|
|
23
|
+
private readonly backend;
|
|
17
24
|
private isOpen;
|
|
18
|
-
private openTime;
|
|
19
|
-
private serverProtocolVersion?;
|
|
20
25
|
onClose?: () => void;
|
|
21
26
|
private operations;
|
|
22
|
-
|
|
23
|
-
* Helper method to determine if runAsync should be set for metadata operations
|
|
24
|
-
* @private
|
|
25
|
-
* @returns true if supported by protocol version, undefined otherwise
|
|
26
|
-
*/
|
|
27
|
-
private getRunAsyncForMetadataOperations;
|
|
28
|
-
constructor({ handle, context, serverProtocolVersion }: DBSQLSessionConstructorOptions);
|
|
27
|
+
constructor(options: DBSQLSessionConstructorOptions);
|
|
29
28
|
get id(): string;
|
|
30
29
|
/**
|
|
31
30
|
* Fetches info
|
|
@@ -113,8 +112,16 @@ export default class DBSQLSession implements IDBSQLSession {
|
|
|
113
112
|
* @returns Operation status
|
|
114
113
|
*/
|
|
115
114
|
close(): Promise<Status>;
|
|
116
|
-
private
|
|
115
|
+
private wrapOperation;
|
|
116
|
+
/**
|
|
117
|
+
* Bracket a backend call with `failIfClosed()` on both sides. The pre-call
|
|
118
|
+
* check rejects work against an already-closed session; the post-call check
|
|
119
|
+
* rejects results that came back after a concurrent close (server-side
|
|
120
|
+
* close doesn't error out the in-flight RPC). Centralizing the pattern
|
|
121
|
+
* keeps the 10+ delegation methods readable and makes the contract
|
|
122
|
+
* impossible to forget.
|
|
123
|
+
*/
|
|
124
|
+
private runBackend;
|
|
117
125
|
private failIfClosed;
|
|
118
|
-
private handleResponse;
|
|
119
126
|
}
|
|
120
127
|
export {};
|
package/dist/DBSQLSession.js
CHANGED
|
@@ -31,113 +31,36 @@ const fs = __importStar(require("fs"));
|
|
|
31
31
|
const path = __importStar(require("path"));
|
|
32
32
|
const node_stream_1 = __importDefault(require("node:stream"));
|
|
33
33
|
const node_util_1 = __importDefault(require("node:util"));
|
|
34
|
-
const uuid_1 = require("uuid");
|
|
35
|
-
const node_int64_1 = __importDefault(require("node-int64"));
|
|
36
34
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
37
|
-
const TCLIService_types_1 = require("../thrift/TCLIService_types");
|
|
38
35
|
const DBSQLOperation_1 = __importDefault(require("./DBSQLOperation"));
|
|
39
36
|
const Status_1 = __importDefault(require("./dto/Status"));
|
|
40
|
-
const InfoValue_1 = __importDefault(require("./dto/InfoValue"));
|
|
41
|
-
const utils_1 = require("./utils");
|
|
42
37
|
const CloseableCollection_1 = __importDefault(require("./utils/CloseableCollection"));
|
|
43
38
|
const IDBSQLLogger_1 = require("./contracts/IDBSQLLogger");
|
|
44
39
|
const HiveDriverError_1 = __importDefault(require("./errors/HiveDriverError"));
|
|
45
40
|
const StagingError_1 = __importDefault(require("./errors/StagingError"));
|
|
46
|
-
const
|
|
47
|
-
const ParameterError_1 = __importDefault(require("./errors/ParameterError"));
|
|
41
|
+
const ThriftSessionBackend_1 = require("./thrift-backend/ThriftSessionBackend");
|
|
48
42
|
const telemetryUtils_1 = require("./telemetry/telemetryUtils");
|
|
49
43
|
// Explicitly promisify a callback-style `pipeline` because `node:stream/promises` is not available in Node 14
|
|
50
44
|
const pipeline = node_util_1.default.promisify(node_stream_1.default.pipeline);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
return new node_int64_1.default(value);
|
|
62
|
-
}
|
|
63
|
-
exports.numberToInt64 = numberToInt64;
|
|
64
|
-
function getDirectResultsOptions(maxRows, config) {
|
|
65
|
-
if (maxRows === null) {
|
|
66
|
-
return {};
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
getDirectResults: {
|
|
70
|
-
maxRows: numberToInt64(maxRows !== null && maxRows !== void 0 ? maxRows : config.directResultsDefaultMaxRows),
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function getArrowOptions(config, serverProtocolVersion) {
|
|
75
|
-
const { arrowEnabled = true, useArrowNativeTypes = true } = config;
|
|
76
|
-
if (!arrowEnabled || !utils_1.ProtocolVersion.supportsArrowMetadata(serverProtocolVersion)) {
|
|
77
|
-
return {
|
|
78
|
-
canReadArrowResult: false,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
canReadArrowResult: true,
|
|
83
|
-
useArrowNativeTypes: {
|
|
84
|
-
timestampAsArrow: useArrowNativeTypes,
|
|
85
|
-
decimalAsArrow: useArrowNativeTypes,
|
|
86
|
-
complexTypesAsArrow: useArrowNativeTypes,
|
|
87
|
-
// TODO: currently unsupported by `apache-arrow` (see https://github.com/streamlit/streamlit/issues/4489)
|
|
88
|
-
intervalTypesAsArrow: false,
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function getQueryParameters(namedParameters, ordinalParameters) {
|
|
93
|
-
const namedParametersProvided = namedParameters !== undefined && Object.keys(namedParameters).length > 0;
|
|
94
|
-
const ordinalParametersProvided = ordinalParameters !== undefined && ordinalParameters.length > 0;
|
|
95
|
-
if (namedParametersProvided && ordinalParametersProvided) {
|
|
96
|
-
throw new ParameterError_1.default('Driver does not support both ordinal and named parameters.');
|
|
97
|
-
}
|
|
98
|
-
if (!namedParametersProvided && !ordinalParametersProvided) {
|
|
99
|
-
return [];
|
|
100
|
-
}
|
|
101
|
-
const result = [];
|
|
102
|
-
if (namedParameters !== undefined) {
|
|
103
|
-
for (const name of Object.keys(namedParameters)) {
|
|
104
|
-
const value = namedParameters[name];
|
|
105
|
-
const param = value instanceof DBSQLParameter_1.DBSQLParameter ? value : new DBSQLParameter_1.DBSQLParameter({ value });
|
|
106
|
-
result.push(param.toSparkParameter({ name }));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (ordinalParameters !== undefined) {
|
|
110
|
-
for (const value of ordinalParameters) {
|
|
111
|
-
const param = value instanceof DBSQLParameter_1.DBSQLParameter ? value : new DBSQLParameter_1.DBSQLParameter({ value });
|
|
112
|
-
result.push(param.toSparkParameter());
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
45
|
+
/**
|
|
46
|
+
* Convert a JS number to a Thrift-wire `node-int64`.
|
|
47
|
+
*
|
|
48
|
+
* @deprecated Thrift-only utility re-exported for back-compat with existing
|
|
49
|
+
* external consumers. Backends other than Thrift do not use `node-int64`;
|
|
50
|
+
* new code should not import this from `DBSQLSession`. It will be removed
|
|
51
|
+
* when the public API stops exposing Thrift wire types.
|
|
52
|
+
*/
|
|
53
|
+
exports.numberToInt64 = ThriftSessionBackend_1.numberToInt64;
|
|
117
54
|
class DBSQLSession {
|
|
118
|
-
|
|
119
|
-
* Helper method to determine if runAsync should be set for metadata operations
|
|
120
|
-
* @private
|
|
121
|
-
* @returns true if supported by protocol version, undefined otherwise
|
|
122
|
-
*/
|
|
123
|
-
getRunAsyncForMetadataOperations() {
|
|
124
|
-
return utils_1.ProtocolVersion.supportsAsyncMetadataOperations(this.serverProtocolVersion) ? true : undefined;
|
|
125
|
-
}
|
|
126
|
-
constructor({ handle, context, serverProtocolVersion }) {
|
|
55
|
+
constructor(options) {
|
|
127
56
|
this.isOpen = true;
|
|
128
57
|
this.operations = new CloseableCollection_1.default();
|
|
129
|
-
this.
|
|
130
|
-
this.
|
|
131
|
-
this.openTime = Date.now();
|
|
132
|
-
// Get the server protocol version from the provided parameter (from TOpenSessionResp)
|
|
133
|
-
this.serverProtocolVersion = serverProtocolVersion;
|
|
58
|
+
this.context = options.context;
|
|
59
|
+
this.backend = options.backend;
|
|
134
60
|
this.context.getLogger().log(IDBSQLLogger_1.LogLevel.debug, `Session created with id: ${this.id}`);
|
|
135
|
-
this.context.getLogger().log(IDBSQLLogger_1.LogLevel.debug, `Server protocol version: ${this.serverProtocolVersion}`);
|
|
136
61
|
}
|
|
137
62
|
get id() {
|
|
138
|
-
|
|
139
|
-
const sessionId = (_b = (_a = this.sessionHandle) === null || _a === void 0 ? void 0 : _a.sessionId) === null || _b === void 0 ? void 0 : _b.guid;
|
|
140
|
-
return sessionId ? (0, uuid_1.stringify)(sessionId) : uuid_1.NIL;
|
|
63
|
+
return this.backend.id;
|
|
141
64
|
}
|
|
142
65
|
/**
|
|
143
66
|
* Fetches info
|
|
@@ -148,15 +71,7 @@ class DBSQLSession {
|
|
|
148
71
|
* const response = await session.getInfo(thrift.TCLIService_types.TGetInfoType.CLI_DBMS_VER);
|
|
149
72
|
*/
|
|
150
73
|
async getInfo(infoType) {
|
|
151
|
-
|
|
152
|
-
const driver = await this.context.getDriver();
|
|
153
|
-
const operationPromise = driver.getInfo({
|
|
154
|
-
sessionHandle: this.sessionHandle,
|
|
155
|
-
infoType,
|
|
156
|
-
});
|
|
157
|
-
const response = await this.handleResponse(operationPromise);
|
|
158
|
-
Status_1.default.assert(response.status);
|
|
159
|
-
return new InfoValue_1.default(response.infoValue);
|
|
74
|
+
return this.runBackend(() => this.backend.getInfo(infoType));
|
|
160
75
|
}
|
|
161
76
|
/**
|
|
162
77
|
* Executes statement
|
|
@@ -168,34 +83,8 @@ class DBSQLSession {
|
|
|
168
83
|
* const operation = await session.executeStatement(query);
|
|
169
84
|
*/
|
|
170
85
|
async executeStatement(statement, options = {}) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const driver = await this.context.getDriver();
|
|
174
|
-
const clientConfig = this.context.getConfig();
|
|
175
|
-
const request = new TCLIService_types_1.TExecuteStatementReq({
|
|
176
|
-
sessionHandle: this.sessionHandle,
|
|
177
|
-
statement,
|
|
178
|
-
queryTimeout: options.queryTimeout ? numberToInt64(options.queryTimeout) : undefined,
|
|
179
|
-
runAsync: true,
|
|
180
|
-
...getDirectResultsOptions(options.maxRows, clientConfig),
|
|
181
|
-
...getArrowOptions(clientConfig, this.serverProtocolVersion),
|
|
182
|
-
});
|
|
183
|
-
if (utils_1.ProtocolVersion.supportsParameterizedQueries(this.serverProtocolVersion)) {
|
|
184
|
-
request.parameters = getQueryParameters(options.namedParameters, options.ordinalParameters);
|
|
185
|
-
}
|
|
186
|
-
const serializedQueryTags = (0, utils_1.serializeQueryTags)(options.queryTags);
|
|
187
|
-
if (serializedQueryTags !== undefined) {
|
|
188
|
-
request.confOverlay = { ...request.confOverlay, query_tags: serializedQueryTags };
|
|
189
|
-
}
|
|
190
|
-
if (utils_1.ProtocolVersion.supportsCloudFetch(this.serverProtocolVersion)) {
|
|
191
|
-
request.canDownloadResult = (_a = options.useCloudFetch) !== null && _a !== void 0 ? _a : clientConfig.useCloudFetch;
|
|
192
|
-
}
|
|
193
|
-
if (utils_1.ProtocolVersion.supportsArrowCompression(this.serverProtocolVersion) && request.canDownloadResult !== true) {
|
|
194
|
-
request.canDecompressLZ4Result = ((_b = options.useLZ4Compression) !== null && _b !== void 0 ? _b : clientConfig.useLZ4Compression) && Boolean((0, utils_1.LZ4)());
|
|
195
|
-
}
|
|
196
|
-
const operationPromise = driver.executeStatement(request);
|
|
197
|
-
const response = await this.handleResponse(operationPromise);
|
|
198
|
-
const operation = this.createOperation(response);
|
|
86
|
+
const opBackend = await this.runBackend(() => this.backend.executeStatement(statement, options));
|
|
87
|
+
const operation = this.wrapOperation(opBackend);
|
|
199
88
|
// If `stagingAllowedLocalPath` is provided - assume that operation possibly may be a staging operation.
|
|
200
89
|
// To know for sure, fetch metadata and check a `isStagingOperation` flag. If it happens that it wasn't
|
|
201
90
|
// a staging operation - not a big deal, we just fetched metadata earlier, but operation is still usable
|
|
@@ -204,7 +93,7 @@ class DBSQLSession {
|
|
|
204
93
|
// operation, everything will work as usual. In a case of staging operation, it will be processed like any
|
|
205
94
|
// other query - it will be possible to get data from it as usual, or use other operation methods.
|
|
206
95
|
if (options.stagingAllowedLocalPath !== undefined) {
|
|
207
|
-
const metadata = await operation.
|
|
96
|
+
const metadata = await operation.getResultMetadata();
|
|
208
97
|
if (metadata.isStagingOperation) {
|
|
209
98
|
const allowedLocalPath = Array.isArray(options.stagingAllowedLocalPath)
|
|
210
99
|
? options.stagingAllowedLocalPath
|
|
@@ -220,7 +109,6 @@ class DBSQLSession {
|
|
|
220
109
|
throw new StagingError_1.default('Staging operation: expected only one row in result');
|
|
221
110
|
}
|
|
222
111
|
const row = rows[0];
|
|
223
|
-
// For REMOVE operation local file is not available, so no need to validate it
|
|
224
112
|
if (row.localFile !== undefined) {
|
|
225
113
|
let allowOperation = false;
|
|
226
114
|
for (const filepath of allowedLocalPath) {
|
|
@@ -259,7 +147,6 @@ class DBSQLSession {
|
|
|
259
147
|
throw new StagingError_1.default(`HTTP error ${response.status} ${response.statusText}`);
|
|
260
148
|
}
|
|
261
149
|
const fileStream = fs.createWriteStream(localFile);
|
|
262
|
-
// `pipeline` will do all the dirty job for us, including error handling and closing all the streams properly
|
|
263
150
|
return pipeline(response.body, fileStream);
|
|
264
151
|
}
|
|
265
152
|
async handleStagingRemove(presignedUrl, headers) {
|
|
@@ -306,16 +193,7 @@ class DBSQLSession {
|
|
|
306
193
|
* @returns DBSQLOperation
|
|
307
194
|
*/
|
|
308
195
|
async getTypeInfo(request = {}) {
|
|
309
|
-
await this.
|
|
310
|
-
const driver = await this.context.getDriver();
|
|
311
|
-
const clientConfig = this.context.getConfig();
|
|
312
|
-
const operationPromise = driver.getTypeInfo({
|
|
313
|
-
sessionHandle: this.sessionHandle,
|
|
314
|
-
runAsync: this.getRunAsyncForMetadataOperations(),
|
|
315
|
-
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
316
|
-
});
|
|
317
|
-
const response = await this.handleResponse(operationPromise);
|
|
318
|
-
return this.createOperation(response);
|
|
196
|
+
return this.wrapOperation(await this.runBackend(() => this.backend.getTypeInfo(request)));
|
|
319
197
|
}
|
|
320
198
|
/**
|
|
321
199
|
* Get list of catalogs
|
|
@@ -324,16 +202,7 @@ class DBSQLSession {
|
|
|
324
202
|
* @returns DBSQLOperation
|
|
325
203
|
*/
|
|
326
204
|
async getCatalogs(request = {}) {
|
|
327
|
-
await this.
|
|
328
|
-
const driver = await this.context.getDriver();
|
|
329
|
-
const clientConfig = this.context.getConfig();
|
|
330
|
-
const operationPromise = driver.getCatalogs({
|
|
331
|
-
sessionHandle: this.sessionHandle,
|
|
332
|
-
runAsync: this.getRunAsyncForMetadataOperations(),
|
|
333
|
-
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
334
|
-
});
|
|
335
|
-
const response = await this.handleResponse(operationPromise);
|
|
336
|
-
return this.createOperation(response);
|
|
205
|
+
return this.wrapOperation(await this.runBackend(() => this.backend.getCatalogs(request)));
|
|
337
206
|
}
|
|
338
207
|
/**
|
|
339
208
|
* Get list of schemas
|
|
@@ -342,18 +211,7 @@ class DBSQLSession {
|
|
|
342
211
|
* @returns DBSQLOperation
|
|
343
212
|
*/
|
|
344
213
|
async getSchemas(request = {}) {
|
|
345
|
-
await this.
|
|
346
|
-
const driver = await this.context.getDriver();
|
|
347
|
-
const clientConfig = this.context.getConfig();
|
|
348
|
-
const operationPromise = driver.getSchemas({
|
|
349
|
-
sessionHandle: this.sessionHandle,
|
|
350
|
-
catalogName: request.catalogName,
|
|
351
|
-
schemaName: request.schemaName,
|
|
352
|
-
runAsync: this.getRunAsyncForMetadataOperations(),
|
|
353
|
-
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
354
|
-
});
|
|
355
|
-
const response = await this.handleResponse(operationPromise);
|
|
356
|
-
return this.createOperation(response);
|
|
214
|
+
return this.wrapOperation(await this.runBackend(() => this.backend.getSchemas(request)));
|
|
357
215
|
}
|
|
358
216
|
/**
|
|
359
217
|
* Get list of tables
|
|
@@ -362,20 +220,7 @@ class DBSQLSession {
|
|
|
362
220
|
* @returns DBSQLOperation
|
|
363
221
|
*/
|
|
364
222
|
async getTables(request = {}) {
|
|
365
|
-
await this.
|
|
366
|
-
const driver = await this.context.getDriver();
|
|
367
|
-
const clientConfig = this.context.getConfig();
|
|
368
|
-
const operationPromise = driver.getTables({
|
|
369
|
-
sessionHandle: this.sessionHandle,
|
|
370
|
-
catalogName: request.catalogName,
|
|
371
|
-
schemaName: request.schemaName,
|
|
372
|
-
tableName: request.tableName,
|
|
373
|
-
tableTypes: request.tableTypes,
|
|
374
|
-
runAsync: this.getRunAsyncForMetadataOperations(),
|
|
375
|
-
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
376
|
-
});
|
|
377
|
-
const response = await this.handleResponse(operationPromise);
|
|
378
|
-
return this.createOperation(response);
|
|
223
|
+
return this.wrapOperation(await this.runBackend(() => this.backend.getTables(request)));
|
|
379
224
|
}
|
|
380
225
|
/**
|
|
381
226
|
* Get list of supported table types
|
|
@@ -384,16 +229,7 @@ class DBSQLSession {
|
|
|
384
229
|
* @returns DBSQLOperation
|
|
385
230
|
*/
|
|
386
231
|
async getTableTypes(request = {}) {
|
|
387
|
-
await this.
|
|
388
|
-
const driver = await this.context.getDriver();
|
|
389
|
-
const clientConfig = this.context.getConfig();
|
|
390
|
-
const operationPromise = driver.getTableTypes({
|
|
391
|
-
sessionHandle: this.sessionHandle,
|
|
392
|
-
runAsync: this.getRunAsyncForMetadataOperations(),
|
|
393
|
-
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
394
|
-
});
|
|
395
|
-
const response = await this.handleResponse(operationPromise);
|
|
396
|
-
return this.createOperation(response);
|
|
232
|
+
return this.wrapOperation(await this.runBackend(() => this.backend.getTableTypes(request)));
|
|
397
233
|
}
|
|
398
234
|
/**
|
|
399
235
|
* Get full information about columns of the table
|
|
@@ -402,20 +238,7 @@ class DBSQLSession {
|
|
|
402
238
|
* @returns DBSQLOperation
|
|
403
239
|
*/
|
|
404
240
|
async getColumns(request = {}) {
|
|
405
|
-
await this.
|
|
406
|
-
const driver = await this.context.getDriver();
|
|
407
|
-
const clientConfig = this.context.getConfig();
|
|
408
|
-
const operationPromise = driver.getColumns({
|
|
409
|
-
sessionHandle: this.sessionHandle,
|
|
410
|
-
catalogName: request.catalogName,
|
|
411
|
-
schemaName: request.schemaName,
|
|
412
|
-
tableName: request.tableName,
|
|
413
|
-
columnName: request.columnName,
|
|
414
|
-
runAsync: this.getRunAsyncForMetadataOperations(),
|
|
415
|
-
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
416
|
-
});
|
|
417
|
-
const response = await this.handleResponse(operationPromise);
|
|
418
|
-
return this.createOperation(response);
|
|
241
|
+
return this.wrapOperation(await this.runBackend(() => this.backend.getColumns(request)));
|
|
419
242
|
}
|
|
420
243
|
/**
|
|
421
244
|
* Get information about function
|
|
@@ -424,34 +247,10 @@ class DBSQLSession {
|
|
|
424
247
|
* @returns DBSQLOperation
|
|
425
248
|
*/
|
|
426
249
|
async getFunctions(request) {
|
|
427
|
-
await this.
|
|
428
|
-
const driver = await this.context.getDriver();
|
|
429
|
-
const clientConfig = this.context.getConfig();
|
|
430
|
-
const operationPromise = driver.getFunctions({
|
|
431
|
-
sessionHandle: this.sessionHandle,
|
|
432
|
-
catalogName: request.catalogName,
|
|
433
|
-
schemaName: request.schemaName,
|
|
434
|
-
functionName: request.functionName,
|
|
435
|
-
runAsync: this.getRunAsyncForMetadataOperations(),
|
|
436
|
-
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
437
|
-
});
|
|
438
|
-
const response = await this.handleResponse(operationPromise);
|
|
439
|
-
return this.createOperation(response);
|
|
250
|
+
return this.wrapOperation(await this.runBackend(() => this.backend.getFunctions(request)));
|
|
440
251
|
}
|
|
441
252
|
async getPrimaryKeys(request) {
|
|
442
|
-
await this.
|
|
443
|
-
const driver = await this.context.getDriver();
|
|
444
|
-
const clientConfig = this.context.getConfig();
|
|
445
|
-
const operationPromise = driver.getPrimaryKeys({
|
|
446
|
-
sessionHandle: this.sessionHandle,
|
|
447
|
-
catalogName: request.catalogName,
|
|
448
|
-
schemaName: request.schemaName,
|
|
449
|
-
tableName: request.tableName,
|
|
450
|
-
runAsync: this.getRunAsyncForMetadataOperations(),
|
|
451
|
-
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
452
|
-
});
|
|
453
|
-
const response = await this.handleResponse(operationPromise);
|
|
454
|
-
return this.createOperation(response);
|
|
253
|
+
return this.wrapOperation(await this.runBackend(() => this.backend.getPrimaryKeys(request)));
|
|
455
254
|
}
|
|
456
255
|
/**
|
|
457
256
|
* Request information about foreign keys between two tables
|
|
@@ -460,22 +259,7 @@ class DBSQLSession {
|
|
|
460
259
|
* @returns DBSQLOperation
|
|
461
260
|
*/
|
|
462
261
|
async getCrossReference(request) {
|
|
463
|
-
await this.
|
|
464
|
-
const driver = await this.context.getDriver();
|
|
465
|
-
const clientConfig = this.context.getConfig();
|
|
466
|
-
const operationPromise = driver.getCrossReference({
|
|
467
|
-
sessionHandle: this.sessionHandle,
|
|
468
|
-
parentCatalogName: request.parentCatalogName,
|
|
469
|
-
parentSchemaName: request.parentSchemaName,
|
|
470
|
-
parentTableName: request.parentTableName,
|
|
471
|
-
foreignCatalogName: request.foreignCatalogName,
|
|
472
|
-
foreignSchemaName: request.foreignSchemaName,
|
|
473
|
-
foreignTableName: request.foreignTableName,
|
|
474
|
-
runAsync: this.getRunAsyncForMetadataOperations(),
|
|
475
|
-
...getDirectResultsOptions(request.maxRows, clientConfig),
|
|
476
|
-
});
|
|
477
|
-
const response = await this.handleResponse(operationPromise);
|
|
478
|
-
return this.createOperation(response);
|
|
262
|
+
return this.wrapOperation(await this.runBackend(() => this.backend.getCrossReference(request)));
|
|
479
263
|
}
|
|
480
264
|
/**
|
|
481
265
|
* Closes the session
|
|
@@ -487,7 +271,6 @@ class DBSQLSession {
|
|
|
487
271
|
if (!this.isOpen) {
|
|
488
272
|
return Status_1.default.success();
|
|
489
273
|
}
|
|
490
|
-
// Close owned operations one by one, removing successfully closed ones from the list
|
|
491
274
|
await this.operations.closeAll();
|
|
492
275
|
// `latencyMs` on CONNECTION_CLOSE is the closeSession RPC duration, not the
|
|
493
276
|
// session lifetime. It's the symmetric counterpart of CREATE_SESSION's
|
|
@@ -506,17 +289,13 @@ class DBSQLSession {
|
|
|
506
289
|
});
|
|
507
290
|
};
|
|
508
291
|
try {
|
|
509
|
-
const driver = await this.context.getDriver();
|
|
510
292
|
closeStart = Date.now();
|
|
511
|
-
const
|
|
512
|
-
sessionHandle: this.sessionHandle,
|
|
513
|
-
});
|
|
514
|
-
Status_1.default.assert(response.status);
|
|
293
|
+
const status = await this.backend.close();
|
|
515
294
|
(_a = this.onClose) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
516
295
|
this.isOpen = false;
|
|
517
296
|
emitClose();
|
|
518
297
|
this.context.getLogger().log(IDBSQLLogger_1.LogLevel.debug, `Session closed with id: ${this.id}`);
|
|
519
|
-
return
|
|
298
|
+
return status;
|
|
520
299
|
}
|
|
521
300
|
catch (err) {
|
|
522
301
|
(_b = this.onClose) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
@@ -525,31 +304,34 @@ class DBSQLSession {
|
|
|
525
304
|
throw err;
|
|
526
305
|
}
|
|
527
306
|
}
|
|
528
|
-
|
|
529
|
-
Status_1.default.assert(response.status);
|
|
530
|
-
const handle = (0, utils_1.definedOrError)(response.operationHandle);
|
|
307
|
+
wrapOperation(backend) {
|
|
531
308
|
const operation = new DBSQLOperation_1.default({
|
|
532
|
-
|
|
533
|
-
directResults: response.directResults,
|
|
309
|
+
backend,
|
|
534
310
|
context: this.context,
|
|
535
311
|
sessionId: this.id,
|
|
536
312
|
});
|
|
537
313
|
this.operations.add(operation);
|
|
538
314
|
return operation;
|
|
539
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* Bracket a backend call with `failIfClosed()` on both sides. The pre-call
|
|
318
|
+
* check rejects work against an already-closed session; the post-call check
|
|
319
|
+
* rejects results that came back after a concurrent close (server-side
|
|
320
|
+
* close doesn't error out the in-flight RPC). Centralizing the pattern
|
|
321
|
+
* keeps the 10+ delegation methods readable and makes the contract
|
|
322
|
+
* impossible to forget.
|
|
323
|
+
*/
|
|
324
|
+
async runBackend(fn) {
|
|
325
|
+
await this.failIfClosed();
|
|
326
|
+
const result = await fn();
|
|
327
|
+
await this.failIfClosed();
|
|
328
|
+
return result;
|
|
329
|
+
}
|
|
540
330
|
async failIfClosed() {
|
|
541
331
|
if (!this.isOpen) {
|
|
542
332
|
throw new HiveDriverError_1.default('The session was closed or has expired');
|
|
543
333
|
}
|
|
544
334
|
}
|
|
545
|
-
async handleResponse(requestPromise) {
|
|
546
|
-
// Currently, after being closed sessions remains usable - server will not
|
|
547
|
-
// error out when trying to run operations on closed session. So it's
|
|
548
|
-
// basically useless to process any errors here
|
|
549
|
-
const result = await requestPromise;
|
|
550
|
-
await this.failIfClosed();
|
|
551
|
-
return result;
|
|
552
|
-
}
|
|
553
335
|
}
|
|
554
336
|
exports.default = DBSQLSession;
|
|
555
337
|
//# sourceMappingURL=DBSQLSession.js.map
|