Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ Dockerfile* text
# crate; regenerated by `npm run build:native`. Tell git/GitHub they're
# machine-generated so they collapse in diffs and are excluded from
# blame and language stats.
native/sea/index.d.ts linguist-generated=true
native/sea/index.js linguist-generated=true
native/kernel/index.d.ts linguist-generated=true
native/kernel/index.js linguist-generated=true
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ dist
lib/version.ts

# SEA native binding — copied/generated from kernel workspace by `npm run build:native`.
# The committed contract is `native/sea/index.d.ts` (TypeScript declarations) and
# `native/sea/index.js` (the napi-rs platform router — small, stable, and required in
# The committed contract is `native/kernel/index.d.ts` (TypeScript declarations) and
# `native/kernel/index.js` (the napi-rs platform router — small, stable, and required in
# the publish tarball so a missing build step can't ship a tarball that can't load).
# The `.node` binaries are large per-platform artifacts and must NOT be committed;
# in production they arrive via the `@databricks/sql-kernel-<triple>` optional deps.
native/sea/index.node
native/sea/index.*.node
native/kernel/index.node
native/kernel/index.*.node
4 changes: 2 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# selects the per-platform `.node` artifact from `@databricks/sql-kernel-*`
# optionalDependencies (populated when the kernel CI publishes them);
# the .d.ts is the consumer-facing type contract.
!native/sea/index.js
!native/sea/index.d.ts
!native/kernel/index.js
!native/kernel/index.d.ts

