@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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import IOperationBackend from './IOperationBackend';
|
|
2
|
+
import { ExecuteStatementOptions, TypeInfoRequest, CatalogsRequest, SchemasRequest, TablesRequest, TableTypesRequest, ColumnsRequest, FunctionsRequest, PrimaryKeysRequest, CrossReferenceRequest } from './IDBSQLSession';
|
|
3
|
+
import Status from '../dto/Status';
|
|
4
|
+
import InfoValue from '../dto/InfoValue';
|
|
5
|
+
/**
|
|
6
|
+
* What a `DBSQLSession` needs from its backend. Returned by
|
|
7
|
+
* `IBackend.openSession()`. Lifecycle tied to a single `DBSQLSession`.
|
|
8
|
+
*/
|
|
9
|
+
export default interface ISessionBackend {
|
|
10
|
+
/** Session identifier. */
|
|
11
|
+
readonly id: string;
|
|
12
|
+
/** Returns general information about the data source. */
|
|
13
|
+
getInfo(infoType: number): Promise<InfoValue>;
|
|
14
|
+
/** Executes DDL/DML statements. */
|
|
15
|
+
executeStatement(statement: string, options: ExecuteStatementOptions): Promise<IOperationBackend>;
|
|
16
|
+
/** Information about supported data types. */
|
|
17
|
+
getTypeInfo(request: TypeInfoRequest): Promise<IOperationBackend>;
|
|
18
|
+
/** List of catalogs. */
|
|
19
|
+
getCatalogs(request: CatalogsRequest): Promise<IOperationBackend>;
|
|
20
|
+
/** List of schemas. */
|
|
21
|
+
getSchemas(request: SchemasRequest): Promise<IOperationBackend>;
|
|
22
|
+
/** List of tables. */
|
|
23
|
+
getTables(request: TablesRequest): Promise<IOperationBackend>;
|
|
24
|
+
/** List of supported table types. */
|
|
25
|
+
getTableTypes(request: TableTypesRequest): Promise<IOperationBackend>;
|
|
26
|
+
/** Full column information for a table. */
|
|
27
|
+
getColumns(request: ColumnsRequest): Promise<IOperationBackend>;
|
|
28
|
+
/** Information about a function. */
|
|
29
|
+
getFunctions(request: FunctionsRequest): Promise<IOperationBackend>;
|
|
30
|
+
/** Primary keys of a table. */
|
|
31
|
+
getPrimaryKeys(request: PrimaryKeysRequest): Promise<IOperationBackend>;
|
|
32
|
+
/** Foreign-key relationships between two tables. */
|
|
33
|
+
getCrossReference(request: CrossReferenceRequest): Promise<IOperationBackend>;
|
|
34
|
+
/** Close the session. Idempotent. */
|
|
35
|
+
close(): Promise<Status>;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ISessionBackend.js","sourceRoot":"","sources":["../../lib/contracts/ISessionBackend.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Internal, non-exported extension of `ConnectionOptions`. Carries M0-only
|
|
4
|
+
* flags that should not appear in the published `.d.ts`.
|
|
5
|
+
*
|
|
6
|
+
* Matches the Python connector pattern: there, `use_kernel` is consumed via
|
|
7
|
+
* `kwargs.get("use_kernel", False)` and is intentionally absent from the typed
|
|
8
|
+
* signature (see `databricks-sql-python/src/databricks/sql/session.py`).
|
|
9
|
+
*
|
|
10
|
+
* Callers cast `ConnectionOptions` to this type *only* at the read site
|
|
11
|
+
* inside the driver; user code that wants to set `useKernel` may still do so
|
|
12
|
+
* via an untyped object literal — the option is not part of the public
|
|
13
|
+
* contract and may be removed without notice.
|
|
14
|
+
*/
|
|
15
|
+
export interface InternalConnectionOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Opt-in flag to dispatch through the Statement Execution API (SEA)
|
|
18
|
+
* backend instead of the default Thrift backend. Defaults to `false`.
|
|
19
|
+
* @internal Not stable; M0 stub only.
|
|
20
|
+
*/
|
|
21
|
+
useKernel?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* kernel-only: kernel connection-pool size (`ConnectionOptions.max_connections`).
|
|
24
|
+
* Validated as a positive integer within the napi `u32` range.
|
|
25
|
+
* @internal kernel path only.
|
|
26
|
+
*/
|
|
27
|
+
maxConnections?: number;
|
|
28
|
+
/**
|
|
29
|
+
* kernel-only: verify the server's TLS certificate. Secure-by-default — omit
|
|
30
|
+
* to keep full chain + hostname verification; set `false` only to opt into
|
|
31
|
+
* the insecure accept-anything mode. This is the master verify toggle:
|
|
32
|
+
* `false` also subsumes the hostname check (see
|
|
33
|
+
* `checkServerCertificateHostname`). Mirrors the Python connector's
|
|
34
|
+
* `_tls_no_verify` (inverted).
|
|
35
|
+
* @internal kernel path only.
|
|
36
|
+
*/
|
|
37
|
+
checkServerCertificate?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* kernel-only: verify that the server certificate matches the host
|
|
40
|
+
* (hostname-vs-SNI check), independently of full chain validation. Omit
|
|
41
|
+
* to keep the secure default (on); set `false` to skip only the hostname
|
|
42
|
+
* check while still validating the chain — e.g. connecting via an IP
|
|
43
|
+
* literal or a host the cert wasn't issued for. No-op when
|
|
44
|
+
* `checkServerCertificate` is `false` (that disables everything). Mirrors
|
|
45
|
+
* the Python connector's `_tls_verify_hostname`.
|
|
46
|
+
* @internal kernel path only.
|
|
47
|
+
*/
|
|
48
|
+
checkServerCertificateHostname?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* kernel-only: PEM-encoded CA certificate (string or `Buffer`) added to the
|
|
51
|
+
* trust store on top of the system roots — for TLS-inspecting proxies or
|
|
52
|
+
* on-prem internal CAs. Honoured regardless of `checkServerCertificate`.
|
|
53
|
+
* @internal kernel path only.
|
|
54
|
+
*/
|
|
55
|
+
customCaCert?: Buffer | string;
|
|
56
|
+
/**
|
|
57
|
+
* kernel-only: PEM-encoded client certificate (string or `Buffer`) for
|
|
58
|
+
* mutual TLS (mTLS). Must be supplied together with `clientKeyPem`; a
|
|
59
|
+
* leaf cert optionally followed by its intermediate chain is accepted.
|
|
60
|
+
* Mirrors the Python connector's `_tls_client_cert_file`.
|
|
61
|
+
* @internal kernel path only.
|
|
62
|
+
*/
|
|
63
|
+
clientCertPem?: Buffer | string;
|
|
64
|
+
/**
|
|
65
|
+
* kernel-only: PEM-encoded private key (string or `Buffer`) for the mTLS
|
|
66
|
+
* client certificate. Must be supplied together with `clientCertPem`.
|
|
67
|
+
* For portability supply a PKCS#8 key (`BEGIN PRIVATE KEY`). Mirrors the
|
|
68
|
+
* Python connector's `_tls_client_cert_key_file`.
|
|
69
|
+
* @internal kernel path only.
|
|
70
|
+
*/
|
|
71
|
+
clientKeyPem?: Buffer | string;
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InternalConnectionOptions.js","sourceRoot":"","sources":["../../lib/contracts/InternalConnectionOptions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backend-neutral operation state. Mirrors the kernel/pyo3 `StatementStatus`
|
|
3
|
+
* and the Python connector's `CommandState`, so a kernel `IOperationBackend`
|
|
4
|
+
* implementer can return these without depending on the Thrift wire enum.
|
|
5
|
+
*
|
|
6
|
+
* Thrift mapping (in `ThriftOperationBackend.adaptOperationStatus`):
|
|
7
|
+
* - INITIALIZED_STATE, PENDING_STATE → Pending
|
|
8
|
+
* - RUNNING_STATE → Running
|
|
9
|
+
* - FINISHED_STATE → Succeeded
|
|
10
|
+
* - CANCELED_STATE → Cancelled
|
|
11
|
+
* - CLOSED_STATE → Closed
|
|
12
|
+
* - ERROR_STATE, TIMEDOUT_STATE → Failed
|
|
13
|
+
* - UKNOWN_STATE / anything else → Unknown
|
|
14
|
+
*/
|
|
15
|
+
export declare enum OperationState {
|
|
16
|
+
Pending = "Pending",
|
|
17
|
+
Running = "Running",
|
|
18
|
+
Succeeded = "Succeeded",
|
|
19
|
+
Failed = "Failed",
|
|
20
|
+
Cancelled = "Cancelled",
|
|
21
|
+
Closed = "Closed",
|
|
22
|
+
Unknown = "Unknown"
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Neutral status snapshot returned by `IOperationBackend.status()`. Backends
|
|
26
|
+
* adapt their wire format at the boundary; callers in `DBSQLOperation` and
|
|
27
|
+
* `IOperationBackend.waitUntilReady` switch on `state` alone.
|
|
28
|
+
*
|
|
29
|
+
* Fields beyond `state` are best-effort and may be undefined depending on
|
|
30
|
+
* what the backend exposes.
|
|
31
|
+
*/
|
|
32
|
+
export interface OperationStatus {
|
|
33
|
+
/** Current operation state. */
|
|
34
|
+
state: OperationState;
|
|
35
|
+
/**
|
|
36
|
+
* Whether this operation has produced (or is producing) a result set.
|
|
37
|
+
* Some backends only know this after the operation reaches a terminal
|
|
38
|
+
* state — undefined means "no signal from this backend".
|
|
39
|
+
*/
|
|
40
|
+
hasResultSet?: boolean;
|
|
41
|
+
/** Human-readable error/display message, if the backend supplied one. */
|
|
42
|
+
errorMessage?: string;
|
|
43
|
+
/** SQL state code (e.g. "42000"), if available. */
|
|
44
|
+
sqlState?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Opaque progress payload as returned by the backend when callers pass
|
|
47
|
+
* `progress: true`. Treated as untyped by the facade — passed through
|
|
48
|
+
* to `WaitUntilReadyOptions.callback` for the consumer to interpret.
|
|
49
|
+
*/
|
|
50
|
+
progressUpdateResponse?: unknown;
|
|
51
|
+
/**
|
|
52
|
+
* Number of rows modified by a DML statement (UPDATE / INSERT / DELETE /
|
|
53
|
+
* MERGE). `undefined`/`null` for SELECT and on backends/warehouses that do
|
|
54
|
+
* not surface the counter. Mirrors Thrift's
|
|
55
|
+
* `TGetOperationStatusResp.numModifiedRows`.
|
|
56
|
+
*/
|
|
57
|
+
numModifiedRows?: number | null;
|
|
58
|
+
/**
|
|
59
|
+
* Server-supplied user-facing message, when the backend exposes one. Mirrors
|
|
60
|
+
* Thrift's `TGetOperationStatusResp.displayMessage`. May contain SQL
|
|
61
|
+
* fragments or parameter values — treat as potentially sensitive.
|
|
62
|
+
*/
|
|
63
|
+
displayMessage?: string | null;
|
|
64
|
+
/**
|
|
65
|
+
* Server-supplied diagnostic detail (multi-line operator / stack context),
|
|
66
|
+
* when available. Mirrors Thrift's `TGetOperationStatusResp.diagnosticInfo`.
|
|
67
|
+
* For support surfaces, not user-facing.
|
|
68
|
+
*/
|
|
69
|
+
diagnosticInfo?: string | null;
|
|
70
|
+
/**
|
|
71
|
+
* Server-supplied JSON blob with extended error details, when available.
|
|
72
|
+
* Mirrors Thrift's `TGetOperationStatusResp.errorDetailsJson`. Pass-through
|
|
73
|
+
* string — callers parse with `JSON.parse` if they need structured access.
|
|
74
|
+
*/
|
|
75
|
+
errorDetailsJson?: string | null;
|
|
76
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OperationState = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Backend-neutral operation state. Mirrors the kernel/pyo3 `StatementStatus`
|
|
6
|
+
* and the Python connector's `CommandState`, so a kernel `IOperationBackend`
|
|
7
|
+
* implementer can return these without depending on the Thrift wire enum.
|
|
8
|
+
*
|
|
9
|
+
* Thrift mapping (in `ThriftOperationBackend.adaptOperationStatus`):
|
|
10
|
+
* - INITIALIZED_STATE, PENDING_STATE → Pending
|
|
11
|
+
* - RUNNING_STATE → Running
|
|
12
|
+
* - FINISHED_STATE → Succeeded
|
|
13
|
+
* - CANCELED_STATE → Cancelled
|
|
14
|
+
* - CLOSED_STATE → Closed
|
|
15
|
+
* - ERROR_STATE, TIMEDOUT_STATE → Failed
|
|
16
|
+
* - UKNOWN_STATE / anything else → Unknown
|
|
17
|
+
*/
|
|
18
|
+
var OperationState;
|
|
19
|
+
(function (OperationState) {
|
|
20
|
+
OperationState["Pending"] = "Pending";
|
|
21
|
+
OperationState["Running"] = "Running";
|
|
22
|
+
OperationState["Succeeded"] = "Succeeded";
|
|
23
|
+
OperationState["Failed"] = "Failed";
|
|
24
|
+
OperationState["Cancelled"] = "Cancelled";
|
|
25
|
+
OperationState["Closed"] = "Closed";
|
|
26
|
+
OperationState["Unknown"] = "Unknown";
|
|
27
|
+
})(OperationState = exports.OperationState || (exports.OperationState = {}));
|
|
28
|
+
//# sourceMappingURL=OperationStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OperationStatus.js","sourceRoot":"","sources":["../../lib/contracts/OperationStatus.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,IAAY,cAQX;AARD,WAAY,cAAc;IACxB,qCAAmB,CAAA;IACnB,qCAAmB,CAAA;IACnB,yCAAuB,CAAA;IACvB,mCAAiB,CAAA;IACjB,yCAAuB,CAAA;IACvB,mCAAiB,CAAA;IACjB,qCAAmB,CAAA;AACrB,CAAC,EARW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAQzB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { TTableSchema } from '../../thrift/TCLIService_types';
|
|
3
|
+
/**
|
|
4
|
+
* Backend-neutral result-format taxonomy. Mirrors the three on-wire shapes
|
|
5
|
+
* `ThriftOperationBackend` actually dispatches on (`COLUMN_BASED_SET`,
|
|
6
|
+
* `ARROW_BASED_SET`, `URL_BASED_SET`); a kernel implementer surfaces the same
|
|
7
|
+
* three so result-handling stays format-agnostic.
|
|
8
|
+
*/
|
|
9
|
+
export declare enum ResultFormat {
|
|
10
|
+
ColumnBased = "COLUMN_BASED",
|
|
11
|
+
ArrowBased = "ARROW_BASED",
|
|
12
|
+
UrlBased = "URL_BASED"
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Neutral result-set metadata returned by `IOperationBackend.getResultMetadata()`.
|
|
16
|
+
*
|
|
17
|
+
* `schema` keeps the Thrift `TTableSchema` shape for now because the public
|
|
18
|
+
* `DBSQLOperation.getSchema()` and `getMetadata()` already expose it on
|
|
19
|
+
* `IOperation`; carrying it across the boundary preserves back-compat. The
|
|
20
|
+
* kernel backend will adapt its column descriptors into the same shape until
|
|
21
|
+
* the public IOperation surface is migrated in a later PR.
|
|
22
|
+
*/
|
|
23
|
+
export interface ResultMetadata {
|
|
24
|
+
/** Column schema; null if the operation has no result set. */
|
|
25
|
+
schema?: TTableSchema;
|
|
26
|
+
/** Wire format the result handler should dispatch on. */
|
|
27
|
+
resultFormat: ResultFormat;
|
|
28
|
+
/** Whether the result payload is LZ4-compressed. */
|
|
29
|
+
lz4Compressed?: boolean;
|
|
30
|
+
/** Optional Arrow IPC schema bytes (for ARROW_BASED / URL_BASED formats). */
|
|
31
|
+
arrowSchema?: Buffer;
|
|
32
|
+
/** True iff the operation is a staging (PUT/GET/REMOVE) operation. */
|
|
33
|
+
isStagingOperation: boolean;
|
|
34
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResultFormat = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Backend-neutral result-format taxonomy. Mirrors the three on-wire shapes
|
|
6
|
+
* `ThriftOperationBackend` actually dispatches on (`COLUMN_BASED_SET`,
|
|
7
|
+
* `ARROW_BASED_SET`, `URL_BASED_SET`); a kernel implementer surfaces the same
|
|
8
|
+
* three so result-handling stays format-agnostic.
|
|
9
|
+
*/
|
|
10
|
+
var ResultFormat;
|
|
11
|
+
(function (ResultFormat) {
|
|
12
|
+
ResultFormat["ColumnBased"] = "COLUMN_BASED";
|
|
13
|
+
ResultFormat["ArrowBased"] = "ARROW_BASED";
|
|
14
|
+
ResultFormat["UrlBased"] = "URL_BASED";
|
|
15
|
+
})(ResultFormat = exports.ResultFormat || (exports.ResultFormat = {}));
|
|
16
|
+
//# sourceMappingURL=ResultMetadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResultMetadata.js","sourceRoot":"","sources":["../../lib/contracts/ResultMetadata.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACH,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,4CAA4B,CAAA;IAC5B,0CAA0B,CAAA;IAC1B,sCAAsB,CAAA;AACxB,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB"}
|
|
@@ -5,6 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const HiveDriverError_1 = __importDefault(require("./HiveDriverError"));
|
|
7
7
|
class AuthenticationError extends HiveDriverError_1.default {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'AuthenticationError';
|
|
11
|
+
}
|
|
8
12
|
}
|
|
9
13
|
exports.default = AuthenticationError;
|
|
10
14
|
//# sourceMappingURL=AuthenticationError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthenticationError.js","sourceRoot":"","sources":["../../lib/errors/AuthenticationError.ts"],"names":[],"mappings":";;;;;AAAA,wEAAgD;AAEhD,MAAqB,mBAAoB,SAAQ,yBAAe;
|
|
1
|
+
{"version":3,"file":"AuthenticationError.js","sourceRoot":"","sources":["../../lib/errors/AuthenticationError.ts"],"names":[],"mappings":";;;;;AAAA,wEAAgD;AAEhD,MAAqB,mBAAoB,SAAQ,yBAAe;IAC9D,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AALD,sCAKC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Schema, TypeMap } from 'apache-arrow';
|
|
3
|
+
import { TTableSchema } from '../../thrift/TCLIService_types';
|
|
4
|
+
/**
|
|
5
|
+
* Sum the row counts of every RecordBatch message in an Arrow IPC
|
|
6
|
+
* stream, WITHOUT materializing the Arrow vector tree.
|
|
7
|
+
*
|
|
8
|
+
* Why this exists: `ArrowResultConverter` consumes `ArrowBatch` objects
|
|
9
|
+
* that carry an explicit `rowCount`, but the kernel's IPC payload only
|
|
10
|
+
* carries per-RecordBatch `length` (no separate total). `KernelResultsProvider`
|
|
11
|
+
* needs that count to build the `ArrowBatch` it hands to the converter —
|
|
12
|
+
* which then re-decodes the same bytes for the actual values.
|
|
13
|
+
*
|
|
14
|
+
* The previous implementation used `RecordBatchReader` and iterated the
|
|
15
|
+
* batches, which calls `_loadVectors` and materializes the full vector
|
|
16
|
+
* tree for every batch just to read `numRows` and discard everything
|
|
17
|
+
* else — ~2x Arrow decode CPU + transient allocation on the fetch hot
|
|
18
|
+
* path. `MessageReader` instead reads only each message's FlatBuffer
|
|
19
|
+
* metadata header (where `RecordBatch.length` lives) and skips the body
|
|
20
|
+
* bytes, so no vectors are decoded here. The converter's later re-decode
|
|
21
|
+
* is the only real materialization.
|
|
22
|
+
*
|
|
23
|
+
* `ipcBytes` must already be Duration-patched (row count is unaffected
|
|
24
|
+
* by the Duration→Int64 rewrite, and the framing is unchanged). Returns
|
|
25
|
+
* 0 for an empty / schema-only stream.
|
|
26
|
+
*/
|
|
27
|
+
export declare function countRowsInIpc(ipcBytes: Buffer): number;
|
|
28
|
+
/**
|
|
29
|
+
* Decode an Arrow IPC schema payload (no record batches) into the
|
|
30
|
+
* apache-arrow Schema object.
|
|
31
|
+
*/
|
|
32
|
+
export declare function decodeIpcSchema(ipcBytes: Buffer): Schema<TypeMap>;
|
|
33
|
+
/**
|
|
34
|
+
* Pre-process raw IPC bytes from the kernel so they're consumable by
|
|
35
|
+
* `apache-arrow@13`. The current transformation is `Duration → Int64`
|
|
36
|
+
* with the original duration unit preserved in field metadata (see
|
|
37
|
+
* `KernelArrowIpcDurationFix.ts`). Returned bytes are byte-identical to
|
|
38
|
+
* the input when no transformation is needed.
|
|
39
|
+
*
|
|
40
|
+
* Exposed so callers can pre-patch the buffer **once** and pass the
|
|
41
|
+
* result through both `decodeIpcBatch` (for row-count extraction in
|
|
42
|
+
* `KernelResultsProvider`) and `ArrowResultConverter.fetchNext` (which
|
|
43
|
+
* re-decodes the same bytes via `RecordBatchReader.from`). Without
|
|
44
|
+
* this, the converter would re-throw on `Duration` because it never
|
|
45
|
+
* sees the patched bytes.
|
|
46
|
+
*/
|
|
47
|
+
export declare function patchIpcBytes(ipcBytes: Buffer): Buffer;
|
|
48
|
+
/**
|
|
49
|
+
* Synthesize a Thrift `TTableSchema` from an Arrow schema decoded out
|
|
50
|
+
* of the kernel's IPC stream. Used by `KernelOperationBackend.getResultMetadata`
|
|
51
|
+
* to drive `ArrowResultConverter.convertThriftTypes` (Phase 2) without
|
|
52
|
+
* changing that code.
|
|
53
|
+
*/
|
|
54
|
+
export declare function arrowSchemaToThriftSchema(arrowSchema: Schema<TypeMap>): TTableSchema;
|
|
@@ -0,0 +1,292 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.arrowSchemaToThriftSchema = exports.patchIpcBytes = exports.decodeIpcSchema = exports.countRowsInIpc = void 0;
|
|
20
|
+
const apache_arrow_1 = require("apache-arrow");
|
|
21
|
+
const TCLIService_types_1 = require("../../thrift/TCLIService_types");
|
|
22
|
+
const KernelArrowIpcDurationFix_1 = require("./KernelArrowIpcDurationFix");
|
|
23
|
+
const HiveDriverError_1 = __importDefault(require("../errors/HiveDriverError"));
|
|
24
|
+
/**
|
|
25
|
+
* Field metadata key used by the kernel to attach the original Databricks
|
|
26
|
+
* SQL type name to each Arrow field. See `databricks-sql-kernel/src/reader/mod.rs`.
|
|
27
|
+
*/
|
|
28
|
+
const DATABRICKS_TYPE_NAME = 'databricks.type_name';
|
|
29
|
+
/**
|
|
30
|
+
* Sum the row counts of every RecordBatch message in an Arrow IPC
|
|
31
|
+
* stream, WITHOUT materializing the Arrow vector tree.
|
|
32
|
+
*
|
|
33
|
+
* Why this exists: `ArrowResultConverter` consumes `ArrowBatch` objects
|
|
34
|
+
* that carry an explicit `rowCount`, but the kernel's IPC payload only
|
|
35
|
+
* carries per-RecordBatch `length` (no separate total). `KernelResultsProvider`
|
|
36
|
+
* needs that count to build the `ArrowBatch` it hands to the converter —
|
|
37
|
+
* which then re-decodes the same bytes for the actual values.
|
|
38
|
+
*
|
|
39
|
+
* The previous implementation used `RecordBatchReader` and iterated the
|
|
40
|
+
* batches, which calls `_loadVectors` and materializes the full vector
|
|
41
|
+
* tree for every batch just to read `numRows` and discard everything
|
|
42
|
+
* else — ~2x Arrow decode CPU + transient allocation on the fetch hot
|
|
43
|
+
* path. `MessageReader` instead reads only each message's FlatBuffer
|
|
44
|
+
* metadata header (where `RecordBatch.length` lives) and skips the body
|
|
45
|
+
* bytes, so no vectors are decoded here. The converter's later re-decode
|
|
46
|
+
* is the only real materialization.
|
|
47
|
+
*
|
|
48
|
+
* `ipcBytes` must already be Duration-patched (row count is unaffected
|
|
49
|
+
* by the Duration→Int64 rewrite, and the framing is unchanged). Returns
|
|
50
|
+
* 0 for an empty / schema-only stream.
|
|
51
|
+
*/
|
|
52
|
+
function countRowsInIpc(ipcBytes) {
|
|
53
|
+
const reader = new apache_arrow_1.MessageReader(ipcBytes);
|
|
54
|
+
let rowCount = 0;
|
|
55
|
+
for (const message of reader) {
|
|
56
|
+
if (message.headerType === apache_arrow_1.MessageHeader.RecordBatch) {
|
|
57
|
+
// header() for a RecordBatch message carries `length` (the row
|
|
58
|
+
// count) in the FlatBuffer metadata — no body decode needed.
|
|
59
|
+
rowCount += Number(message.header().length);
|
|
60
|
+
}
|
|
61
|
+
// Advance past the (undecoded) body so the next message reads at the
|
|
62
|
+
// correct offset. readMessageBody returns a view; it does not decode
|
|
63
|
+
// the body into Arrow vectors.
|
|
64
|
+
const bodyLength = Number(message.bodyLength);
|
|
65
|
+
if (bodyLength > 0) {
|
|
66
|
+
reader.readMessageBody(bodyLength);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return rowCount;
|
|
70
|
+
}
|
|
71
|
+
exports.countRowsInIpc = countRowsInIpc;
|
|
72
|
+
/**
|
|
73
|
+
* Decode an Arrow IPC schema payload (no record batches) into the
|
|
74
|
+
* apache-arrow Schema object.
|
|
75
|
+
*/
|
|
76
|
+
function decodeIpcSchema(ipcBytes) {
|
|
77
|
+
const patched = (0, KernelArrowIpcDurationFix_1.rewriteDurationToInt64)(ipcBytes);
|
|
78
|
+
const reader = apache_arrow_1.RecordBatchReader.from(patched);
|
|
79
|
+
reader.open();
|
|
80
|
+
// `RecordBatchReader.from(emptyBuffer).open()` does not throw — it
|
|
81
|
+
// leaves `schema` undefined. Without this guard a downstream
|
|
82
|
+
// `arrowSchemaToThriftSchema(undefined)` would hit `undefined.fields`
|
|
83
|
+
// and surface a raw TypeError instead of a typed driver error. The
|
|
84
|
+
// real kernel always materialises a schema, so this is defensive.
|
|
85
|
+
if (!reader.schema) {
|
|
86
|
+
throw new HiveDriverError_1.default('kernel result: Arrow IPC stream carried no schema (empty or truncated payload)');
|
|
87
|
+
}
|
|
88
|
+
return reader.schema;
|
|
89
|
+
}
|
|
90
|
+
exports.decodeIpcSchema = decodeIpcSchema;
|
|
91
|
+
/**
|
|
92
|
+
* Pre-process raw IPC bytes from the kernel so they're consumable by
|
|
93
|
+
* `apache-arrow@13`. The current transformation is `Duration → Int64`
|
|
94
|
+
* with the original duration unit preserved in field metadata (see
|
|
95
|
+
* `KernelArrowIpcDurationFix.ts`). Returned bytes are byte-identical to
|
|
96
|
+
* the input when no transformation is needed.
|
|
97
|
+
*
|
|
98
|
+
* Exposed so callers can pre-patch the buffer **once** and pass the
|
|
99
|
+
* result through both `decodeIpcBatch` (for row-count extraction in
|
|
100
|
+
* `KernelResultsProvider`) and `ArrowResultConverter.fetchNext` (which
|
|
101
|
+
* re-decodes the same bytes via `RecordBatchReader.from`). Without
|
|
102
|
+
* this, the converter would re-throw on `Duration` because it never
|
|
103
|
+
* sees the patched bytes.
|
|
104
|
+
*/
|
|
105
|
+
function patchIpcBytes(ipcBytes) {
|
|
106
|
+
return (0, KernelArrowIpcDurationFix_1.rewriteDurationToInt64)(ipcBytes);
|
|
107
|
+
}
|
|
108
|
+
exports.patchIpcBytes = patchIpcBytes;
|
|
109
|
+
/**
|
|
110
|
+
* Map an Arrow `DataType` (with optional `databricks.type_name`
|
|
111
|
+
* metadata) onto the closest Thrift `TTypeId`.
|
|
112
|
+
*
|
|
113
|
+
* This is the synthesis step that lets the existing
|
|
114
|
+
* `ArrowResultConverter` Phase-2 dispatch (`convertThriftValue` in
|
|
115
|
+
* `lib/result/utils.ts:61-98`) keep working unchanged for the kernel
|
|
116
|
+
* path. Phase-2 keys exclusively off `TPrimitiveTypeEntry.type` per
|
|
117
|
+
* column, so we synthesize a `TColumnDesc` whose `TTypeId` matches the
|
|
118
|
+
* server-emitted Arrow type as closely as possible.
|
|
119
|
+
*
|
|
120
|
+
* Resolution order:
|
|
121
|
+
* 1. The kernel attaches `databricks.type_name` (e.g. "DECIMAL",
|
|
122
|
+
* "INTERVAL", "STRUCT") to each field's metadata. Prefer that when
|
|
123
|
+
* present — it carries the original SQL semantic that the Arrow
|
|
124
|
+
* type alone can lose (e.g. INTERVAL → Utf8 with metadata).
|
|
125
|
+
* 2. Fall back to the Arrow `DataType.typeId` for primitive types.
|
|
126
|
+
*
|
|
127
|
+
* This matches the JDBC and Python drivers' policy of trusting the
|
|
128
|
+
* server's logical type assignment over the wire-level Arrow encoding.
|
|
129
|
+
*/
|
|
130
|
+
function arrowTypeToTTypeId(field) {
|
|
131
|
+
var _a;
|
|
132
|
+
const typeName = (_a = field.metadata.get(DATABRICKS_TYPE_NAME)) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
133
|
+
switch (typeName) {
|
|
134
|
+
case 'BOOLEAN':
|
|
135
|
+
return TCLIService_types_1.TTypeId.BOOLEAN_TYPE;
|
|
136
|
+
case 'TINYINT':
|
|
137
|
+
case 'BYTE':
|
|
138
|
+
return TCLIService_types_1.TTypeId.TINYINT_TYPE;
|
|
139
|
+
case 'SMALLINT':
|
|
140
|
+
case 'SHORT':
|
|
141
|
+
return TCLIService_types_1.TTypeId.SMALLINT_TYPE;
|
|
142
|
+
case 'INT':
|
|
143
|
+
case 'INTEGER':
|
|
144
|
+
return TCLIService_types_1.TTypeId.INT_TYPE;
|
|
145
|
+
case 'BIGINT':
|
|
146
|
+
case 'LONG':
|
|
147
|
+
return TCLIService_types_1.TTypeId.BIGINT_TYPE;
|
|
148
|
+
case 'FLOAT':
|
|
149
|
+
case 'REAL':
|
|
150
|
+
return TCLIService_types_1.TTypeId.FLOAT_TYPE;
|
|
151
|
+
case 'DOUBLE':
|
|
152
|
+
return TCLIService_types_1.TTypeId.DOUBLE_TYPE;
|
|
153
|
+
case 'STRING':
|
|
154
|
+
return TCLIService_types_1.TTypeId.STRING_TYPE;
|
|
155
|
+
case 'VARCHAR':
|
|
156
|
+
return TCLIService_types_1.TTypeId.VARCHAR_TYPE;
|
|
157
|
+
case 'CHAR':
|
|
158
|
+
return TCLIService_types_1.TTypeId.CHAR_TYPE;
|
|
159
|
+
case 'BINARY':
|
|
160
|
+
return TCLIService_types_1.TTypeId.BINARY_TYPE;
|
|
161
|
+
case 'DATE':
|
|
162
|
+
return TCLIService_types_1.TTypeId.DATE_TYPE;
|
|
163
|
+
case 'TIMESTAMP':
|
|
164
|
+
case 'TIMESTAMP_NTZ':
|
|
165
|
+
return TCLIService_types_1.TTypeId.TIMESTAMP_TYPE;
|
|
166
|
+
case 'DECIMAL':
|
|
167
|
+
return TCLIService_types_1.TTypeId.DECIMAL_TYPE;
|
|
168
|
+
// INTERVAL — surface as STRING_TYPE to match the Thrift backend and the
|
|
169
|
+
// Python kernel connector, both of which report interval columns with a
|
|
170
|
+
// string type code. The cell value is already rendered to the canonical
|
|
171
|
+
// interval string (e.g. "2-6" / "3 12:30:15.000000000") by
|
|
172
|
+
// ArrowResultConverter, which keys off the Arrow value type (not this
|
|
173
|
+
// synthesized TTypeId), so value formatting is unaffected.
|
|
174
|
+
case 'INTERVAL':
|
|
175
|
+
case 'INTERVAL DAY':
|
|
176
|
+
case 'INTERVAL DAY TO HOUR':
|
|
177
|
+
case 'INTERVAL DAY TO MINUTE':
|
|
178
|
+
case 'INTERVAL DAY TO SECOND':
|
|
179
|
+
case 'INTERVAL HOUR':
|
|
180
|
+
case 'INTERVAL HOUR TO MINUTE':
|
|
181
|
+
case 'INTERVAL HOUR TO SECOND':
|
|
182
|
+
case 'INTERVAL MINUTE':
|
|
183
|
+
case 'INTERVAL MINUTE TO SECOND':
|
|
184
|
+
case 'INTERVAL SECOND':
|
|
185
|
+
case 'INTERVAL YEAR':
|
|
186
|
+
case 'INTERVAL YEAR TO MONTH':
|
|
187
|
+
case 'INTERVAL MONTH':
|
|
188
|
+
return TCLIService_types_1.TTypeId.STRING_TYPE;
|
|
189
|
+
case 'ARRAY':
|
|
190
|
+
return TCLIService_types_1.TTypeId.ARRAY_TYPE;
|
|
191
|
+
case 'MAP':
|
|
192
|
+
return TCLIService_types_1.TTypeId.MAP_TYPE;
|
|
193
|
+
case 'STRUCT':
|
|
194
|
+
return TCLIService_types_1.TTypeId.STRUCT_TYPE;
|
|
195
|
+
case 'NULL':
|
|
196
|
+
case 'VOID':
|
|
197
|
+
return TCLIService_types_1.TTypeId.NULL_TYPE;
|
|
198
|
+
default:
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
// Fall back to Arrow's own type id when no databricks metadata is set
|
|
202
|
+
// (e.g. unit tests constructing batches without metadata).
|
|
203
|
+
const arrowType = field.type;
|
|
204
|
+
if (apache_arrow_1.DataType.isBool(arrowType))
|
|
205
|
+
return TCLIService_types_1.TTypeId.BOOLEAN_TYPE;
|
|
206
|
+
if (apache_arrow_1.DataType.isInt(arrowType)) {
|
|
207
|
+
// Duration columns are rewritten to Int64 with a
|
|
208
|
+
// `databricks.arrow.duration_unit` metadata marker (see
|
|
209
|
+
// `KernelArrowIpcDurationFix.ts`). Surface them as STRING_TYPE (matching the
|
|
210
|
+
// Thrift backend and Python kernel) — the converter still formats the
|
|
211
|
+
// value into the thrift INTERVAL DAY-TIME string via the duration_unit
|
|
212
|
+
// metadata, independent of this type code.
|
|
213
|
+
if (arrowType.bitWidth === 64 && field.metadata.has(KernelArrowIpcDurationFix_1.DURATION_UNIT_METADATA_KEY)) {
|
|
214
|
+
return TCLIService_types_1.TTypeId.STRING_TYPE;
|
|
215
|
+
}
|
|
216
|
+
switch (arrowType.bitWidth) {
|
|
217
|
+
case 8:
|
|
218
|
+
return TCLIService_types_1.TTypeId.TINYINT_TYPE;
|
|
219
|
+
case 16:
|
|
220
|
+
return TCLIService_types_1.TTypeId.SMALLINT_TYPE;
|
|
221
|
+
case 32:
|
|
222
|
+
return TCLIService_types_1.TTypeId.INT_TYPE;
|
|
223
|
+
case 64:
|
|
224
|
+
return TCLIService_types_1.TTypeId.BIGINT_TYPE;
|
|
225
|
+
default:
|
|
226
|
+
return TCLIService_types_1.TTypeId.BIGINT_TYPE;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (apache_arrow_1.DataType.isFloat(arrowType)) {
|
|
230
|
+
// `precision` is the Arrow `Precision` enum (HALF=0, SINGLE=1, DOUBLE=2),
|
|
231
|
+
// NOT a bit-width — `=== 2` is DOUBLE. Everything else (HALF/SINGLE) maps
|
|
232
|
+
// to the thrift FLOAT type.
|
|
233
|
+
return arrowType.precision === 2 ? TCLIService_types_1.TTypeId.DOUBLE_TYPE : TCLIService_types_1.TTypeId.FLOAT_TYPE;
|
|
234
|
+
}
|
|
235
|
+
if (apache_arrow_1.DataType.isDecimal(arrowType))
|
|
236
|
+
return TCLIService_types_1.TTypeId.DECIMAL_TYPE;
|
|
237
|
+
if (apache_arrow_1.DataType.isUtf8(arrowType))
|
|
238
|
+
return TCLIService_types_1.TTypeId.STRING_TYPE;
|
|
239
|
+
if (apache_arrow_1.DataType.isBinary(arrowType))
|
|
240
|
+
return TCLIService_types_1.TTypeId.BINARY_TYPE;
|
|
241
|
+
if (apache_arrow_1.DataType.isDate(arrowType))
|
|
242
|
+
return TCLIService_types_1.TTypeId.DATE_TYPE;
|
|
243
|
+
if (apache_arrow_1.DataType.isTimestamp(arrowType))
|
|
244
|
+
return TCLIService_types_1.TTypeId.TIMESTAMP_TYPE;
|
|
245
|
+
// Native Arrow Interval types. The server-side INTERVAL YEAR-MONTH
|
|
246
|
+
// (and the legacy IntervalDayTime variant) come through with type
|
|
247
|
+
// id 11 / -25 / -26 — apache-arrow@13 surfaces them as `Int32Array`
|
|
248
|
+
// pairs which the converter formats to thrift's `"Y-M"` / day-time
|
|
249
|
+
// strings.
|
|
250
|
+
if (apache_arrow_1.DataType.isInterval(arrowType)) {
|
|
251
|
+
// Surface native Arrow interval types as STRING_TYPE too (Thrift / Python
|
|
252
|
+
// kernel parity). The converter formats the value to the thrift "Y-M" /
|
|
253
|
+
// day-time string from the Arrow value, independent of this type code.
|
|
254
|
+
return TCLIService_types_1.TTypeId.STRING_TYPE;
|
|
255
|
+
}
|
|
256
|
+
if (apache_arrow_1.DataType.isList(arrowType))
|
|
257
|
+
return TCLIService_types_1.TTypeId.ARRAY_TYPE;
|
|
258
|
+
if (apache_arrow_1.DataType.isMap(arrowType))
|
|
259
|
+
return TCLIService_types_1.TTypeId.MAP_TYPE;
|
|
260
|
+
if (apache_arrow_1.DataType.isStruct(arrowType))
|
|
261
|
+
return TCLIService_types_1.TTypeId.STRUCT_TYPE;
|
|
262
|
+
if (apache_arrow_1.DataType.isNull(arrowType))
|
|
263
|
+
return TCLIService_types_1.TTypeId.NULL_TYPE;
|
|
264
|
+
return TCLIService_types_1.TTypeId.STRING_TYPE;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Synthesize a Thrift `TTableSchema` from an Arrow schema decoded out
|
|
268
|
+
* of the kernel's IPC stream. Used by `KernelOperationBackend.getResultMetadata`
|
|
269
|
+
* to drive `ArrowResultConverter.convertThriftTypes` (Phase 2) without
|
|
270
|
+
* changing that code.
|
|
271
|
+
*/
|
|
272
|
+
function arrowSchemaToThriftSchema(arrowSchema) {
|
|
273
|
+
const columns = arrowSchema.fields.map((field, index) => {
|
|
274
|
+
const primitiveEntry = {
|
|
275
|
+
type: arrowTypeToTTypeId(field),
|
|
276
|
+
};
|
|
277
|
+
return {
|
|
278
|
+
columnName: field.name,
|
|
279
|
+
typeDesc: {
|
|
280
|
+
types: [
|
|
281
|
+
{
|
|
282
|
+
primitiveEntry,
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
},
|
|
286
|
+
position: index + 1,
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
return { columns };
|
|
290
|
+
}
|
|
291
|
+
exports.arrowSchemaToThriftSchema = arrowSchemaToThriftSchema;
|
|
292
|
+
//# sourceMappingURL=KernelArrowIpc.js.map
|