diff --git a/CHANGELOG.md b/CHANGELOG.md index c4140be5..1646c0ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/CONNECTION_PARAMETERS.md b/CONNECTION_PARAMETERS.md index edba6002..e2db5e09 100644 --- a/CONNECTION_PARAMETERS.md +++ b/CONNECTION_PARAMETERS.md @@ -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` | ✅ | ✅ | — | Named SQL parameters. Cannot be combined with non-empty `ordinalParameters`. Thrift requires a protocol that supports parameterized queries. | -| `ordinalParameters` | `Array` | ✅ | ✅ | — | Positional SQL parameters. Cannot be combined with non-empty `namedParameters`. | -| `queryTags` | `Record` | ✅ | ✅ | — | 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` | ❌ | ✅ | — | 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` | ✅ | ✅ | — | Named SQL parameters. Cannot be combined with non-empty `ordinalParameters`. Thrift requires a protocol that supports parameterized queries. | +| `ordinalParameters` | `Array` | ✅ | ✅ | — | Positional SQL parameters. Cannot be combined with non-empty `namedParameters`. | +| `queryTags` | `Record` | ✅ | ✅ | — | 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` | ❌ | ✅ | — | Kernel-only per-statement Spark conf overlay. Structured `queryTags` overwrite its `query_tags` key when non-empty. | ## Metadata-operation request parameters @@ -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, diff --git a/KERNEL_REV b/KERNEL_REV index 2add322e..98ae92d2 100644 --- a/KERNEL_REV +++ b/KERNEL_REV @@ -1 +1 @@ -5c3a909771f749174567af074bfe18c24a335f5c +4691f70cda81ad2b22c419d876d7aebbdbf878fe diff --git a/lib/kernel/KernelSessionBackend.ts b/lib/kernel/KernelSessionBackend.ts index dd55dd4c..80d6560b 100644 --- a/lib/kernel/KernelSessionBackend.ts +++ b/lib/kernel/KernelSessionBackend.ts @@ -144,15 +144,14 @@ 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 { this.failIfClosed(); @@ -160,7 +159,7 @@ export default class KernelSessionBackend implements ISessionBackend { // 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. @@ -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() @@ -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 @@ -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); } @@ -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); } @@ -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 @@ -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, + }; // Raw binding preserves qualified SQL types such as INTERVAL MONTH. const rawParams = positionalParams ?? namedParams; if (rawParams !== undefined) { @@ -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. */ diff --git a/native/kernel/index.d.ts b/native/kernel/index.d.ts index 87640ca0..f4d14eac 100644 --- a/native/kernel/index.d.ts +++ b/native/kernel/index.d.ts @@ -1132,6 +1132,8 @@ export interface ExecuteOptions { * `StatementSpec.row_limit`. Omitted ⇒ no driver-imposed cap. */ rowLimit?: number + /** Request LZ4 compression for Arrow results. Omit to use the session default. */ + lz4Compression?: boolean /** * Positional parameters, in 1-based wire order. Index `i` in this * Vec corresponds to the `i+1`-th `?` placeholder in the SQL. diff --git a/tests/unit/kernel/execution.test.ts b/tests/unit/kernel/execution.test.ts index 9aae43f5..d88d6569 100644 --- a/tests/unit/kernel/execution.test.ts +++ b/tests/unit/kernel/execution.test.ts @@ -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(); @@ -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); }); @@ -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 () => {