@databricks/sql 1.14.0 → 1.16.0-rc.1
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 +12 -0
- package/dist/DBSQLClient.d.ts +102 -0
- package/dist/DBSQLClient.js +541 -55
- 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 +67 -17
- package/dist/DBSQLOperation.js +245 -217
- 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 -16
- package/dist/DBSQLSession.js +77 -268
- package/dist/DBSQLSession.js.map +1 -1
- package/dist/connection/auth/DatabricksOAuth/OAuthManager.js +10 -6
- package/dist/connection/auth/DatabricksOAuth/OAuthManager.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 +30 -0
- package/dist/contracts/IDBSQLClient.d.ts +115 -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/index.d.ts +2 -0
- package/dist/index.js +7 -3
- package/dist/index.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.d.ts +8 -1
- package/dist/result/CloudFetchResultHandler.js +64 -10
- package/dist/result/CloudFetchResultHandler.js.map +1 -1
- package/dist/result/RowSetProvider.d.ts +8 -1
- package/dist/result/RowSetProvider.js +110 -1
- package/dist/result/RowSetProvider.js.map +1 -1
- package/dist/telemetry/DatabricksTelemetryExporter.js +101 -34
- package/dist/telemetry/DatabricksTelemetryExporter.js.map +1 -1
- package/dist/telemetry/FeatureFlagCache.js +10 -4
- package/dist/telemetry/FeatureFlagCache.js.map +1 -1
- package/dist/telemetry/MetricsAggregator.d.ts +38 -0
- package/dist/telemetry/MetricsAggregator.js +249 -14
- package/dist/telemetry/MetricsAggregator.js.map +1 -1
- package/dist/telemetry/TelemetryClient.d.ts +94 -14
- package/dist/telemetry/TelemetryClient.js +252 -20
- package/dist/telemetry/TelemetryClient.js.map +1 -1
- package/dist/telemetry/TelemetryClientProvider.d.ts +28 -33
- package/dist/telemetry/TelemetryClientProvider.js +58 -52
- package/dist/telemetry/TelemetryClientProvider.js.map +1 -1
- package/dist/telemetry/TelemetryEventEmitter.d.ts +52 -26
- package/dist/telemetry/TelemetryEventEmitter.js +88 -109
- package/dist/telemetry/TelemetryEventEmitter.js.map +1 -1
- package/dist/telemetry/{urlUtils.d.ts → telemetryTypeMappers.d.ts} +8 -5
- package/dist/telemetry/telemetryTypeMappers.js +72 -0
- package/dist/telemetry/telemetryTypeMappers.js.map +1 -0
- package/dist/telemetry/telemetryUtils.d.ts +14 -0
- package/dist/telemetry/telemetryUtils.js +52 -1
- package/dist/telemetry/telemetryUtils.js.map +1 -1
- package/dist/telemetry/types.d.ts +48 -1
- package/dist/telemetry/types.js +5 -2
- package/dist/telemetry/types.js.map +1 -1
- 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/dist/version.js.map +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 +14 -3
- package/dist/telemetry/urlUtils.js +0 -35
- package/dist/telemetry/urlUtils.js.map +0 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel → driver log bridge.
|
|
3
|
+
*
|
|
4
|
+
* The Rust kernel emits its diagnostics via `tracing`. In a Node process those
|
|
5
|
+
* events have no subscriber and are dropped — so by default the driver's
|
|
6
|
+
* `DBSQLLogger` only ever saw JS-side lines. The napi binding's
|
|
7
|
+
* `initKernelLogging` installs a process-global subscriber that forwards
|
|
8
|
+
* kernel events (batched) to a JS callback; this module wires that callback
|
|
9
|
+
* into the **same** `IDBSQLLogger` the driver logs through, so logs from all
|
|
10
|
+
* three layers (driver, napi shim, kernel) land in one place — and one file
|
|
11
|
+
* when the logger has a file transport.
|
|
12
|
+
*
|
|
13
|
+
* Verbosity follows the driver's logger level (see `installKernelLogBridge`),
|
|
14
|
+
* filtered kernel-side so we don't pay the channel/bridge cost for events the
|
|
15
|
+
* sink would discard anyway.
|
|
16
|
+
*/
|
|
17
|
+
import IDBSQLLogger, { LogLevel } from '../contracts/IDBSQLLogger';
|
|
18
|
+
import { KernelNativeBinding, KernelNativeLogRecord } from './KernelNativeLoader';
|
|
19
|
+
/**
|
|
20
|
+
* Map a kernel level string (`error`/`warn`/`info`/`debug`/`trace`) onto the
|
|
21
|
+
* driver's `LogLevel`. The kernel's `trace` has no `LogLevel` analogue, so it
|
|
22
|
+
* folds into `debug` (the most verbose driver level).
|
|
23
|
+
*/
|
|
24
|
+
export declare function kernelLevelToLogLevel(level: string): LogLevel;
|
|
25
|
+
/**
|
|
26
|
+
* Map a driver `LogLevel` onto the kernel level string the napi bridge expects.
|
|
27
|
+
* The `LogLevel` enum values are already the kernel-compatible lower-case
|
|
28
|
+
* strings, so this is the identity at runtime — kept as an explicit function so
|
|
29
|
+
* the boundary is named and a future divergence has one place to live.
|
|
30
|
+
*/
|
|
31
|
+
export declare function logLevelToKernelLevel(level: LogLevel): string;
|
|
32
|
+
/**
|
|
33
|
+
* Format one kernel log record into a single driver log line, tagged with its
|
|
34
|
+
* origin so kernel lines are distinguishable from driver lines in a shared
|
|
35
|
+
* sink/file.
|
|
36
|
+
*/
|
|
37
|
+
export declare function formatKernelLine(record: KernelNativeLogRecord): string;
|
|
38
|
+
/**
|
|
39
|
+
* Install the kernel→driver log bridge: forward kernel `tracing` events into
|
|
40
|
+
* `logger` at `level`.
|
|
41
|
+
*
|
|
42
|
+
* - **Verbosity** is set kernel-side to `level` so events the sink would drop
|
|
43
|
+
* never cross the bridge.
|
|
44
|
+
* - **Process-global, last-writer-wins:** the napi binding holds a single
|
|
45
|
+
* process-global subscriber + sink (a `tracing` global subscriber installs
|
|
46
|
+
* once). Each call retargets the sink to `logger`, so in a multi-client
|
|
47
|
+
* process the most recently connected client's logger receives kernel logs —
|
|
48
|
+
* mirroring the Python connector's `pyo3_log` model. Single-client apps, the
|
|
49
|
+
* common case, are unaffected.
|
|
50
|
+
* - **Runtime retargeting:** if `logger` exposes `onLevelChange` (as
|
|
51
|
+
* `DBSQLLogger` does), the bridge subscribes so a later `logger.setLevel(...)`
|
|
52
|
+
* also retargets the kernel-side filter via `setKernelLogLevel` — keeping
|
|
53
|
+
* kernel verbosity in lock-step with the driver's at runtime, not just at
|
|
54
|
+
* connect. Loggers without it still get the connect-time level.
|
|
55
|
+
* - **Graceful on older bindings:** if the loaded `.node` predates
|
|
56
|
+
* `initKernelLogging`, this is a no-op (kernel logs simply stay unbridged)
|
|
57
|
+
* rather than a hard failure — logging is advisory.
|
|
58
|
+
*
|
|
59
|
+
* Returns an **unsubscribe** function the caller must invoke on teardown
|
|
60
|
+
* (`KernelBackend.close()`) to drop the level-change listener; it is a safe no-op
|
|
61
|
+
* when nothing was subscribed.
|
|
62
|
+
*/
|
|
63
|
+
export declare function installKernelLogBridge(binding: KernelNativeBinding, logger: IDBSQLLogger, level: LogLevel): () => void;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2026 Databricks, Inc.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.installKernelLogBridge = exports.formatKernelLine = exports.logLevelToKernelLevel = exports.kernelLevelToLogLevel = void 0;
|
|
17
|
+
/**
|
|
18
|
+
* Kernel → driver log bridge.
|
|
19
|
+
*
|
|
20
|
+
* The Rust kernel emits its diagnostics via `tracing`. In a Node process those
|
|
21
|
+
* events have no subscriber and are dropped — so by default the driver's
|
|
22
|
+
* `DBSQLLogger` only ever saw JS-side lines. The napi binding's
|
|
23
|
+
* `initKernelLogging` installs a process-global subscriber that forwards
|
|
24
|
+
* kernel events (batched) to a JS callback; this module wires that callback
|
|
25
|
+
* into the **same** `IDBSQLLogger` the driver logs through, so logs from all
|
|
26
|
+
* three layers (driver, napi shim, kernel) land in one place — and one file
|
|
27
|
+
* when the logger has a file transport.
|
|
28
|
+
*
|
|
29
|
+
* Verbosity follows the driver's logger level (see `installKernelLogBridge`),
|
|
30
|
+
* filtered kernel-side so we don't pay the channel/bridge cost for events the
|
|
31
|
+
* sink would discard anyway.
|
|
32
|
+
*/
|
|
33
|
+
const IDBSQLLogger_1 = require("../contracts/IDBSQLLogger");
|
|
34
|
+
/**
|
|
35
|
+
* Map a kernel level string (`error`/`warn`/`info`/`debug`/`trace`) onto the
|
|
36
|
+
* driver's `LogLevel`. The kernel's `trace` has no `LogLevel` analogue, so it
|
|
37
|
+
* folds into `debug` (the most verbose driver level).
|
|
38
|
+
*/
|
|
39
|
+
function kernelLevelToLogLevel(level) {
|
|
40
|
+
switch (level) {
|
|
41
|
+
case 'error':
|
|
42
|
+
return IDBSQLLogger_1.LogLevel.error;
|
|
43
|
+
case 'warn':
|
|
44
|
+
return IDBSQLLogger_1.LogLevel.warn;
|
|
45
|
+
case 'info':
|
|
46
|
+
return IDBSQLLogger_1.LogLevel.info;
|
|
47
|
+
case 'debug':
|
|
48
|
+
case 'trace':
|
|
49
|
+
return IDBSQLLogger_1.LogLevel.debug;
|
|
50
|
+
default:
|
|
51
|
+
// Unknown kernel level — surface it rather than drop it; debug is the
|
|
52
|
+
// least surprising bucket for an unrecognised severity.
|
|
53
|
+
return IDBSQLLogger_1.LogLevel.debug;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.kernelLevelToLogLevel = kernelLevelToLogLevel;
|
|
57
|
+
/**
|
|
58
|
+
* Map a driver `LogLevel` onto the kernel level string the napi bridge expects.
|
|
59
|
+
* The `LogLevel` enum values are already the kernel-compatible lower-case
|
|
60
|
+
* strings, so this is the identity at runtime — kept as an explicit function so
|
|
61
|
+
* the boundary is named and a future divergence has one place to live.
|
|
62
|
+
*/
|
|
63
|
+
function logLevelToKernelLevel(level) {
|
|
64
|
+
return level;
|
|
65
|
+
}
|
|
66
|
+
exports.logLevelToKernelLevel = logLevelToKernelLevel;
|
|
67
|
+
/**
|
|
68
|
+
* Format one kernel log record into a single driver log line, tagged with its
|
|
69
|
+
* origin so kernel lines are distinguishable from driver lines in a shared
|
|
70
|
+
* sink/file.
|
|
71
|
+
*/
|
|
72
|
+
function formatKernelLine(record) {
|
|
73
|
+
return `[kernel ${record.target}] ${record.message}`;
|
|
74
|
+
}
|
|
75
|
+
exports.formatKernelLine = formatKernelLine;
|
|
76
|
+
/**
|
|
77
|
+
* Install the kernel→driver log bridge: forward kernel `tracing` events into
|
|
78
|
+
* `logger` at `level`.
|
|
79
|
+
*
|
|
80
|
+
* - **Verbosity** is set kernel-side to `level` so events the sink would drop
|
|
81
|
+
* never cross the bridge.
|
|
82
|
+
* - **Process-global, last-writer-wins:** the napi binding holds a single
|
|
83
|
+
* process-global subscriber + sink (a `tracing` global subscriber installs
|
|
84
|
+
* once). Each call retargets the sink to `logger`, so in a multi-client
|
|
85
|
+
* process the most recently connected client's logger receives kernel logs —
|
|
86
|
+
* mirroring the Python connector's `pyo3_log` model. Single-client apps, the
|
|
87
|
+
* common case, are unaffected.
|
|
88
|
+
* - **Runtime retargeting:** if `logger` exposes `onLevelChange` (as
|
|
89
|
+
* `DBSQLLogger` does), the bridge subscribes so a later `logger.setLevel(...)`
|
|
90
|
+
* also retargets the kernel-side filter via `setKernelLogLevel` — keeping
|
|
91
|
+
* kernel verbosity in lock-step with the driver's at runtime, not just at
|
|
92
|
+
* connect. Loggers without it still get the connect-time level.
|
|
93
|
+
* - **Graceful on older bindings:** if the loaded `.node` predates
|
|
94
|
+
* `initKernelLogging`, this is a no-op (kernel logs simply stay unbridged)
|
|
95
|
+
* rather than a hard failure — logging is advisory.
|
|
96
|
+
*
|
|
97
|
+
* Returns an **unsubscribe** function the caller must invoke on teardown
|
|
98
|
+
* (`KernelBackend.close()`) to drop the level-change listener; it is a safe no-op
|
|
99
|
+
* when nothing was subscribed.
|
|
100
|
+
*/
|
|
101
|
+
function installKernelLogBridge(binding, logger, level) {
|
|
102
|
+
// Defensive: a stale/older binding without the bridge export must not break
|
|
103
|
+
// connect() — logging is non-critical.
|
|
104
|
+
if (typeof binding.initKernelLogging !== 'function') {
|
|
105
|
+
return () => { };
|
|
106
|
+
}
|
|
107
|
+
const callback = (err, records) => {
|
|
108
|
+
if (err || !records) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
for (const record of records) {
|
|
112
|
+
logger.log(kernelLevelToLogLevel(record.level), formatKernelLine(record));
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
binding.initKernelLogging(callback, logLevelToKernelLevel(level));
|
|
116
|
+
// Keep the kernel's level in lock-step with runtime `logger.setLevel(...)`
|
|
117
|
+
// calls. Requires both a logger that notifies (`onLevelChange`) and a binding
|
|
118
|
+
// that can retarget (`setKernelLogLevel`); otherwise the connect-time level
|
|
119
|
+
// stands and there is nothing to unsubscribe.
|
|
120
|
+
if (typeof logger.onLevelChange === 'function' && typeof binding.setKernelLogLevel === 'function') {
|
|
121
|
+
return logger.onLevelChange((newLevel) => {
|
|
122
|
+
binding.setKernelLogLevel(logLevelToKernelLevel(newLevel));
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return () => { };
|
|
126
|
+
}
|
|
127
|
+
exports.installKernelLogBridge = installKernelLogBridge;
|
|
128
|
+
//# sourceMappingURL=KernelLogging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KernelLogging.js","sourceRoot":"","sources":["../../lib/kernel/KernelLogging.ts"],"names":[],"mappings":";AAAA,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAEjC;;;;;;;;;;;;;;;GAeG;AAEH,4DAAmE;AAGnE;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,KAAa;IACjD,QAAQ,KAAK,EAAE;QACb,KAAK,OAAO;YACV,OAAO,uBAAQ,CAAC,KAAK,CAAC;QACxB,KAAK,MAAM;YACT,OAAO,uBAAQ,CAAC,IAAI,CAAC;QACvB,KAAK,MAAM;YACT,OAAO,uBAAQ,CAAC,IAAI,CAAC;QACvB,KAAK,OAAO,CAAC;QACb,KAAK,OAAO;YACV,OAAO,uBAAQ,CAAC,KAAK,CAAC;QACxB;YACE,sEAAsE;YACtE,wDAAwD;YACxD,OAAO,uBAAQ,C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;KACJ;IAED,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;AAClB,CAAC;AAjCD,wDAiCC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy loader for the SEA (Statement Execution API) native binding.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the load-failure-tolerant pattern of `lib/utils/lz4.ts`: the
|
|
5
|
+
* `.node` artifact ships via per-platform optional dependencies
|
|
6
|
+
* (`@databricks/databricks-sql-kernel-<triple>`), so its absence must not crash
|
|
7
|
+
* a Thrift-only consumer of the driver. Callers that actually need
|
|
8
|
+
* kernel construct a {@link KernelNativeLoader} (or use the process-global
|
|
9
|
+
* {@link getKernelNative}) which throws a structured error if the binding
|
|
10
|
+
* could not be loaded.
|
|
11
|
+
*
|
|
12
|
+
* M0 publishes a single triple (`linux-x64-gnu`); see
|
|
13
|
+
* `native/kernel/README.md` for the supported-platform policy.
|
|
14
|
+
*/
|
|
15
|
+
import type { Connection as NativeConnection, Statement as NativeStatement, ConnectionOptions as NativeConnectionOptions, ArrowBatch as NativeArrowBatch, ArrowSchema as NativeArrowSchema, ExecuteOptions as NativeExecuteOptions, TypedValueInput as NativeTypedValueInput, NamedTypedValueInput as NativeNamedTypedValueInput, AsyncStatement as NativeAsyncStatement, AsyncResultHandle as NativeAsyncResultHandle, CancellableExecution as NativeCancellableExecution, LogRecord as NativeLogRecord } from '../../native/kernel';
|
|
16
|
+
export type KernelConnectionOptions = NativeConnectionOptions;
|
|
17
|
+
export type KernelArrowBatch = NativeArrowBatch;
|
|
18
|
+
export type KernelArrowSchema = NativeArrowSchema;
|
|
19
|
+
export type KernelConnection = NativeConnection;
|
|
20
|
+
export type KernelStatement = NativeStatement;
|
|
21
|
+
export type KernelNativeExecuteOptions = NativeExecuteOptions;
|
|
22
|
+
export type KernelNativeTypedValueInput = NativeTypedValueInput;
|
|
23
|
+
export type KernelNativeNamedTypedValueInput = NativeNamedTypedValueInput;
|
|
24
|
+
export type KernelNativeAsyncStatement = NativeAsyncStatement;
|
|
25
|
+
export type KernelNativeAsyncResultHandle = NativeAsyncResultHandle;
|
|
26
|
+
export type KernelNativeCancellableExecution = NativeCancellableExecution;
|
|
27
|
+
export type KernelNativeLogRecord = NativeLogRecord;
|
|
28
|
+
/**
|
|
29
|
+
* The full native binding surface, derived from the generated module
|
|
30
|
+
* so it can never drift from the `.d.ts` contract: when the kernel
|
|
31
|
+
* adds or renames a free function / class, this type follows
|
|
32
|
+
* automatically and `defaultRequire`'s cast stays correct.
|
|
33
|
+
*/
|
|
34
|
+
export type KernelNativeBinding = typeof import('../../native/kernel');
|
|
35
|
+
/**
|
|
36
|
+
* Loads and caches the kernel native binding. Exposed as a class with an
|
|
37
|
+
* injectable `load` seam so consumers (e.g. `KernelBackend`) can be unit
|
|
38
|
+
* tested with a stub binding instead of requiring a real `.node` on the
|
|
39
|
+
* test machine. Most production code uses the process-global default
|
|
40
|
+
* via {@link getKernelNative} / {@link tryGetKernelNative}.
|
|
41
|
+
*/
|
|
42
|
+
export declare class KernelNativeLoader {
|
|
43
|
+
private readonly load;
|
|
44
|
+
private readonly nodeMajor;
|
|
45
|
+
private cached;
|
|
46
|
+
private cachedError;
|
|
47
|
+
/**
|
|
48
|
+
* @param load injectable module-require seam (stub a binding in tests)
|
|
49
|
+
* @param nodeMajor injectable Node-major detector. Defaults to reading the
|
|
50
|
+
* live `process.version`; injected in unit tests so the
|
|
51
|
+
* load/shape branches are exercised independently of the
|
|
52
|
+
* runner's actual Node version (the matrix spans 14–20).
|
|
53
|
+
*/
|
|
54
|
+
constructor(load?: () => KernelNativeBinding, nodeMajor?: () => number);
|
|
55
|
+
private tryLoad;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the loaded native binding. Throws a structured error if the
|
|
58
|
+
* binding is unavailable on this platform / Node version.
|
|
59
|
+
*/
|
|
60
|
+
get(): KernelNativeBinding;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the loaded binding or `undefined` if it could not be
|
|
63
|
+
* loaded. Use this for capability-detection at startup; use
|
|
64
|
+
* {@link get} at the point where kernel is actually required.
|
|
65
|
+
*/
|
|
66
|
+
tryGet(): KernelNativeBinding | undefined;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Returns the loaded native binding from the process-global loader.
|
|
70
|
+
* Throws a structured error if the binding is unavailable.
|
|
71
|
+
*/
|
|
72
|
+
export declare function getKernelNative(): KernelNativeBinding;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the loaded binding from the process-global loader, or
|
|
75
|
+
* `undefined` if it could not be loaded.
|
|
76
|
+
*/
|
|
77
|
+
export declare function tryGetKernelNative(): KernelNativeBinding | undefined;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2026 Databricks, Inc.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.tryGetKernelNative = exports.getKernelNative = exports.KernelNativeLoader = void 0;
|
|
17
|
+
const MIN_NODE_MAJOR = 18;
|
|
18
|
+
function detectNodeMajor() {
|
|
19
|
+
// `process.version` is `vX.Y.Z`; parseInt stops at the first non-digit.
|
|
20
|
+
return parseInt(process.version.slice(1), 10);
|
|
21
|
+
}
|
|
22
|
+
function platformLabel() {
|
|
23
|
+
return `${process.platform}-${process.arch}`;
|
|
24
|
+
}
|
|
25
|
+
function loadFailureHint(err) {
|
|
26
|
+
const platform = platformLabel();
|
|
27
|
+
// Do not name a concrete package: the published name uses the napi-rs
|
|
28
|
+
// triple (e.g. `-linux-x64-gnu` / `-linux-x64-musl` / `-win32-x64-msvc`),
|
|
29
|
+
// not the bare `${platform}` shown here, so a literal example would
|
|
30
|
+
// 404. Point at the README's supported-triple list instead.
|
|
31
|
+
const installHint = 'Install the matching @databricks/databricks-sql-kernel-* optional dependency for your platform ' +
|
|
32
|
+
'(see native/kernel/README.md for the supported triples; M0 ships linux-x64-gnu only).';
|
|
33
|
+
if (err.code === 'MODULE_NOT_FOUND') {
|
|
34
|
+
return `kernel native binding not installed for platform ${platform} on Node ${process.version}. ${installHint}`;
|
|
35
|
+
}
|
|
36
|
+
if (err.code === 'ERR_DLOPEN_FAILED') {
|
|
37
|
+
// Surface the underlying dlerror string (e.g. `GLIBC_2.32 not found`)
|
|
38
|
+
// plus concrete remediation — without it the cause is invisible.
|
|
39
|
+
return (`kernel native binding present but failed to dlopen on platform ${platform} / Node ${process.version}: ` +
|
|
40
|
+
`${err.message}. Common causes: glibc/musl mismatch (e.g. Alpine Linux — install the -musl variant), ` +
|
|
41
|
+
`Node ABI mismatch (try \`rm -rf node_modules && npm install\`), or CPU-architecture mismatch. ` +
|
|
42
|
+
`The binding requires Node >=${MIN_NODE_MAJOR}.`);
|
|
43
|
+
}
|
|
44
|
+
return `kernel native binding failed to load on platform ${platform} / Node ${process.version}: ${err.message}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Default loader: resolves `native/kernel/index.js` (the napi-rs router),
|
|
48
|
+
* which selects the per-platform `.node`. `.js` is omitted so eslint's
|
|
49
|
+
* `import/extensions` rule accepts the call.
|
|
50
|
+
*/
|
|
51
|
+
function defaultRequire() {
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
|
|
53
|
+
return require('../../native/kernel');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Verify the loaded module exposes the surface the driver depends on.
|
|
57
|
+
* Catches kernel-side renames at load time rather than letting them
|
|
58
|
+
* surface as `undefined is not a function` deep in a call path.
|
|
59
|
+
*/
|
|
60
|
+
function assertBindingShape(binding) {
|
|
61
|
+
const missing = [];
|
|
62
|
+
if (typeof binding.version !== 'function')
|
|
63
|
+
missing.push('version');
|
|
64
|
+
if (typeof binding.openSession !== 'function')
|
|
65
|
+
missing.push('openSession');
|
|
66
|
+
if (typeof binding.Connection !== 'function')
|
|
67
|
+
missing.push('Connection');
|
|
68
|
+
if (typeof binding.Statement !== 'function')
|
|
69
|
+
missing.push('Statement');
|
|
70
|
+
// Classes the async (submit/poll) and cancellable-sync execution paths depend
|
|
71
|
+
// on. Checking them here turns a stale/older cached `.node` into a clear
|
|
72
|
+
// load-time error instead of an `X is not a function` mid-query (e.g.
|
|
73
|
+
// `Connection.submitStatement` / `executeStatementCancellable`).
|
|
74
|
+
if (typeof binding.AsyncStatement !== 'function')
|
|
75
|
+
missing.push('AsyncStatement');
|
|
76
|
+
if (typeof binding.AsyncResultHandle !== 'function')
|
|
77
|
+
missing.push('AsyncResultHandle');
|
|
78
|
+
if (typeof binding.CancellableExecution !== 'function')
|
|
79
|
+
missing.push('CancellableExecution');
|
|
80
|
+
if (missing.length > 0) {
|
|
81
|
+
throw new Error(`kernel native binding loaded but is missing expected export(s): ${missing.join(', ')}. ` +
|
|
82
|
+
`The kernel-generated binding and the JS loader are out of sync.`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Loads and caches the kernel native binding. Exposed as a class with an
|
|
87
|
+
* injectable `load` seam so consumers (e.g. `KernelBackend`) can be unit
|
|
88
|
+
* tested with a stub binding instead of requiring a real `.node` on the
|
|
89
|
+
* test machine. Most production code uses the process-global default
|
|
90
|
+
* via {@link getKernelNative} / {@link tryGetKernelNative}.
|
|
91
|
+
*/
|
|
92
|
+
class KernelNativeLoader {
|
|
93
|
+
/**
|
|
94
|
+
* @param load injectable module-require seam (stub a binding in tests)
|
|
95
|
+
* @param nodeMajor injectable Node-major detector. Defaults to reading the
|
|
96
|
+
* live `process.version`; injected in unit tests so the
|
|
97
|
+
* load/shape branches are exercised independently of the
|
|
98
|
+
* runner's actual Node version (the matrix spans 14–20).
|
|
99
|
+
*/
|
|
100
|
+
constructor(load = defaultRequire, nodeMajor = detectNodeMajor) {
|
|
101
|
+
this.load = load;
|
|
102
|
+
this.nodeMajor = nodeMajor;
|
|
103
|
+
}
|
|
104
|
+
tryLoad() {
|
|
105
|
+
const nodeMajor = this.nodeMajor();
|
|
106
|
+
// Fail closed: if we cannot determine the Node major (NaN) or it is
|
|
107
|
+
// below the floor, refuse the load and fall back to Thrift.
|
|
108
|
+
if (!Number.isFinite(nodeMajor) || nodeMajor < MIN_NODE_MAJOR) {
|
|
109
|
+
this.cachedError = new Error(`kernel native binding requires Node >=${MIN_NODE_MAJOR}; running Node ${process.version}. ` +
|
|
110
|
+
`Continue using the Thrift backend on this runtime.`);
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const binding = this.load();
|
|
115
|
+
assertBindingShape(binding);
|
|
116
|
+
return binding;
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
if (err instanceof Error && 'code' in err) {
|
|
120
|
+
this.cachedError = new Error(loadFailureHint(err));
|
|
121
|
+
}
|
|
122
|
+
else if (err instanceof Error) {
|
|
123
|
+
// Shape-check failure or any other Error — preserve its message.
|
|
124
|
+
this.cachedError = err;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
this.cachedError = new Error(`kernel native binding failed to load with non-standard error: ${String(err)}`);
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Returns the loaded native binding. Throws a structured error if the
|
|
134
|
+
* binding is unavailable on this platform / Node version.
|
|
135
|
+
*/
|
|
136
|
+
get() {
|
|
137
|
+
var _a, _b;
|
|
138
|
+
if (this.cached === undefined) {
|
|
139
|
+
this.cached = (_a = this.tryLoad()) !== null && _a !== void 0 ? _a : null;
|
|
140
|
+
}
|
|
141
|
+
if (this.cached === null) {
|
|
142
|
+
throw (_b = this.cachedError) !== null && _b !== void 0 ? _b : new Error('kernel native binding unavailable');
|
|
143
|
+
}
|
|
144
|
+
return this.cached;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Returns the loaded binding or `undefined` if it could not be
|
|
148
|
+
* loaded. Use this for capability-detection at startup; use
|
|
149
|
+
* {@link get} at the point where kernel is actually required.
|
|
150
|
+
*/
|
|
151
|
+
tryGet() {
|
|
152
|
+
var _a, _b;
|
|
153
|
+
if (this.cached === undefined) {
|
|
154
|
+
this.cached = (_a = this.tryLoad()) !== null && _a !== void 0 ? _a : null;
|
|
155
|
+
}
|
|
156
|
+
return (_b = this.cached) !== null && _b !== void 0 ? _b : undefined;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.KernelNativeLoader = KernelNativeLoader;
|
|
160
|
+
// Process-global default instance + thin convenience wrappers.
|
|
161
|
+
const defaultLoader = new KernelNativeLoader();
|
|
162
|
+
/**
|
|
163
|
+
* Returns the loaded native binding from the process-global loader.
|
|
164
|
+
* Throws a structured error if the binding is unavailable.
|
|
165
|
+
*/
|
|
166
|
+
function getKernelNative() {
|
|
167
|
+
return defaultLoader.get();
|
|
168
|
+
}
|
|
169
|
+
exports.getKernelNative = getKernelNative;
|
|
170
|
+
/**
|
|
171
|
+
* Returns the loaded binding from the process-global loader, or
|
|
172
|
+
* `undefined` if it could not be loaded.
|
|
173
|
+
*/
|
|
174
|
+
function tryGetKernelNative() {
|
|
175
|
+
return defaultLoader.tryGet();
|
|
176
|
+
}
|
|
177
|
+
exports.tryGetKernelNative = tryGetKernelNative;
|
|
178
|
+
//# sourceMappingURL=KernelNativeLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KernelNativeLoader.js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ACrB,CAAC;IAED;;;;OAIG;IACH,MAAM;;QACJ,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE;YAC7B,IAAI,CAAC,MAAM,GAAG,MAAA,IAAI,CAAC,OAAO,EAAE,mCAAI,IAAI,CAAC;SACtC;QACD,OAAO,MAAA,IAAI,CAAC,MAAM,mCAAI,SAAS,CAAC;IAClC,CAAC;CACF;AAvED,gDAuEC;AAED,+DAA+D;AAC/D,MAAM,aAAa,GAAG,IAAI,kBAAkB,EAAE,CAAC;AAE/C;;;GAGG;AACH,SAAgB,eAAe;IAC7B,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC;AAC7B,CAAC;AAFD,0CAEC;AAED;;;GAGG;AACH,SAAgB,kBAAkB;IAChC,OAAO,aAAa,CAAC,MAAM,EAAE,CAAC;AAChC,CAAC;AAFD,gDAEC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import IOperationBackend, { IOperationBackendWaitOptions } from '../contracts/IOperationBackend';
|
|
2
|
+
import { OperationStatus } from '../contracts/OperationStatus';
|
|
3
|
+
import { ResultMetadata } from '../contracts/ResultMetadata';
|
|
4
|
+
import IClientContext from '../contracts/IClientContext';
|
|
5
|
+
import Status from '../dto/Status';
|
|
6
|
+
import { KernelStatement, KernelNativeAsyncStatement, KernelNativeCancellableExecution } from './KernelNativeLoader';
|
|
7
|
+
import { KernelStatementHandle } from './KernelOperationLifecycle';
|
|
8
|
+
/**
|
|
9
|
+
* Structural union of the lifecycle surface (cancel/close) and the
|
|
10
|
+
* fetch surface (fetchNextBatch/schema). The real napi `Statement`
|
|
11
|
+
* implements both; lifecycle-only test stubs implement only the
|
|
12
|
+
* cancel/close half — fetch methods are accessed lazily and the
|
|
13
|
+
* lifecycle tests never reach that path.
|
|
14
|
+
*/
|
|
15
|
+
export type KernelOperationStatement = KernelStatementHandle & Partial<KernelStatement>;
|
|
16
|
+
/**
|
|
17
|
+
* Constructor options for `KernelOperationBackend`. Exactly one of
|
|
18
|
+
* `asyncStatement` (query path — `Connection.submitStatement`) or `statement`
|
|
19
|
+
* (metadata path — `Connection.list*` / `get*`, already terminal) must be set.
|
|
20
|
+
*/
|
|
21
|
+
export interface KernelOperationBackendOptions {
|
|
22
|
+
/** The pending napi `AsyncStatement` from `Connection.submitStatement(...)`. */
|
|
23
|
+
asyncStatement?: KernelNativeAsyncStatement;
|
|
24
|
+
/** The terminal napi `Statement` from a metadata call. */
|
|
25
|
+
statement?: KernelOperationStatement;
|
|
26
|
+
/**
|
|
27
|
+
* The pending napi `CancellableExecution` from
|
|
28
|
+
* `Connection.executeStatementCancellable(...)` — the sync (`runAsync: false`)
|
|
29
|
+
* query path. `result()` drives the blocking `execute()` to a terminal
|
|
30
|
+
* `Statement` (the fetch handle); `cancel()` fires a detached canceller that
|
|
31
|
+
* interrupts a still-running `result()` mid-COMPUTE. Exactly one of
|
|
32
|
+
* `asyncStatement`, `statement`, or `cancellableExecution` must be set.
|
|
33
|
+
*/
|
|
34
|
+
cancellableExecution?: KernelNativeCancellableExecution;
|
|
35
|
+
context: IClientContext;
|
|
36
|
+
/**
|
|
37
|
+
* Optional override for `id`. Defaults to the napi statement-id when the
|
|
38
|
+
* handle exposes one, else a fresh UUIDv4.
|
|
39
|
+
*/
|
|
40
|
+
id?: string;
|
|
41
|
+
}
|
|
42
|
+
export default class KernelOperationBackend implements IOperationBackend {
|
|
43
|
+
private readonly asyncStatement?;
|
|
44
|
+
private readonly cancellableExecution?;
|
|
45
|
+
private blockingStatement?;
|
|
46
|
+
private richStatusFieldsPromise?;
|
|
47
|
+
private readonly lifecycleHandle;
|
|
48
|
+
private readonly context;
|
|
49
|
+
private readonly _id;
|
|
50
|
+
private readonly lifecycle;
|
|
51
|
+
private resultSlicer?;
|
|
52
|
+
private resultsProvider?;
|
|
53
|
+
private metadata?;
|
|
54
|
+
private metadataPromise?;
|
|
55
|
+
private fetchHandlePromise?;
|
|
56
|
+
constructor({ asyncStatement, statement, cancellableExecution, context, id }: KernelOperationBackendOptions);
|
|
57
|
+
get id(): string;
|
|
58
|
+
hasResultSet(): boolean;
|
|
59
|
+
fetchChunk({ limit, disableBuffering, isClosed, }: {
|
|
60
|
+
limit: number;
|
|
61
|
+
disableBuffering?: boolean;
|
|
62
|
+
isClosed?: () => boolean;
|
|
63
|
+
}): Promise<Array<object>>;
|
|
64
|
+
hasMore(): Promise<boolean>;
|
|
65
|
+
getResultMetadata(): Promise<ResultMetadata>;
|
|
66
|
+
status(_progress: boolean): Promise<OperationStatus>;
|
|
67
|
+
waitUntilReady(options?: IOperationBackendWaitOptions): Promise<void>;
|
|
68
|
+
cancel(): Promise<Status>;
|
|
69
|
+
close(): Promise<Status>;
|
|
70
|
+
/**
|
|
71
|
+
* Read the kernel's rich operation-status fields (`numModifiedRows` /
|
|
72
|
+
* `displayMessage` / `diagnosticInfo` / `errorDetailsJson`) off the terminal
|
|
73
|
+
* sync `Statement`. These accessors live only on the blocking `Statement`
|
|
74
|
+
* (metadata path, or the sync `runAsync:false` path once `result()` has
|
|
75
|
+
* resolved) — not on the async `AsyncStatement` / `AsyncResultHandle` — so:
|
|
76
|
+
*
|
|
77
|
+
* - on the async path we have no `Statement`, so we return all-null;
|
|
78
|
+
* - on the sync path we await `getFetchHandle()` first, which both drives
|
|
79
|
+
* `result()` to completion and stores the resolved `Statement` on
|
|
80
|
+
* `blockingStatement` (the handle that backs the accessors);
|
|
81
|
+
* - if the (older) binding predates these accessors we degrade to all-null
|
|
82
|
+
* rather than throwing — `getOperationStatus()` must never fail just
|
|
83
|
+
* because the rich fields are unavailable.
|
|
84
|
+
*
|
|
85
|
+
* Errors from the individual accessors are swallowed to null: a failed
|
|
86
|
+
* status-field read must not turn a successful operation's status query into
|
|
87
|
+
* a throw. The fields are best-effort metadata, not the operation outcome.
|
|
88
|
+
*/
|
|
89
|
+
private readRichStatusFields;
|
|
90
|
+
private computeRichStatusFields;
|
|
91
|
+
/**
|
|
92
|
+
* Read the four rich-status accessors (`numModifiedRows` / `displayMessage` /
|
|
93
|
+
* `diagnosticInfo` / `errorDetailsJson`) off a kernel handle — the terminal
|
|
94
|
+
* sync `Statement` or the async `AsyncStatement`, which expose the same
|
|
95
|
+
* accessor shape. Per-field read errors are swallowed to `null`: a failed
|
|
96
|
+
* status-field read must never turn a successful operation's status query
|
|
97
|
+
* into a throw. Degrades to all-null for a missing handle or a binding that
|
|
98
|
+
* predates the accessors.
|
|
99
|
+
*/
|
|
100
|
+
private readStatusFieldsFrom;
|
|
101
|
+
/**
|
|
102
|
+
* Poll the kernel `AsyncStatement` to a terminal state on a fixed 100ms
|
|
103
|
+
* cadence, mirroring the Thrift backend's `waitUntilReady` loop. We poll
|
|
104
|
+
* `status()` (a cheap GetStatementStatus RPC) rather than awaiting
|
|
105
|
+
* `awaitResult()` directly so that `status()` reports the real
|
|
106
|
+
* Pending/Running/Succeeded state to a progress callback each tick, and so a
|
|
107
|
+
* JS-initiated `cancel()`/`close()` is observed between ticks via
|
|
108
|
+
* `failIfNotActive`. On success it materialises the result handle (so the
|
|
109
|
+
* first fetch is free); on a server-driven terminal state it throws the typed
|
|
110
|
+
* error the `IOperationBackend` contract requires.
|
|
111
|
+
*
|
|
112
|
+
* Terminal errors are thrown as `OperationStateError` (NOT plain
|
|
113
|
+
* `HiveDriverError`) for Cancelled/Closed/Unknown, because the DBSQLOperation
|
|
114
|
+
* facade only mirrors its `cancelled`/`closed` flags when
|
|
115
|
+
* `err instanceof OperationStateError` — exactly as the Thrift backend does.
|
|
116
|
+
* The Failed branch surfaces the kernel's typed SQL-error envelope via
|
|
117
|
+
* `awaitResult()`.
|
|
118
|
+
*/
|
|
119
|
+
private waitUntilReadyAsync;
|
|
120
|
+
/**
|
|
121
|
+
* Sync (`runAsync: false`) execute path. Drives the blocking
|
|
122
|
+
* `CancellableExecution.result()` to a terminal `Statement` (the kernel polls
|
|
123
|
+
* to completion server-side). The
|
|
124
|
+
* await is interruptible: a JS-initiated `cancel()` fires the detached
|
|
125
|
+
* canceller, the server flips the statement terminal, and the parked
|
|
126
|
+
* `result()` rejects with `Cancelled` — which we map to the typed
|
|
127
|
+
* `OperationStateError(Canceled)`.
|
|
128
|
+
*
|
|
129
|
+
* Unlike the async path there is no status poll loop (the kernel owns
|
|
130
|
+
* polling), so the progress callback fires once on completion, matching the
|
|
131
|
+
* metadata path's single completion tick.
|
|
132
|
+
*/
|
|
133
|
+
private waitUntilReadyCancellable;
|
|
134
|
+
/**
|
|
135
|
+
* Drive `awaitResult()` on a Failed statement to surface the kernel's typed
|
|
136
|
+
* SQL-error envelope. Falls back to a generic error if `awaitResult()`
|
|
137
|
+
* unexpectedly resolves instead of rejecting.
|
|
138
|
+
*/
|
|
139
|
+
private throwAsyncError;
|
|
140
|
+
/**
|
|
141
|
+
* Best-effort close of the kernel statement when the poll loop ends on a
|
|
142
|
+
* server-driven terminal error (Failed/Cancelled/Closed/Unknown/Timeout).
|
|
143
|
+
* Without it the kernel-side statement handle leaks until session close (the
|
|
144
|
+
* poll loop, unlike `fetchChunk`, otherwise just throws). Never masks the
|
|
145
|
+
* original error; warn-logs a close failure so the leak is diagnosable.
|
|
146
|
+
*/
|
|
147
|
+
private bestEffortClose;
|
|
148
|
+
/**
|
|
149
|
+
* Resolve (and memoise) the fetch handle: `awaitResult()`'s `AsyncResultHandle`
|
|
150
|
+
* on the query path, or the already-terminal `Statement` on the metadata path.
|
|
151
|
+
*/
|
|
152
|
+
private getFetchHandle;
|
|
153
|
+
private getResultSlicer;
|
|
154
|
+
}
|