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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Honor client and per-statement `useLZ4Compression` in the kernel backend.
- Release completed Thrift CloudFetch body-reader listeners so idle connections do not retain downloaded result buffers.

## 3.1.0
Expand Down
28 changes: 14 additions & 14 deletions CONNECTION_PARAMETERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,19 @@ telemetry implementation, so only the options explicitly forwarded by

## Per-statement options (`session.executeStatement(sql, options)`)

| Option | Type | Thrift | Kernel | Default Value | Note |
| ------------------------- | ------------------------------------------------------- | :----: | :----: | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `queryTimeout` | `number \| bigint \| Int64` | ✅ | ❌ | — | Thrift sends this server-side timeout for Compute clusters. Kernel ignores it; SQL Warehouses use `STATEMENT_TIMEOUT`. |
| `runAsync` | `boolean` | ❌ | ✅ | — / `false` | Thrift always sends asynchronously and ignores the option. Kernel `false`/omitted uses direct execution; `true` submits and polls. This execute option is not deprecated. |
| `maxRows` | `number \| bigint \| Int64 \| null` | ✅ | ❌ | `100000` / — | Thrift uses it for the initial Direct Results row count; `null` disables Direct Results. Kernel does not retain or forward the supplied value. |
| `useCloudFetch` | `boolean` | ✅ | ❌ | `true` / — | Kernel logs and ignores this per-statement hint; Kernel result fetching owns its CloudFetch behavior. |
| `useLZ4Compression` | `boolean` | ✅ | ❌ | `true` / — | Thrift uses it when supported and when the result is not CloudFetch. Kernel owns and auto-detects result compression. |
| `stagingAllowedLocalPath` | `string \| string[]` | ✅ | ❌ | — | Local allowlist for Thrift volume/staging operations. Kernel volume operations are unsupported. |
| `namedParameters` | `Record<string, DBSQLParameter \| DBSQLParameterValue>` | ✅ | ✅ | — | Named SQL parameters. Cannot be combined with non-empty `ordinalParameters`. Thrift requires a protocol that supports parameterized queries. |
| `ordinalParameters` | `Array<DBSQLParameter \| DBSQLParameterValue>` | ✅ | ✅ | — | Positional SQL parameters. Cannot be combined with non-empty `namedParameters`. |
| `queryTags` | `Record<string, string \| null \| undefined>` | ✅ | ✅ | — | Serialized into the per-statement `query_tags` conf overlay on both. |
| `rowLimit` | `number` | ❌ | ✅ | — | Kernel-only server-side row cap. Thrift logs and ignores it. |
| `statementConf` | `Record<string, string>` | ❌ | ✅ | — | Kernel-only per-statement Spark conf overlay. Structured `queryTags` overwrite its `query_tags` key when non-empty. |
| Option | Type | Thrift | Kernel | Default Value | Note |
| ------------------------- | ------------------------------------------------------- | :----: | :----: | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `queryTimeout` | `number \| bigint \| Int64` | ✅ | ❌ | — | Thrift sends this server-side timeout for Compute clusters. Kernel ignores it; SQL Warehouses use `STATEMENT_TIMEOUT`. |
| `runAsync` | `boolean` | ❌ | ✅ | — / `false` | Thrift always sends asynchronously and ignores the option. Kernel `false`/omitted uses direct execution; `true` submits and polls. This execute option is not deprecated. |
| `maxRows` | `number \| bigint \| Int64 \| null` | ✅ | ❌ | `100000` / — | Thrift uses it for the initial Direct Results row count; `null` disables Direct Results. Kernel does not retain or forward the supplied value. |
| `useCloudFetch` | `boolean` | ✅ | ❌ | `true` / — | Kernel logs and ignores this per-statement hint; Kernel result fetching owns its CloudFetch behavior. |
| `useLZ4Compression` | `boolean` | ✅ | ✅ | Client setting | Override the client setting for this statement. On Thrift, the option applies to inline results with CloudFetch disabled. |
| `stagingAllowedLocalPath` | `string \| string[]` | ✅ | ❌ | — | Local allowlist for Thrift volume/staging operations. Kernel volume operations are unsupported. |
| `namedParameters` | `Record<string, DBSQLParameter \| DBSQLParameterValue>` | ✅ | ✅ | — | Named SQL parameters. Cannot be combined with non-empty `ordinalParameters`. Thrift requires a protocol that supports parameterized queries. |
| `ordinalParameters` | `Array<DBSQLParameter \| DBSQLParameterValue>` | ✅ | ✅ | — | Positional SQL parameters. Cannot be combined with non-empty `namedParameters`. |
| `queryTags` | `Record<string, string \| null \| undefined>` | ✅ | ✅ | — | Serialized into the per-statement `query_tags` conf overlay on both. |
| `rowLimit` | `number` | ❌ | ✅ | — | Kernel-only server-side row cap. Thrift logs and ignores it. |
| `statementConf` | `Record<string, string>` | ❌ | ✅ | — | Kernel-only per-statement Spark conf overlay. Structured `queryTags` overwrite its `query_tags` key when non-empty. |