!LICENSE
!NOTICE
Expand Down
4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ package-lock.json
# Generated by napi-rs from the kernel's `napi-binding/napi/` crate;
# regenerated by `npm run build:native`. Format follows napi-rs's
# defaults (no semicolons), not this repo's prettier config.
native/sea/index.d.ts
native/sea/index.js
native/kernel/index.d.ts
native/kernel/index.js
8 changes: 4 additions & 4 deletions lib/DBSQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { buildUserAgentString } from './utils';
import IBackend from './contracts/IBackend';
import { InternalConnectionOptions } from './contracts/InternalConnectionOptions';
import ThriftBackend from './thrift-backend/ThriftBackend';
import SeaBackend from './sea/SeaBackend';
import KernelBackend from './kernel/KernelBackend';
import PlainHttpAuthentication from './connection/auth/PlainHttpAuthentication';
import DatabricksOAuth, { OAuthFlow } from './connection/auth/DatabricksOAuth';
import {
Expand Down Expand Up @@ -627,12 +627,12 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I

this.connectionProvider = this.createConnectionProvider(options);

// M0: `useSEA` is consumed via a non-exported internal-options cast so it
// M0: `useKernel` is consumed via a non-exported internal-options cast so it
// doesn't ship in the public `.d.ts`. Mirrors Python's `kwargs.get("use_sea")`
// pattern (see databricks-sql-python/src/databricks/sql/session.py).
const internalOptions = options as ConnectionOptions & InternalConnectionOptions;
const backend = internalOptions.useSEA
? new SeaBackend({ context: this })
const backend = internalOptions.useKernel
? new KernelBackend({ context: this })
: new ThriftBackend({
context: this,
onConnectionEvent: (event, payload) => this.forwardConnectionEvent(event, payload),
Expand Down
4 changes: 2 additions & 2 deletions lib/contracts/IBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import ISessionBackend from './ISessionBackend';

/**
* Top-level backend dispatch handle. One instance per `DBSQLClient`,
* chosen at `connect()` time based on the `useSEA` flag and never
* chosen at `connect()` time based on the `useKernel` flag and never
* re-selected per-call.
*/
export default interface IBackend {
/**
* Establish backend-level state before any session is opened. Implementations
* consume `options` to build backend-specific connection parameters (e.g. the
* SEA backend derives napi-binding `SeaNativeConnectionOptions` from the auth
* SEA backend derives napi-binding `KernelNativeConnectionOptions` from the auth
* + host fields here). Transport-layer connection providers are owned by
* `DBSQLClient` (via `IClientContext`) and exposed to backends through
* constructor injection.
Expand Down
2 changes: 1 addition & 1 deletion lib/contracts/IDBSQLSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type ExecuteStatementOptions = {
* - **Thrift backend:** no-op. The Thrift path always submits asynchronously
* (`runAsync: true` on the wire) and polls during fetch; this option is not
* read.
* - **Kernel backend (`useSEA`):** selects the kernel execution path —
* - **Kernel backend (`useKernel`):** selects the kernel execution path —
* `false`/unset (default) runs the blocking direct-results path (faster,
* cancellable mid-compute); `true` submits and polls (returns a pending
* handle before completion). Default is sync, matching the python
Expand Down
4 changes: 2 additions & 2 deletions lib/contracts/InternalConnectionOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* signature (see `databricks-sql-python/src/databricks/sql/session.py`).
*
* Callers cast `ConnectionOptions` to this type *only* at the read site
* inside the driver; user code that wants to set `useSEA` may still do so
* inside the driver; user code that wants to set `useKernel` may still do so
* via an untyped object literal — the option is not part of the public
* contract and may be removed without notice.
*/
Expand All @@ -17,7 +17,7 @@ export interface InternalConnectionOptions {
* backend instead of the default Thrift backend. Defaults to `false`.
* @internal Not stable; M0 stub only.
*/
useSEA?: boolean;
useKernel?: boolean;

/**
* SEA-only: kernel connection-pool size (`ConnectionOptions.max_connections`).
Expand Down
12 changes: 6 additions & 6 deletions lib/sea/SeaArrowIpc.ts → lib/kernel/KernelArrowIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import { RecordBatchReader, MessageReader, MessageHeader, Schema, Field, DataType, TypeMap } from 'apache-arrow';
import { TTableSchema, TTypeId, TPrimitiveTypeEntry } from '../../thrift/TCLIService_types';
import { rewriteDurationToInt64, DURATION_UNIT_METADATA_KEY } from './SeaArrowIpcDurationFix';
import { rewriteDurationToInt64, DURATION_UNIT_METADATA_KEY } from './KernelArrowIpcDurationFix';
import HiveDriverError from '../errors/HiveDriverError';

/**
Expand All @@ -29,7 +29,7 @@ const DATABRICKS_TYPE_NAME = 'databricks.type_name';
*
* Why this exists: `ArrowResultConverter` consumes `ArrowBatch` objects
* that carry an explicit `rowCount`, but the kernel's IPC payload only
* carries per-RecordBatch `length` (no separate total). `SeaResultsProvider`
* carries per-RecordBatch `length` (no separate total). `KernelResultsProvider`
* needs that count to build the `ArrowBatch` it hands to the converter —
* which then re-decodes the same bytes for the actual values.
*
Expand Down Expand Up @@ -89,12 +89,12 @@ export function decodeIpcSchema(ipcBytes: Buffer): Schema<TypeMap> {
* Pre-process raw IPC bytes from the kernel so they're consumable by
* `apache-arrow@13`. The current transformation is `Duration → Int64`
* with the original duration unit preserved in field metadata (see
* `SeaArrowIpcDurationFix.ts`). Returned bytes are byte-identical to
* `KernelArrowIpcDurationFix.ts`). Returned bytes are byte-identical to
* the input when no transformation is needed.
*
* Exposed so callers can pre-patch the buffer **once** and pass the
* result through both `decodeIpcBatch` (for row-count extraction in
* `SeaResultsProvider`) and `ArrowResultConverter.fetchNext` (which
* `KernelResultsProvider`) and `ArrowResultConverter.fetchNext` (which
* re-decodes the same bytes via `RecordBatchReader.from`). Without
* this, the converter would re-throw on `Duration` because it never
* sees the patched bytes.
Expand Down Expand Up @@ -198,7 +198,7 @@ function arrowTypeToTTypeId(field: Field<DataType>): TTypeId {
if (DataType.isInt(arrowType)) {
// Duration columns are rewritten to Int64 with a
// `databricks.arrow.duration_unit` metadata marker (see
// `SeaArrowIpcDurationFix.ts`). Surface them as INTERVAL_DAY_TIME
// `KernelArrowIpcDurationFix.ts`). Surface them as INTERVAL_DAY_TIME
// so the converter formats them back into the thrift string form.
if (arrowType.bitWidth === 64 && field.metadata.has(DURATION_UNIT_METADATA_KEY)) {
return TTypeId.INTERVAL_DAY_TIME_TYPE;
Expand Down Expand Up @@ -246,7 +246,7 @@ function arrowTypeToTTypeId(field: Field<DataType>): TTypeId {

/**
* Synthesize a Thrift `TTableSchema` from an Arrow schema decoded out
* of the kernel's IPC stream. Used by `SeaOperationBackend.getResultMetadata`
* of the kernel's IPC stream. Used by `KernelOperationBackend.getResultMetadata`
* to drive `ArrowResultConverter.convertThriftTypes` (Phase 2) without
* changing that code.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*
* Why this lives in its own file: the rewriter is the only place in the
* codebase that needs to construct FlatBuffers by hand using the
* `flatbuffers` library; isolating it keeps `SeaArrowIpc.ts` focused on
* `flatbuffers` library; isolating it keeps `KernelArrowIpc.ts` focused on
* the high-level Arrow-decoded views.
*
* @see lib/result/ArrowResultConverter.ts — the Phase-1 INTERVAL formatter
Expand Down
30 changes: 15 additions & 15 deletions lib/sea/SeaAuth.ts → lib/kernel/KernelAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const U2M_DEFAULT_REDIRECT_PORT = 8030;

/**
* Shape consumed by the napi-binding's `openSession()` (see
* `native/sea/index.d.ts`). Mirrors `ConnectionOptions` in the binding's
* `native/kernel/index.d.ts`). Mirrors `ConnectionOptions` in the binding's
* `.d.ts`; declared locally to avoid coupling the JS-side adapter to the
* auto-generated TS file.
*
Expand All @@ -45,10 +45,10 @@ const U2M_DEFAULT_REDIRECT_PORT = 8030;
* variant names verbatim (`'Pat'`, `'OAuthM2m'`, `'OAuthU2m'` — napi-rs's
* `#[napi(string_enum)]` without an explicit case option emits the
* Rust variant identifier as-is). We duplicate the values here instead
* of importing `AuthMode` from `native/sea/index.d.ts` because that
* of importing `AuthMode` from `native/kernel/index.d.ts` because that
* file declares `AuthMode` as `export const enum`, which is
* incompatible with `isolatedModules` and a runtime-coupling hazard.
* The Rust source of truth lives at `native/sea/src/database.rs`.
* The Rust source of truth lives at `native/kernel/src/database.rs`.
*/
/**
* Session-level defaults shared across all auth-mode variants.
Expand All @@ -63,7 +63,7 @@ const U2M_DEFAULT_REDIRECT_PORT = 8030;
* creation. Mirror that here so the adapter doesn't promise a
* capability the binding can't honour.
*/
export interface SeaSessionDefaults {
export interface KernelSessionDefaults {
catalog?: string;
schema?: string;
sessionConf?: Record<string, string>;
Expand All @@ -88,7 +88,7 @@ export interface SeaSessionDefaults {
/**
* Per-session kernel connection-pool size
* (kernel `ConnectionOptions.max_connections`). Validated as a positive
* integer within the napi `u32` range by `buildSeaConnectionOptions`.
* integer within the napi `u32` range by `buildKernelConnectionOptions`.
*/
maxConnections?: number;
}
Expand All @@ -100,10 +100,10 @@ export interface SeaSessionDefaults {
*
* The napi shape takes `customCaCert` as a `Buffer` only; the public
* `ConnectionOptions` additionally accepts a PEM string, which
* `buildSeaConnectionOptions` normalises to a `Buffer` before crossing
* `buildKernelConnectionOptions` normalises to a `Buffer` before crossing
* the FFI boundary.
*/
export interface SeaTlsOptions {
export interface KernelTlsOptions {
/**
* Verify the server's TLS certificate. The SEA backend is
* **secure-by-default**: omitting this leaves the kernel default of
Expand All @@ -117,8 +117,8 @@ export interface SeaTlsOptions {
customCaCert?: Buffer;
}

export type SeaNativeConnectionOptions = SeaSessionDefaults &
SeaTlsOptions &
export type KernelNativeConnectionOptions = KernelSessionDefaults &
KernelTlsOptions &
(
| {
hostName: string;
Expand Down Expand Up @@ -181,13 +181,13 @@ const MAX_U32 = 0xffffffff;
* Throws `HiveDriverError` when `customCaCert` is supplied but empty or
* (for strings) lacks a PEM certificate header.
*/
export function buildSeaTlsOptions(options: ConnectionOptions): SeaTlsOptions {
export function buildKernelTlsOptions(options: ConnectionOptions): KernelTlsOptions {
// Read the SEA-only fields through the purpose-built internal options type
// rather than an ad-hoc inline cast, so the shape can't silently drift from
// its declaration and a typo'd key fails to compile.
const { checkServerCertificate, customCaCert } = options as ConnectionOptions & InternalConnectionOptions;

const tls: SeaTlsOptions = {};
const tls: KernelTlsOptions = {};

if (checkServerCertificate !== undefined) {
tls.checkServerCertificate = checkServerCertificate;
Expand Down Expand Up @@ -274,15 +274,15 @@ export function buildSeaTlsOptions(options: ConnectionOptions): SeaTlsOptions {
* - `HiveDriverError` for unsupported auth modes / Azure-direct /
* custom persistence / ambiguous combinations.
*/
export function buildSeaConnectionOptions(options: ConnectionOptions): SeaNativeConnectionOptions {
export function buildKernelConnectionOptions(options: ConnectionOptions): KernelNativeConnectionOptions {
const { authType } = options as { authType?: string };

const base: {
hostName: string;
httpPath: string;
intervalsAsString: boolean;
maxConnections?: number;
} & SeaTlsOptions = {
} & KernelTlsOptions = {
hostName: options.host,
httpPath: prependSlash(options.path),
// Match the NodeJS Thrift driver, which surfaces INTERVAL columns as
Expand All @@ -294,7 +294,7 @@ export function buildSeaConnectionOptions(options: ConnectionOptions): SeaNative
intervalsAsString: true,
// TLS knobs (server-cert verification toggle + custom CA). Validated and
// normalised (string PEM → Buffer) here so the napi shape only sees a Buffer.
...buildSeaTlsOptions(options),
...buildKernelTlsOptions(options),
};

// SEA-only pool sizing; read via cast to match how this function reads the
Expand Down Expand Up @@ -363,7 +363,7 @@ export function buildSeaConnectionOptions(options: ConnectionOptions): SeaNative
// "secret is required" error rather than being silently routed to U2M
// (which would hide their intent). Cost: `id + no secret` throws here
// where thrift would run U2M, and SEA U2M has no custom-client-id support
// (see buildSeaConnectionOptions header). The U2M arm still defends against an id
// (see buildKernelConnectionOptions header). The U2M arm still defends against an id
// sneaking through: fires only when `oauthClientId` is provided as
// a blank-reserved literal (e.g., whitespace, `"null"`, `"undefined"`)
// alongside an absent/blank secret — both `idIsBlank` and
Expand Down
Loading
Loading