## Metadata-operation request parameters

Expand All @@ -244,7 +244,7 @@ session parameter surface.

Thrift-only capabilities include custom/token-provider authentication, custom
OAuth persistence, SOCKS proxies, authenticated/driver-buffer telemetry knobs,
query timeout, Direct Results `maxRows`, per-statement CloudFetch/LZ4 hints, and
query timeout, Direct Results `maxRows`, per-statement CloudFetch hints, and
volume operations.

Kernel-only capabilities include connection-pool sizing, proxy bypass hosts,
Expand Down
2 changes: 1 addition & 1 deletion KERNEL_REV
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5c3a909771f749174567af074bfe18c24a335f5c
4691f70cda81ad2b22c419d876d7aebbdbf878fe
45 changes: 13 additions & 32 deletions lib/kernel/KernelSessionBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,22 @@ export default class KernelSessionBackend implements ISessionBackend {
* never forwarded to the kernel and never applied as a client-side
* deadline — see the note in `executeStatement`;
* - `rowLimit` → `rowLimit` (kernel-only server-side row cap);
* - `useLZ4Compression` → `lz4Compression`, with the client setting as the default;
* - `queryTags` → serialised into the conf overlay's reserved
* `query_tags` key (the same wire shape Thrift's `serializeQueryTags`
* produces), merged with any explicit `statementConf`.
*
* Still rejected (genuinely unsupported on kernel, rather than silently
* dropped): `useCloudFetch` (governed by the kernel `ResultConfig`, not a
* per-statement knob), `useLZ4Compression` (kernel owns result compression),
* and `stagingAllowedLocalPath` (volume operations). `maxRows` is applied by
* the facade at fetch time, so it is intentionally not handled here.
* The kernel backend logs a warning when a statement supplies `useCloudFetch`
* or `stagingAllowedLocalPath` and ignores those hints. The session controls
* CloudFetch through `ResultConfig`. The facade applies `maxRows` at fetch time.
*/
public async executeStatement(statement: string, options: ExecuteStatementOptions): Promise<IOperationBackend> {
this.failIfClosed();

// Per-statement options the kernel backend doesn't honour are treated as
// NO-OPs (logged at warn), not errors — so call sites written for the Thrift
// backend are drop-in on the kernel path. These are perf/format hints the
// kernel governs internally (useCloudFetch / useLZ4Compression) or a feature
// kernel governs internally (useCloudFetch) or a feature
// it doesn't expose yet (staging); ignoring them cannot change query results.
// NB: parameter binding (compound/BINARY) is deliberately NOT no-op'd — a
// dropped param would silently change results, so it still throws.
Expand All @@ -172,14 +171,6 @@ export default class KernelSessionBackend implements ISessionBackend {
'kernel executeStatement: ignoring per-statement `useCloudFetch` — result fetching is governed by the kernel result configuration (no-op on kernel).',
);
}
if (options.useLZ4Compression !== undefined) {
this.context
.getLogger()
.log(
LogLevel.warn,
'kernel executeStatement: ignoring per-statement `useLZ4Compression` — result compression is governed by the kernel (no-op on kernel).',
);
}
if (options.stagingAllowedLocalPath !== undefined) {
this.context
.getLogger()
Expand Down Expand Up @@ -224,6 +215,7 @@ export default class KernelSessionBackend implements ISessionBackend {
// execution. So `queryTimeout` is neither forwarded to the kernel nor used as
// a client-side deadline.

const execOptions = this.buildExecuteOptions(options);
if (!runAsync) {
// DEFAULT — directResults (the Thrift/JDBC model). The kernel's
// `executeStatementDirect` runs ExecuteStatement with a bounded server
Expand All @@ -234,13 +226,9 @@ export default class KernelSessionBackend implements ISessionBackend {
// query stays cancellable via `op.cancel()` and `close()` is a clean
// release (no client-side drive-to-terminal). Fire-and-forget DDL/DML
// commits because the server runs it inline during the POST.
const execOptions = this.buildExecuteOptions(options);
let direct: KernelStatement | KernelNativeAsyncStatement;
try {
direct =
execOptions === undefined
? await this.connection.executeStatementDirect(statement)
: await this.connection.executeStatementDirect(statement, execOptions);
direct = await this.connection.executeStatementDirect(statement, execOptions);
} catch (err) {
throw this.logAndMapError('executeStatement', err);
}
Expand All @@ -264,13 +252,9 @@ export default class KernelSessionBackend implements ISessionBackend {

// Async path: submit (`wait_timeout=0s`) returns a pending handle the
// backend polls. (`queryTimeout` is a no-op on kernel — see the note above.)
const execOptions = this.buildExecuteOptions(options);
let asyncStatement;
try {
asyncStatement =
execOptions === undefined
? await this.connection.submitStatement(statement)
: await this.connection.submitStatement(statement, execOptions);
asyncStatement = await this.connection.submitStatement(statement, execOptions);
} catch (err) {
throw this.logAndMapError('executeStatement', err);
}
Expand All @@ -283,12 +267,7 @@ export default class KernelSessionBackend implements ISessionBackend {
});
}

/**
* Translate the public `ExecuteStatementOptions` into the kernel napi
* `ExecuteOptions`, returning `undefined` when nothing is set so the
* no-options call shape (`executeStatement(sql)`) is preserved.
*/
private buildExecuteOptions(options: ExecuteStatementOptions): KernelNativeExecuteOptions | undefined {
private buildExecuteOptions(options: ExecuteStatementOptions): KernelNativeExecuteOptions {
// Positional (`?`) and named (`:name`) parameters are mutually exclusive —
// the kernel binds one placeholder style per statement. Use the SAME error
// type and message as the Thrift backend (`ThriftSessionBackend`) so a
Expand All @@ -299,7 +278,9 @@ export default class KernelSessionBackend implements ISessionBackend {
throw new ParameterError('Driver does not support both ordinal and named parameters.');
}

const execOptions: KernelNativeExecuteOptions = {};
const execOptions: KernelNativeExecuteOptions = {
lz4Compression: options.useLZ4Compression ?? this.context.getConfig().useLZ4Compression,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The backend now always sends lz4Compression, but the kernel platform packages are still pinned to 1.5.0. Only KERNEL_REV and the type declaration changed, so installed binaries probably ignore the field and the option has no effect. Publish and pin native packages that support it, or document the dependency.

🔀 Found by both reviewers · confirmed by the judge

@aakash-saravanan-db aakash-saravanan-db Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The supporting native package requirement is documented in this PR’s Dependencies section and linked to kernel PR databricks/databricks-sql-kernel#511. Published 1.5.0 does not provide the opt-out, so this PR remains blocked until a supporting native package is published and the platform package pins are updated to its assigned version.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at bcdd5a1: platform packages stay pinned to 1.5.0, which doesn't support lz4Compression. Pins need updating once a supporting package is published.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The driver now sends lz4Compression, but only KERNEL_REV is bumped and the published kernel optionalDependencies stay at 1.5.0. An older binding would likely ignore the field, so the option would be silently dropped. Pin a compatible published kernel across all platform packages, or document the required follow-up bump in the CHANGELOG.

🔀 Found by both reviewers · confirmed by the judge

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same open supporting-native-package prerequisite acknowledged above and documented under Dependencies. The PR remains blocked until a supporting package is published and its assigned version is pinned; no version is assigned yet. Kernel PR: databricks/databricks-sql-kernel#511.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at 9fb2352: CHANGELOG.md:5 claims kernel useLZ4Compression support, but kernel optionalDependencies stay at 1.5.0 and the CHANGELOG doesn't mention the required bump.

};
// Raw binding preserves qualified SQL types such as INTERVAL MONTH.
const rawParams = positionalParams ?? namedParams;
if (rawParams !== undefined) {
Expand Down Expand Up @@ -328,7 +309,7 @@ export default class KernelSessionBackend implements ISessionBackend {
}
}

return Object.keys(execOptions).length > 0 ? execOptions : undefined;
return execOptions;
}

/** Wrap a napi metadata `Statement` (already terminal) as an operation backend. */
Expand Down
2 changes: 2 additions & 0 deletions native/kernel/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 20 additions & 9 deletions tests/unit/kernel/execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,12 +1052,24 @@ describe('KernelSessionBackend', () => {
expect(options.rawParams).to.deep.equal([{ sqlType: 'INTERVAL MONTH', value: '2-6' }]);
});

it('executeStatement sends no options object on the no-params path', async () => {
const connection = new FakeNativeConnection();
const session = makeSession(connection);
await session.executeStatement('SELECT 1', {});
expect(connection.lastOptions).to.equal(undefined);
});
for (const runAsync of [false, true]) {
for (const [client, statement, expected] of [
[true, undefined, true],
[false, undefined, false],
[true, false, false],
[false, true, true],
] as const) {
it(`forwards LZ4 compression with client=${client}, statement=${statement}, runAsync=${runAsync}`, async () => {
const connection = new FakeNativeConnection();
const context = makeContext();
context.getConfig().useLZ4Compression = client;
const session = new KernelSessionBackend({ connection, context });
await session.executeStatement('SELECT 1', { runAsync, useLZ4Compression: statement });
expect(connection.lastOptions).to.deep.equal({ lz4Compression: expected });
expect(connection.lastAsyncStatement !== undefined).to.equal(runAsync);
});
}
}

it('executeStatement rejects mixing ordinal and named parameters with the same ParameterError as Thrift', async () => {
const connection = new FakeNativeConnection();
Expand All @@ -1080,7 +1092,7 @@ describe('KernelSessionBackend', () => {
await session.executeStatement('SELECT 1', { queryTimeout: 30 });
// queryTimeout is a no-op on kernel (SQL Warehouses use STATEMENT_TIMEOUT). It
// must NOT be mapped to the kernel's `wait_timeout` (the inline-hold window),
// so nothing is forwarded onto the napi options.
// so the napi options carry no timeout override.
expect((connection.lastOptions as { queryTimeoutSecs?: number } | undefined)?.queryTimeoutSecs).to.equal(undefined);
});

Expand Down Expand Up @@ -1152,12 +1164,11 @@ describe('KernelSessionBackend', () => {

// Unsupported-on-kernel per-statement HINTS are NO-OPs (not errors) so Thrift-
// targeted call sites are drop-in on the kernel path. They are kernel-governed
// perf/format hints (useCloudFetch / useLZ4Compression) or an unexposed feature
// hints (useCloudFetch) or an unexposed feature
// (staging); ignoring them can't change results. (Parameter binding is NOT here
// — a dropped param would change results, so it still throws; asserted above.)
for (const { name, options } of [
{ name: 'useCloudFetch', options: { useCloudFetch: true } },
{ name: 'useLZ4Compression', options: { useLZ4Compression: true } },
{ name: 'stagingAllowedLocalPath', options: { stagingAllowedLocalPath: '/tmp' } },
] as const) {
it(`executeStatement ignores unsupported ${name} (no-op, does not throw)`, async () => {
Expand Down
Loading